- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- Location:
- binary-improvements2/WebServer/src/WebAPI/APIs
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/WebAPI/APIs/GetPlayersLocation.cs
r401 r402 1 using System.Collections.Generic; 2 using AllocsFixes.JSON; 3 using AllocsFixes.PersistentData; 4 using JetBrains.Annotations; 5 6 namespace Webserver.WebAPI { 7 [UsedImplicitly] 8 public class GetPlayersLocation : AbsWebAPI { 9 public override void HandleRequest (RequestContext _context) { 10 AdminTools admTools = GameManager.Instance.adminTools; 11 PlatformUserIdentifierAbs reqUserId = _context.Connection?.UserId; 12 13 bool listOffline = false; 14 if (_context.Request.QueryString ["offline"] != null) { 15 bool.TryParse (_context.Request.QueryString ["offline"], out listOffline); 16 } 17 18 bool bViewAll = WebConnection.CanViewAllPlayers (_context.PermissionLevel); 19 20 JsonArray playersJsResult = new JsonArray (); 21 22 Players playersList = PersistentContainer.Instance.Players; 23 24 foreach ((PlatformUserIdentifierAbs userId, Player player) in playersList.Dict) { 25 if (admTools != null) { 26 if (admTools.IsBanned (userId, out _, out _)) { 27 continue; 28 } 29 } 30 31 if (!listOffline && !player.IsOnline) { 32 continue; 33 } 34 35 if (!bViewAll && !player.PlatformId.Equals (reqUserId)) { 36 continue; 37 } 38 39 JsonObject pos = new JsonObject (); 40 pos.Add ("x", new JsonNumber (player.LastPosition.x)); 41 pos.Add ("y", new JsonNumber (player.LastPosition.y)); 42 pos.Add ("z", new JsonNumber (player.LastPosition.z)); 43 44 JsonObject pJson = new JsonObject (); 45 pJson.Add ("steamid", new JsonString (userId.CombinedString)); 46 47 // pJson.Add("entityid", new JSONNumber (p.EntityID)); 48 // pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add ("name", new JsonString (player.Name)); 50 pJson.Add ("online", new JsonBoolean (player.IsOnline)); 51 pJson.Add ("position", pos); 52 53 // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 54 // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 55 // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 56 57 playersJsResult.Add (pJson); 58 } 59 60 WebUtils.WriteJson (_context.Response, playersJsResult); 61 } 62 } 63 } 1 // using AllocsFixes.PersistentData; 2 // using JetBrains.Annotations; 3 // 4 // namespace Webserver.WebAPI.APIs { 5 // [UsedImplicitly] 6 // public class GetPlayersLocation : AbsWebAPI { 7 // public override void HandleRequest (RequestContext _context) { 8 // AdminTools admTools = GameManager.Instance.adminTools; 9 // PlatformUserIdentifierAbs reqUserId = _context.Connection?.UserId; 10 // 11 // bool listOffline = false; 12 // if (_context.Request.QueryString ["offline"] != null) { 13 // bool.TryParse (_context.Request.QueryString ["offline"], out listOffline); 14 // } 15 // 16 // bool bViewAll = WebConnection.CanViewAllPlayers (_context.PermissionLevel); 17 // 18 // JsonArray playersJsResult = new JsonArray (); 19 // 20 // Players playersList = PersistentContainer.Instance.Players; 21 // 22 // foreach ((PlatformUserIdentifierAbs userId, Player player) in playersList.Dict) { 23 // if (admTools != null) { 24 // if (admTools.IsBanned (userId, out _, out _)) { 25 // continue; 26 // } 27 // } 28 // 29 // if (!listOffline && !player.IsOnline) { 30 // continue; 31 // } 32 // 33 // if (!bViewAll && !player.PlatformId.Equals (reqUserId)) { 34 // continue; 35 // } 36 // 37 // JsonObject pos = new JsonObject (); 38 // pos.Add ("x", new JsonNumber (player.LastPosition.x)); 39 // pos.Add ("y", new JsonNumber (player.LastPosition.y)); 40 // pos.Add ("z", new JsonNumber (player.LastPosition.z)); 41 // 42 // JsonObject pJson = new JsonObject (); 43 // pJson.Add ("steamid", new JsonString (userId.CombinedString)); 44 // 45 // // pJson.Add("entityid", new JSONNumber (p.EntityID)); 46 // // pJson.Add("ip", new JSONString (p.IP)); 47 // pJson.Add ("name", new JsonString (player.Name)); 48 // pJson.Add ("online", new JsonBoolean (player.IsOnline)); 49 // pJson.Add ("position", pos); 50 // 51 // // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 52 // // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 53 // // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 54 // 55 // playersJsResult.Add (pJson); 56 // } 57 // 58 // WebUtils.WriteJson (_context.Response, playersJsResult); 59 // } 60 // } 61 // }
Note:
See TracChangeset
for help on using the changeset viewer.