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

Last change on this file since 336 was 332, checked in by alloc, 6 years ago

*Latest optimizations

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