[325] | 1 | using System.Net;
|
---|
[253] | 2 | using AllocsFixes.JSON;
|
---|
| 3 | using AllocsFixes.PersistentData;
|
---|
| 4 |
|
---|
[325] | 5 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
| 6 | public class GetPlayersLocation : WebAPI {
|
---|
| 7 | public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
|
---|
| 8 | int permissionLevel) {
|
---|
| 9 | AdminTools admTools = GameManager.Instance.adminTools;
|
---|
| 10 | user = user ?? new WebConnection ("", "", 0L);
|
---|
[253] | 11 |
|
---|
[315] | 12 | bool listOffline = false;
|
---|
| 13 | if (req.QueryString ["offline"] != null) {
|
---|
| 14 | bool.TryParse (req.QueryString ["offline"], out listOffline);
|
---|
| 15 | }
|
---|
| 16 |
|
---|
[325] | 17 | bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel);
|
---|
[253] | 18 |
|
---|
[325] | 19 | JSONArray playersJsResult = new JSONArray ();
|
---|
[253] | 20 |
|
---|
| 21 | Players playersList = PersistentContainer.Instance.Players;
|
---|
| 22 |
|
---|
| 23 | foreach (string sid in playersList.SteamIDs) {
|
---|
[325] | 24 | if (admTools != null) {
|
---|
| 25 | if (admTools.IsBanned (sid)) {
|
---|
| 26 | continue;
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
[253] | 29 |
|
---|
[325] | 30 | Player p = playersList [sid, false];
|
---|
[253] | 31 |
|
---|
[315] | 32 | if (listOffline || p.IsOnline) {
|
---|
[326] | 33 | ulong player_steam_ID;
|
---|
[325] | 34 | if (!ulong.TryParse (sid, out player_steam_ID)) {
|
---|
| 35 | player_steam_ID = 0L;
|
---|
| 36 | }
|
---|
[253] | 37 |
|
---|
[325] | 38 | if (player_steam_ID == user.SteamID || bViewAll) {
|
---|
| 39 | JSONObject pos = new JSONObject ();
|
---|
| 40 | pos.Add ("x", new JSONNumber (p.LastPosition.x));
|
---|
| 41 | pos.Add ("y", new JSONNumber (p.LastPosition.y));
|
---|
| 42 | pos.Add ("z", new JSONNumber (p.LastPosition.z));
|
---|
[253] | 43 |
|
---|
[325] | 44 | JSONObject pJson = new JSONObject ();
|
---|
| 45 | pJson.Add ("steamid", new JSONString (sid));
|
---|
[253] | 46 |
|
---|
[325] | 47 | // pJson.Add("entityid", new JSONNumber (p.EntityID));
|
---|
| 48 | // pJson.Add("ip", new JSONString (p.IP));
|
---|
| 49 | pJson.Add ("name", new JSONString (p.Name));
|
---|
| 50 | pJson.Add ("online", new JSONBoolean (p.IsOnline));
|
---|
| 51 | pJson.Add ("position", pos);
|
---|
[268] | 52 |
|
---|
[325] | 53 | // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime));
|
---|
| 54 | // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s")));
|
---|
| 55 | // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1));
|
---|
| 56 |
|
---|
[315] | 57 | playersJsResult.Add (pJson);
|
---|
[325] | 58 | }
|
---|
[315] | 59 | }
|
---|
[325] | 60 | }
|
---|
[253] | 61 |
|
---|
| 62 | WriteJSON (resp, playersJsResult);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
[325] | 65 | }
|
---|