[332] | 1 | using System.Collections.Generic;
|
---|
[253] | 2 | using AllocsFixes.JSON;
|
---|
| 3 | using AllocsFixes.PersistentData;
|
---|
[382] | 4 | using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
|
---|
| 5 | using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
|
---|
[253] | 6 |
|
---|
[325] | 7 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
| 8 | public class GetPlayersLocation : WebAPI {
|
---|
[351] | 9 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
| 10 | int _permissionLevel) {
|
---|
[325] | 11 | AdminTools admTools = GameManager.Instance.adminTools;
|
---|
[369] | 12 | PlatformUserIdentifierAbs userId = _user?.UserId;
|
---|
[253] | 13 |
|
---|
[315] | 14 | bool listOffline = false;
|
---|
[351] | 15 | if (_req.QueryString ["offline"] != null) {
|
---|
| 16 | bool.TryParse (_req.QueryString ["offline"], out listOffline);
|
---|
[315] | 17 | }
|
---|
| 18 |
|
---|
[351] | 19 | bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel);
|
---|
[253] | 20 |
|
---|
[325] | 21 | JSONArray playersJsResult = new JSONArray ();
|
---|
[253] | 22 |
|
---|
| 23 | Players playersList = PersistentContainer.Instance.Players;
|
---|
| 24 |
|
---|
[369] | 25 | foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) {
|
---|
[325] | 26 | if (admTools != null) {
|
---|
[369] | 27 | if (admTools.IsBanned (kvp.Key, out _, out _)) {
|
---|
[325] | 28 | continue;
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
[253] | 31 |
|
---|
[332] | 32 | Player p = kvp.Value;
|
---|
[253] | 33 |
|
---|
[315] | 34 | if (listOffline || p.IsOnline) {
|
---|
[369] | 35 | if (bViewAll || p.PlatformId.Equals (userId)) {
|
---|
[325] | 36 | JSONObject pos = new JSONObject ();
|
---|
| 37 | pos.Add ("x", new JSONNumber (p.LastPosition.x));
|
---|
| 38 | pos.Add ("y", new JSONNumber (p.LastPosition.y));
|
---|
| 39 | pos.Add ("z", new JSONNumber (p.LastPosition.z));
|
---|
[253] | 40 |
|
---|
[325] | 41 | JSONObject pJson = new JSONObject ();
|
---|
[369] | 42 | pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString));
|
---|
[253] | 43 |
|
---|
[325] | 44 | // pJson.Add("entityid", new JSONNumber (p.EntityID));
|
---|
| 45 | // pJson.Add("ip", new JSONString (p.IP));
|
---|
| 46 | pJson.Add ("name", new JSONString (p.Name));
|
---|
| 47 | pJson.Add ("online", new JSONBoolean (p.IsOnline));
|
---|
| 48 | pJson.Add ("position", pos);
|
---|
[268] | 49 |
|
---|
[325] | 50 | // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime));
|
---|
| 51 | // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s")));
|
---|
| 52 | // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1));
|
---|
| 53 |
|
---|
[315] | 54 | playersJsResult.Add (pJson);
|
---|
[325] | 55 | }
|
---|
[315] | 56 | }
|
---|
[325] | 57 | }
|
---|
[253] | 58 |
|
---|
[351] | 59 | WriteJSON (_resp, playersJsResult);
|
---|
[253] | 60 | }
|
---|
| 61 | }
|
---|
[325] | 62 | }
|
---|