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;
|
2017-10-03 19:17:35 -04:00
|
|
|
|
using System.IO;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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;
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
using SharedLibrary.Objects;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SharedLibrary.Services;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using SharedLibrary.Database.Models;
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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());
|
2017-09-27 16:07:43 -04:00
|
|
|
|
SharedLibrary.WebService.PageList.Add(new PlayerHistoryJSON());
|
2017-06-12 13:50:00 -04:00
|
|
|
|
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());
|
2017-08-17 19:28:08 -04:00
|
|
|
|
SharedLibrary.WebService.PageList.Add(new AdminsJSON());
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(new Admins());
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
|
|
|
|
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-09-27 16:07:43 -04:00
|
|
|
|
ApplicationManager.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-11-25 20:29:58 -05:00
|
|
|
|
return Task.Run(async () => await requestedPage.GetPage(queryset, headers)).Result;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-11-15 16:04:13 -05:00
|
|
|
|
if (File.Exists(path.Replace("/", "\\").Substring(1)))
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-10-03 19:17:35 -04:00
|
|
|
|
var f = File.ReadAllBytes(path.Replace("/", "\\").Substring(1));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
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>(),
|
2017-10-03 19:17:35 -04:00
|
|
|
|
content = Encoding.ASCII.GetString(f),
|
2017-06-12 13:50:00 -04:00
|
|
|
|
contentType = "text/css"
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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>(),
|
2017-10-03 19:17:35 -04:00
|
|
|
|
content = Encoding.ASCII.GetString(f),
|
2017-06-12 13:50:00 -04:00
|
|
|
|
contentType = "application/javascript"
|
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return css;
|
|
|
|
|
}
|
2017-10-03 19:17:35 -04:00
|
|
|
|
|
|
|
|
|
else if (path.Contains(".png"))
|
|
|
|
|
{
|
|
|
|
|
HttpResponse png = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>(),
|
|
|
|
|
BinaryContent = f,
|
|
|
|
|
contentType = "image/png"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return png;
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestedPage = new Error404();
|
2017-11-25 20:29:58 -05:00
|
|
|
|
return Task.Run(async () => await requestedPage.GetPage(queryset, headers)).Result;
|
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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<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-06-19 13:58:01 -04:00
|
|
|
|
foreach (Server S in ApplicationManager.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,
|
2017-09-27 16:07:43 -04:00
|
|
|
|
players = new List<PlayerInfo>(),
|
2017-10-04 19:01:04 -04:00
|
|
|
|
PlayerHistory = S.PlayerHistory.ToArray()
|
2017-06-12 13:50:00 -04:00
|
|
|
|
};
|
2017-09-27 16:07:43 -04:00
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
bool authed = querySet["IP"] == "127.0.0.1"
|
|
|
|
|
|| (await (ApplicationManager.GetInstance().GetClientService() as ClientService).GetPrivilegedClients())
|
2017-11-25 20:29:58 -05:00
|
|
|
|
.Where(x => x.IPAddress == querySet["IP"])
|
2017-11-29 19:35:50 -05:00
|
|
|
|
.Where(x => x.Level > Player.Permission.Trusted).Count() > 0;
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
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()
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
playerID = P.ClientId,
|
2017-06-12 13:50:00 -04:00
|
|
|
|
playerName = P.Name,
|
2017-08-23 18:29:48 -04:00
|
|
|
|
playerLevel = authed ? P.Level.ToString() : Player.Permission.User.ToString()
|
2017-06-12 13:50:00 -04:00
|
|
|
|
};
|
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-11-25 20:29:58 -05: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 16:07:43 -04:00
|
|
|
|
|
|
|
|
|
class PlayerHistoryJSON : IPage
|
|
|
|
|
{
|
|
|
|
|
public string GetName()
|
|
|
|
|
{
|
|
|
|
|
return "Player History";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetPath()
|
|
|
|
|
{
|
|
|
|
|
return "/_playerhistory";
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
public async Task<HttpResponse> GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-09-27 16:07:43 -04:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var history = new SharedLibrary.Helpers.PlayerHistory[0];
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Int32.Parse(querySet["server"]);
|
|
|
|
|
history = ApplicationManager.GetInstance().GetServers()[id].PlayerHistory.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(history),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetContentType()
|
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Visible()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<HttpResponse> GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
var cmd = new List<SharedLibrary.Helpers.CommandResult>();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (querySet["command"] != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (querySet["server"] != null)
|
|
|
|
|
{
|
2017-06-19 13:58:01 -04:00
|
|
|
|
Server S = ApplicationManager.GetInstance().Servers.ToList().Find(x => (x.GetPort().ToString() == querySet["server"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (S != null)
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
// fixme
|
|
|
|
|
Func<EFClient, bool> predicate = c => c.IPAddress == querySet["IP"];
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Player admin = (await ApplicationManager.GetInstance().GetClientService().Find(predicate)).FirstOrDefault()?.AsPlayer();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (admin == null)
|
2017-11-29 19:35:50 -05:00
|
|
|
|
admin = new Player() { Name = "RestUser"};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
Event remoteEvent = new Event(Event.GType.Say, querySet["command"], admin, null, S)
|
|
|
|
|
{
|
|
|
|
|
Remote = true
|
|
|
|
|
};
|
2017-11-25 20:29:58 -05:00
|
|
|
|
admin.CurrentServer = S;
|
|
|
|
|
await S.ExecuteEvent(remoteEvent);
|
|
|
|
|
|
|
|
|
|
var results = S.commandResult.Where(c => c.Clientd == admin.ClientId).ToList();
|
|
|
|
|
cmd.AddRange(results);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
for (int i = 0; i < results.Count(); i++)
|
|
|
|
|
S.commandResult.Remove(results[i]);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-11-25 20:29:58 -05:00
|
|
|
|
cmd.Add(new SharedLibrary.Helpers.CommandResult() { Clientd = 0, Message = "Invalid server selected" });
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
2017-11-25 20:29:58 -05:00
|
|
|
|
cmd.Add(new SharedLibrary.Helpers.CommandResult() { Clientd = 0, Message = "No server selected" });
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
cmd.Add(new SharedLibrary.Helpers.CommandResult() { Clientd = 0, Message = "No command entered" });
|
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(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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<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<PenaltyInfo> info = new List<PenaltyInfo>();
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
foreach (var penalty in await ApplicationManager.GetInstance().GetPenaltyService().GetRecentPenalties(15, from))
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
|
|
|
|
PenaltyInfo pInfo = new PenaltyInfo()
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
adminName = penalty.Punisher.Name,
|
|
|
|
|
adminLevel = penalty.Punisher.Level.ToString(),
|
|
|
|
|
penaltyReason = penalty.Offense,
|
|
|
|
|
penaltyTime = Utilities.GetTimePassed(penalty.When),
|
|
|
|
|
penaltyType = penalty.Type.ToString(),
|
|
|
|
|
playerName = penalty.Offender.Name,
|
|
|
|
|
playerID = penalty.Offender.ClientId,
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Expires = penalty.Expires > DateTime.UtcNow ? (penalty.Expires - DateTime.UtcNow).TimeSpanText() : ""
|
2017-06-12 13:50:00 -04:00
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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-08-17 19:28:08 -04:00
|
|
|
|
|
|
|
|
|
class Admins : HTMLPage
|
|
|
|
|
{
|
|
|
|
|
public override string GetName()
|
|
|
|
|
{
|
|
|
|
|
return "Admins";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetPath()
|
|
|
|
|
{
|
|
|
|
|
return "/Admins";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder S = new StringBuilder();
|
|
|
|
|
S.Append(LoadHeader());
|
|
|
|
|
|
|
|
|
|
IFile admins = new IFile("webfront\\admins.html");
|
|
|
|
|
S.Append(admins.GetText());
|
|
|
|
|
admins.Close();
|
|
|
|
|
|
|
|
|
|
S.Append(LoadFooter());
|
|
|
|
|
|
|
|
|
|
return S.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AdminsJSON : IPage
|
|
|
|
|
{
|
|
|
|
|
public string GetName()
|
|
|
|
|
{
|
|
|
|
|
return "Admins Json";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetPath()
|
|
|
|
|
{
|
|
|
|
|
return "/GetAdmins";
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
public async Task<HttpResponse> GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-08-17 19:28:08 -04:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
var Admins = (await ApplicationManager.GetInstance().GetClientService()
|
2017-11-25 20:29:58 -05:00
|
|
|
|
.GetPrivilegedClients())
|
2017-11-29 19:35:50 -05:00
|
|
|
|
.OrderByDescending(a => a.Level);
|
|
|
|
|
|
2017-08-17 19:28:08 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
2017-11-29 19:35:50 -05:00
|
|
|
|
content = Admins.Select(a => new
|
|
|
|
|
{
|
|
|
|
|
ClientId = a.ClientId,
|
|
|
|
|
Level = a.Level,
|
|
|
|
|
Name = a.Name
|
|
|
|
|
}),
|
2017-08-17 19:28:08 -04:00
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetContentType()
|
|
|
|
|
{
|
|
|
|
|
return "application/json";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Visible()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<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()
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
/* contentType = GetContentType(),
|
|
|
|
|
content = Newtonsoft.Json.JsonConvert
|
|
|
|
|
.SerializeObject(((ApplicationManager.GetInstance().GetClientPenalties()) as PenaltyList)
|
|
|
|
|
.AsChronoList(Convert.ToInt32(querySet["from"]), 50, Penalty.Type.Ban), Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonConverter[] {
|
|
|
|
|
new Newtonsoft.Json.Converters.StringEnumConverter()
|
|
|
|
|
}),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()*/
|
2017-06-12 13:50:00 -04:00
|
|
|
|
};
|
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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<HttpResponse> GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2017-10-04 19:01:04 -04:00
|
|
|
|
var pages = SharedLibrary.WebService.PageList.Select(p => new
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-10-04 19:01:04 -04:00
|
|
|
|
pagePath = p.GetPath(),
|
|
|
|
|
pageName = p.GetName(),
|
|
|
|
|
visible = p.Visible(),
|
|
|
|
|
});
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
2017-10-04 19:01:04 -04:00
|
|
|
|
content = Newtonsoft.Json.JsonConvert.SerializeObject(pages.ToArray()),
|
2017-06-12 13:50:00 -04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-27 16:07:43 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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-11-25 20:29:58 -05:00
|
|
|
|
public async Task<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>();
|
2017-11-25 20:29:58 -05:00
|
|
|
|
IList<SharedLibrary.Database.Models.EFClient> matchedPlayers = new List<SharedLibrary.Database.Models.EFClient>();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
HttpResponse resp = new HttpResponse()
|
|
|
|
|
{
|
|
|
|
|
contentType = GetContentType(),
|
|
|
|
|
additionalHeaders = new Dictionary<string, string>()
|
|
|
|
|
};
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Func<EFClient, bool> predicate = c => c.IPAddress == querySet["IP"] && c.Level > Player.Permission.Trusted;
|
|
|
|
|
bool authed = (await ApplicationManager.GetInstance().GetClientService().Find(predicate)).Count > 0
|
2017-08-17 19:28:08 -04:00
|
|
|
|
|| querySet["IP"] == "127.0.0.1";
|
2017-06-01 13:42:28 -04:00
|
|
|
|
bool recent = false;
|
2017-11-19 01:44:11 -05:00
|
|
|
|
bool individual = querySet["id"] != null;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-11-19 01:44:11 -05:00
|
|
|
|
if (individual)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
matchedPlayers.Add(await ApplicationManager.GetInstance().GetClientService().Get(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-11-25 20:29:58 -05:00
|
|
|
|
matchedPlayers.Add(await ApplicationManager.GetInstance().GetClientService().GetUnique(querySet["npID"]));
|
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-11-25 20:29:58 -05:00
|
|
|
|
matchedPlayers = await ApplicationManager.GetInstance().GetClientService().Find(c => c.Name.Contains(querySet["name"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet["recent"] != null)
|
|
|
|
|
{
|
2017-11-18 01:59:37 -05:00
|
|
|
|
int offset = 0;
|
|
|
|
|
if (querySet["offset"] != null)
|
|
|
|
|
offset = Int32.Parse(querySet["offset"]);
|
|
|
|
|
if (offset < 0)
|
|
|
|
|
throw new FormatException("Invalid offset");
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
matchedPlayers = await ApplicationManager.GetInstance().GetClientService().GetRecentClients(offset, 15);
|
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()
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
playerIP = pp.IPAddress,
|
|
|
|
|
playerID = pp.ClientId,
|
2017-06-12 13:50:00 -04:00
|
|
|
|
playerLevel = pp.Level.ToString(),
|
|
|
|
|
playerName = pp.Name,
|
2017-11-25 20:29:58 -05:00
|
|
|
|
playernpID = pp.NetworkId,
|
2017-06-12 13:50:00 -04:00
|
|
|
|
forumID = -1,
|
|
|
|
|
authed = authed,
|
2017-11-19 01:44:11 -05:00
|
|
|
|
showV2Features = false,
|
|
|
|
|
playerAliases = new List<string>(),
|
|
|
|
|
playerIPs = new List<string>()
|
2017-06-12 13:50:00 -04:00
|
|
|
|
};
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
if (!recent)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
eachPlayer.playerAliases = pp.AliasLink.Children
|
|
|
|
|
.OrderBy(a => a.Name)
|
|
|
|
|
.Select(a => a.Name)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if (authed)
|
|
|
|
|
eachPlayer.playerIPs = pp.AliasLink.Children
|
|
|
|
|
.Select(a => a.IPAddress)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
//eachPlayer.playerAliases = eachPlayer.playerAliases.Distinct().ToList();
|
|
|
|
|
// eachPlayer.playerIPs = eachPlayer.playerIPs.Distinct().ToList();
|
2017-11-19 01:44:11 -05:00
|
|
|
|
|
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;
|
2017-10-04 19:01:04 -04:00
|
|
|
|
public SharedLibrary.Helpers.PlayerHistory[] PlayerHistory;
|
2017-09-27 16:07:43 -04:00
|
|
|
|
public int ID;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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;
|
2017-09-27 16:07:43 -04:00
|
|
|
|
public string Expires;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
struct CommandInfo
|
|
|
|
|
{
|
|
|
|
|
public List<string> Result;
|
|
|
|
|
}
|
2017-08-17 19:28:08 -04:00
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
class PrivilegedUsers
|
|
|
|
|
{
|
|
|
|
|
public Player.Permission Permission { get; set; }
|
|
|
|
|
public List<Player> Players { get; set; }
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|