source: binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs@ 256

Last change on this file since 256 was 256, checked in by alloc, 9 years ago

Mod 6-8-12

File size: 1.9 KB
RevLine 
[253]1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace 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 = GameManager.Instance.adminTools;
14 user = user ?? new WebConnection ("", "", 0L);
15
16 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel);
17
18 JSONArray playersJsResult = new JSONArray ();
19
20 Players playersList = PersistentContainer.Instance.Players;
21
22 foreach (string sid in playersList.SteamIDs) {
23 if (admTools != null)
24 if (admTools.IsBanned (sid))
25 continue;
26
27 Player p = playersList [sid, false];
28
29 ulong player_steam_ID = 0L;
30 if (!ulong.TryParse (sid, out player_steam_ID))
31 player_steam_ID = 0L;
32
33 if ((player_steam_ID == user.SteamID) || bViewAll) {
34 JSONObject pos = new JSONObject ();
35 pos.Add("x", new JSONNumber (p.LastPosition.x));
36 pos.Add("y", new JSONNumber (p.LastPosition.y));
37 pos.Add("z", new JSONNumber (p.LastPosition.z));
38
39 JSONObject pJson = new JSONObject ();
40 pJson.Add("steamid", new JSONString (sid));
[256]41 pJson.Add("entityid", new JSONNumber (p.EntityID));
[253]42 pJson.Add("ip", new JSONString (p.IP));
43 pJson.Add("name", new JSONString (p.Name));
44 pJson.Add("online", new JSONBoolean (p.IsOnline));
45 pJson.Add("position", pos);
46
47 playersJsResult.Add (pJson);
48 }
49 }
50
51 WriteJSON (resp, playersJsResult);
52 }
53 }
54}
55
Note: See TracBrowser for help on using the repository browser.