[251] | 1 | using AllocsFixes.JSON;
|
---|
| 2 | using AllocsFixes.PersistentData;
|
---|
| 3 | using System;
|
---|
| 4 | using System.Collections.Generic;
|
---|
| 5 | using System.Net;
|
---|
| 6 |
|
---|
| 7 | namespace AllocsFixes.NetConnections.Servers.Web.API
|
---|
| 8 | {
|
---|
| 9 | public class GetPlayersLocation : WebAPI
|
---|
| 10 | {
|
---|
| 11 | public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
|
---|
| 12 | {
|
---|
| 13 | AdminTools admTools = null;
|
---|
| 14 |
|
---|
| 15 | try { admTools = GameManager.Instance.adminTools; } catch { }
|
---|
| 16 | try { user = user ?? new WebConnection ("", "", 0L); } catch { } // default user, cheap way to avoid 'null reference exception'
|
---|
| 17 |
|
---|
| 18 | bool bViewAll = false; try { bViewAll = user.CanViewAllPlayers (permissionLevel); } catch { }
|
---|
| 19 |
|
---|
| 20 | JSONArray playersJsResult = new JSONArray ();
|
---|
| 21 |
|
---|
| 22 | Players playersList = PersistentContainer.Instance.Players;
|
---|
| 23 |
|
---|
| 24 | foreach (string sid in playersList.SteamIDs) {
|
---|
| 25 | try {
|
---|
| 26 | if ((admTools != null) && (PetesUtils.ValidText (sid)))
|
---|
| 27 | if (admTools.IsBanned (sid))
|
---|
| 28 | continue;
|
---|
| 29 | }
|
---|
| 30 | catch { }
|
---|
| 31 |
|
---|
| 32 | try
|
---|
| 33 | {
|
---|
| 34 | Player p = playersList [sid, false];
|
---|
| 35 |
|
---|
| 36 | ulong player_steam_ID = 0L;
|
---|
| 37 | if (!ulong.TryParse (sid, out player_steam_ID))
|
---|
| 38 | player_steam_ID = 0L;
|
---|
| 39 |
|
---|
| 40 | if ((player_steam_ID == user.SteamID) || bViewAll) {
|
---|
| 41 | JSONObject pos = new JSONObject ();
|
---|
| 42 | pos.Add("x", new JSONNumber (p.LastPosition.x));
|
---|
| 43 | pos.Add("y", new JSONNumber (p.LastPosition.y));
|
---|
| 44 | pos.Add("z", new JSONNumber (p.LastPosition.z));
|
---|
| 45 |
|
---|
| 46 | JSONObject pJson = new JSONObject ();
|
---|
| 47 | pJson.Add("steamid", new JSONString (sid));
|
---|
| 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);
|
---|
| 52 |
|
---|
| 53 | playersJsResult.Add (pJson);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | catch { }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | WriteJSON (resp, playersJsResult);
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|