source: binary-improvements2/MapRendering/Web/API/GetPlayersLocation.cs@ 384

Last change on this file since 384 was 383, checked in by alloc, 2 years ago

Fixed a bunch of warnings

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