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

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

fixes 8_11_14_1

File size: 2.1 KB
Line 
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));
41 pJson.Add("entityid", new JSONNumber (p.EntityID));
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 pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime));
48 pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s")));
49 pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1));
50
51 playersJsResult.Add (pJson);
52 }
53 }
54
55 WriteJSON (resp, playersJsResult);
56 }
57 }
58}
59
Note: See TracBrowser for help on using the repository browser.