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

Last change on this file since 418 was 369, checked in by alloc, 3 years ago

Preparations for A20 release
Changes usage of "SteamID" to "UserID" in console commands
Also changes a bunch of the WebAPI stuff to show / use UserIDs

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