2017-06-06 23:45:21 -04:00
|
|
|
|
using Kayak;
|
|
|
|
|
using Kayak.Http;
|
|
|
|
|
using SharedLibrary;
|
|
|
|
|
using System;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
2017-06-06 23:45:21 -04:00
|
|
|
|
using System.Text;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
|
|
|
|
public class WebService
|
|
|
|
|
{
|
|
|
|
|
public static IServer webService;
|
|
|
|
|
|
2017-06-06 23:45:21 -04:00
|
|
|
|
public static IScheduler GetScheduler()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
var webScheduler = Kayak.KayakScheduler.Factory.Create(new Scheduler());
|
|
|
|
|
webService = KayakServer.Factory.CreateHttp(new Request(), webScheduler);
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
SharedLibrary.WebService.PageList.Add(new Pages());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new Homepage());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new ServersJSON());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new Penalties());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new PenaltiesJSON());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new Players());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new GetPlayer());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new WebConsole());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new ConsoleJSON());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new PubbansJSON());
|
|
|
|
|
|
|
|
|
|
Thread scheduleThread = new Thread(() => { ScheduleThreadStart(webScheduler, webService); })
|
|
|
|
|
{
|
|
|
|
|
Name = "Web Service Thread"
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
scheduleThread.Start();
|
|
|
|
|
|
|
|
|
|
return webScheduler;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 23:45:21 -04:00
|
|
|
|
private static void ScheduleThreadStart(IScheduler S, IServer ss)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string[] webConfig = System.IO.File.ReadAllLines("config\\web.cfg");
|
|
|
|
|
var address = Dns.GetHostAddresses(webConfig[0])[0];
|
|
|
|
|
int port = Convert.ToInt32(webConfig[1]);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (ss.Listen(new IPEndPoint(address, port)))
|
|
|
|
|
S.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2017-06-07 20:59:59 -04:00
|
|
|
|
Manager.GetInstance().Logger.WriteError($"Unable to start webservice ( port is probably in use ): {e.Message}");
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
using (ss.Listen(new IPEndPoint(IPAddress.Any, 1624)))
|
|
|
|
|
S.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 23:45:21 -04:00
|
|
|
|
public static HttpResponse GetPage(string path, System.Collections.Specialized.NameValueCollection queryset, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
if (SharedLibrary.WebService.PageList == null || SharedLibrary.WebService.PageList.Count == 0)
|
2017-06-06 23:45:21 -04:00
|
|
|
|
return new HttpResponse() { content = "Error: page list not initialized!", contentType = "text/plaintext" };
|
|
|
|
|
|
|
|
|
|
if (path == null)
|
|
|
|
|
return new HttpResponse() { content = "Error: no path specified", contentType = "text/plaintext" };
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
IPage requestedPage = SharedLibrary.WebService.PageList.Find(x => x.GetPath().ToLower() == path.ToLower());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (requestedPage != null)
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return requestedPage.GetPage(queryset, headers);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (System.IO.File.Exists(path.Replace("/", "\\").Substring(1)))
|
|
|
|
|
{
|
|
|
|
|
IFile f = new IFile(path.Replace("/", "\\").Substring(1));
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (path.Contains(".css"))
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse css = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>(),
|
|
|
|
|
content = f.GetText(),
|
|
|
|
|
contentType = "text/css"
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
f.Close();
|
|
|
|
|
return css;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (path.Contains(".js"))
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse css = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>(),
|
|
|
|
|
content = f.GetText(),
|
|
|
|
|
contentType = "application/javascript"
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
f.Close();
|
|
|
|
|
return css;
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
f.Close();
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestedPage = new Error404();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return requestedPage.GetPage(queryset, headers);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Error404 : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "404";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>(),
|
|
|
|
|
content = "404 not found!",
|
|
|
|
|
contentType = GetContentType()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "text/html";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Homepage : HTMLPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Home";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
StringBuilder S = new StringBuilder();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadHeader());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
IFile p = new IFile("webfront\\main.html");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(p.GetText());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
p.Close();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadFooter());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
return S.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ServersJSON : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Servers";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/_servers";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
var info = new List<ServerInfo>();
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
foreach (Server S in Manager.GetInstance().Servers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
ServerInfo eachServer = new ServerInfo()
|
|
|
|
|
{
|
|
|
|
|
serverName = S.Hostname,
|
|
|
|
|
serverPort = S.GetPort(),
|
|
|
|
|
maxPlayers = S.MaxClients,
|
|
|
|
|
mapName = S.CurrentMap.Alias,
|
2017-06-12 17:47:31 -04:00
|
|
|
|
gameType = Utilities.GetLocalizedGametype(S.Gametype),
|
2017-06-12 13:50:00 -04:00
|
|
|
|
currentPlayers = S.GetPlayersAsList().Count,
|
|
|
|
|
chatHistory = S.ChatHistory,
|
|
|
|
|
players = new List<PlayerInfo>()
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-07 20:59:59 -04:00
|
|
|
|
foreach (Player P in S.GetPlayersAsList())
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
PlayerInfo pInfo = new PlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
playerID = P.DatabaseID,
|
|
|
|
|
playerName = P.Name,
|
|
|
|
|
playerLevel = P.Level.ToString()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
eachServer.players.Add(pInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.Add(eachServer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(info),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Info : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Info";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/_info";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
ApplicationInfo info = new ApplicationInfo()
|
|
|
|
|
{
|
|
|
|
|
name = "IW4MAdmin",
|
|
|
|
|
version = Program.Version
|
|
|
|
|
};
|
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(info),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConsoleJSON : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "_Console";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/_console";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
CommandInfo cmd = new CommandInfo()
|
|
|
|
|
{
|
|
|
|
|
Result = new List<string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (querySet["command"] != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (querySet["server"] != null)
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
Server S = Manager.GetInstance().Servers.ToList().Find(x => (x.GetPort().ToString() == querySet["server"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (S != null)
|
|
|
|
|
{
|
2017-05-29 22:25:49 -04:00
|
|
|
|
Player admin = Manager.GetInstance().GetClientDatabase().GetPlayer(querySet["IP"]);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (admin == null)
|
|
|
|
|
admin = new Player("RestUser", "-1", -1, (int)Player.Permission.User);
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
Event remoteEvent = new Event(Event.GType.Say, querySet["command"], admin, null, S)
|
|
|
|
|
{
|
|
|
|
|
Remote = true
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
admin.lastEvent = remoteEvent;
|
|
|
|
|
|
|
|
|
|
S.ExecuteEvent(remoteEvent);
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
while (S.commandResult.Count > 0)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
cmd.Result.Add(S.commandResult.Dequeue());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cmd.Result.Add("Invalid server selected.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cmd.Result.Add("Invalid server selected.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd.Result.Add("No command entered.");
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(cmd),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PenaltiesJSON : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Penalties";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/_penalties";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
int from = 0;
|
|
|
|
|
if (querySet["from"] != null)
|
|
|
|
|
from = Int32.Parse(querySet["from"]);
|
|
|
|
|
List<Penalty> selectedPenalties;
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
//selectedPenalties = Manager.GetInstance().Servers.First().Bans.OrderByDescending(x => x.When).ToList().GetRange(Convert.ToInt32(querySet["from"]), 15);
|
|
|
|
|
selectedPenalties = ((Manager.GetInstance().GetClientPenalties()) as PenaltyList).AsChronoList(Convert.ToInt32(querySet["from"]), 15).OrderByDescending(b => b.When).ToList();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
selectedPenalties = new List<Penalty>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<PenaltyInfo> info = new List<PenaltyInfo>();
|
|
|
|
|
|
|
|
|
|
foreach (var p in selectedPenalties)
|
|
|
|
|
{
|
2017-05-31 01:31:56 -04:00
|
|
|
|
Player admin = Manager.GetInstance().GetClientDatabase().GetPlayer(p.PenaltyOriginID, 0);
|
|
|
|
|
Player penalized = Manager.GetInstance().GetClientDatabase().GetPlayer(p.OffenderID, 0);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (admin == null && penalized == null)
|
|
|
|
|
continue;
|
|
|
|
|
if (admin == null)
|
|
|
|
|
admin = new Player("Unknown", "-1", -1, (int)Player.Permission.Banned);
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
|
|
|
|
PenaltyInfo pInfo = new PenaltyInfo()
|
|
|
|
|
{
|
|
|
|
|
adminName = admin.Name,
|
|
|
|
|
adminLevel = admin.Level.ToString(),
|
|
|
|
|
penaltyReason = p.Reason,
|
2017-06-12 17:47:31 -04:00
|
|
|
|
penaltyTime = SharedLibrary.Utilities.GetTimePassed(p.When),
|
2017-06-12 13:50:00 -04:00
|
|
|
|
penaltyType = p.BType.ToString(),
|
|
|
|
|
playerName = penalized.Name,
|
|
|
|
|
playerID = penalized.DatabaseID
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-31 01:31:56 -04:00
|
|
|
|
if (admin.NetworkID == penalized.NetworkID)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
pInfo.adminName = "IW4MAdmin";
|
|
|
|
|
pInfo.adminLevel = Player.Permission.Console.ToString();
|
|
|
|
|
}
|
|
|
|
|
info.Add(pInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(info),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Penalties : HTMLPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Penalties";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/penalties";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
StringBuilder S = new StringBuilder();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadHeader());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
IFile penalities = new IFile("webfront\\penalties.html");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(penalities.GetText());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
penalities.Close();
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadFooter());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
return S.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class WebConsole : HTMLPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Console";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/console";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
StringBuilder S = new StringBuilder();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadHeader());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
IFile console = new IFile("webfront\\console.html");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(console.GetText());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
console.Close();
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadFooter());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
return S.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Players : HTMLPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Players";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/players";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
StringBuilder S = new StringBuilder();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadHeader());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
IFile penalities = new IFile("webfront\\players.html");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(penalities.GetText());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
penalities.Close();
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(LoadFooter());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
return S.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
class PubbansJSON : IPage
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Public Ban List";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/pubbans";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(((Manager.GetInstance().GetClientPenalties()) as PenaltyList).AsChronoList(Convert.ToInt32(querySet["from"]), 15), Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter() }),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Pages : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Pages";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/pages";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
List<PageInfo> pages = new List<PageInfo>();
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
foreach (var p in SharedLibrary.WebService.PageList.Where(x => x.Visible()))
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
if (p == this)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
PageInfo pi = new PageInfo()
|
|
|
|
|
{
|
|
|
|
|
pagePath = p.GetPath(),
|
|
|
|
|
pageName = p.GetName(),
|
|
|
|
|
visible = p.Visible()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
pages.Add(pi);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(pages),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class GetPlayer : IPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetContentType()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/getplayer";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "GetPlayer";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
List<PlayerInfo> pInfo = new List<PlayerInfo>();
|
|
|
|
|
List<Player> matchedPlayers = new List<Player>();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-05-29 22:25:49 -04:00
|
|
|
|
bool authed = Manager.GetInstance().GetClientDatabase().GetAdmins().FindAll(x => x.IP == querySet["IP"]).Count > 0;
|
2017-06-01 13:42:28 -04:00
|
|
|
|
bool recent = false;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (querySet["id"] != null)
|
|
|
|
|
{
|
2017-05-29 22:25:49 -04:00
|
|
|
|
matchedPlayers.Add(Manager.GetInstance().GetClientDatabase().GetPlayer(Convert.ToInt32(querySet["id"])));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
else if (querySet["npID"] != null)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-05-29 22:25:49 -04:00
|
|
|
|
matchedPlayers.Add(Manager.GetInstance().GetClientDatabase().GetPlayers(new List<string> { querySet["npID"] }).First());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
else if (querySet["name"] != null)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-05-29 22:25:49 -04:00
|
|
|
|
matchedPlayers = Manager.GetInstance().GetClientDatabase().FindPlayers(querySet["name"]);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet["recent"] != null)
|
|
|
|
|
{
|
2017-05-29 22:25:49 -04:00
|
|
|
|
matchedPlayers = Manager.GetInstance().GetClientDatabase().GetRecentPlayers();
|
2017-06-01 13:42:28 -04:00
|
|
|
|
recent = true;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (matchedPlayers != null && matchedPlayers.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var pp in matchedPlayers)
|
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (pp == null) continue;
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
|
|
|
|
PlayerInfo eachPlayer = new PlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
playerID = pp.DatabaseID,
|
|
|
|
|
playerIP = pp.IP,
|
|
|
|
|
playerLevel = pp.Level.ToString(),
|
|
|
|
|
playerName = pp.Name,
|
|
|
|
|
playernpID = pp.NetworkID,
|
|
|
|
|
forumID = -1,
|
|
|
|
|
authed = authed,
|
|
|
|
|
showV2Features = false
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-01 13:42:28 -04:00
|
|
|
|
if (!recent)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-01 13:42:28 -04:00
|
|
|
|
foreach (var a in Manager.GetInstance().Servers.First().GetAliases(pp))
|
|
|
|
|
{
|
|
|
|
|
eachPlayer.playerAliases = a.Names;
|
|
|
|
|
eachPlayer.playerIPs = a.IPS;
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eachPlayer.playerConnections = pp.Connections;
|
2017-06-12 17:47:31 -04:00
|
|
|
|
eachPlayer.lastSeen = Utilities.GetTimePassed(pp.LastConnection);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
pInfo.Add(eachPlayer);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(pInfo);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(null);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct ServerInfo
|
|
|
|
|
{
|
|
|
|
|
public string serverName;
|
|
|
|
|
public int serverPort;
|
|
|
|
|
public string mapName;
|
|
|
|
|
public string gameType;
|
|
|
|
|
public int currentPlayers;
|
|
|
|
|
public int maxPlayers;
|
|
|
|
|
public List<Chat> chatHistory;
|
|
|
|
|
public List<PlayerInfo> players;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct ApplicationInfo
|
|
|
|
|
{
|
|
|
|
|
public double version;
|
|
|
|
|
public string name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct PageInfo
|
|
|
|
|
{
|
|
|
|
|
public string pageName;
|
|
|
|
|
public string pagePath;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
public string pageType;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public bool visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct PlayerInfo
|
|
|
|
|
{
|
|
|
|
|
public string playerName;
|
|
|
|
|
public int playerID;
|
|
|
|
|
public string playerLevel;
|
|
|
|
|
public string playerIP;
|
|
|
|
|
public string playernpID;
|
|
|
|
|
public Int64 forumID;
|
|
|
|
|
public List<string> playerAliases;
|
|
|
|
|
public List<string> playerIPs;
|
|
|
|
|
public int playerConnections;
|
|
|
|
|
public string lastSeen;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
public bool showV2Features;
|
|
|
|
|
public bool authed;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct PenaltyInfo
|
|
|
|
|
{
|
|
|
|
|
public string playerName;
|
|
|
|
|
public int playerID;
|
|
|
|
|
public string adminName;
|
|
|
|
|
public string adminLevel;
|
|
|
|
|
public string penaltyType;
|
|
|
|
|
public string penaltyReason;
|
|
|
|
|
public string penaltyTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct CommandInfo
|
|
|
|
|
{
|
|
|
|
|
public List<string> Result;
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|