- Timestamp:
- Oct 28, 2015, 7:51:20 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r244 r251 11 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 12 { 13 JSONArray playersJsResult = new JSONArray (); 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 (); 14 21 15 22 Players playersList = PersistentContainer.Instance.Players; 16 23 17 24 foreach (string sid in playersList.SteamIDs) { 18 Player p = playersList[sid, false]; 25 try { 26 if ((admTools != null) && (PetesUtils.ValidText (sid))) 27 if (admTools.IsBanned (sid)) 28 continue; 29 } 30 catch { } 19 31 20 JSONObject pos = new JSONObject(); 21 pos.Add("x", new JSONNumber(p.LastPosition.x)); 22 pos.Add("y", new JSONNumber(p.LastPosition.y)); 23 pos.Add("z", new JSONNumber(p.LastPosition.z)); 32 try 33 { 34 Player p = playersList [sid, false]; 24 35 25 JSONObject pJson = new JSONObject(); 26 pJson.Add("steamid", new JSONString(sid)); 27 pJson.Add("ip", new JSONString(p.IP)); 28 pJson.Add("name", new JSONString(p.Name)); 29 pJson.Add("online", new JSONBoolean(p.IsOnline)); 30 pJson.Add("position", pos); 36 ulong player_steam_ID = 0L; 37 if (!ulong.TryParse (sid, out player_steam_ID)) 38 player_steam_ID = 0L; 31 39 32 playersJsResult.Add(pJson); 33 } 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)); 34 45 35 WriteJSON(resp, playersJsResult); 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); 36 60 } 37 61 }
Note:
See TracChangeset
for help on using the changeset viewer.