- 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/GetPlayersOnline.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 GetPlayersOnline : AbsWebAPI { 9 public override void HandleRequest (RequestContext _context) { 10 JsonArray players = new JsonArray (); 11 12 World w = GameManager.Instance.World; 13 foreach ((int entityId, EntityPlayer entityPlayer) in w.Players.dict) { 14 ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (entityId); 15 Player player = PersistentContainer.Instance.Players [ci.InternalId, false]; 16 17 JsonObject pos = new JsonObject (); 18 pos.Add ("x", new JsonNumber ((int) entityPlayer.GetPosition ().x)); 19 pos.Add ("y", new JsonNumber ((int) entityPlayer.GetPosition ().y)); 20 pos.Add ("z", new JsonNumber ((int) entityPlayer.GetPosition ().z)); 21 22 JsonObject p = new JsonObject (); 23 p.Add ("steamid", new JsonString (ci.PlatformId.CombinedString)); 24 p.Add ("entityid", new JsonNumber (ci.entityId)); 25 p.Add ("ip", new JsonString (ci.ip)); 26 p.Add ("name", new JsonString (entityPlayer.EntityName)); 27 p.Add ("online", new JsonBoolean (true)); 28 p.Add ("position", pos); 29 30 p.Add ("level", new JsonNumber (player?.Level ?? -1)); 31 p.Add ("health", new JsonNumber (entityPlayer.Health)); 32 p.Add ("stamina", new JsonNumber (entityPlayer.Stamina)); 33 p.Add ("zombiekills", new JsonNumber (entityPlayer.KilledZombies)); 34 p.Add ("playerkills", new JsonNumber (entityPlayer.KilledPlayers)); 35 p.Add ("playerdeaths", new JsonNumber (entityPlayer.Died)); 36 p.Add ("score", new JsonNumber (entityPlayer.Score)); 37 38 p.Add ("totalplaytime", new JsonNumber (player?.TotalPlayTime ?? -1)); 39 p.Add ("lastonline", new JsonString (player != null ? player.LastOnline.ToString ("s") : string.Empty)); 40 p.Add ("ping", new JsonNumber (ci.ping)); 41 42 players.Add (p); 43 } 44 45 WebUtils.WriteJson (_context.Response, players); 46 } 47 } 48 } 1 // using AllocsFixes.PersistentData; 2 // using JetBrains.Annotations; 3 // 4 // namespace Webserver.WebAPI.APIs { 5 // [UsedImplicitly] 6 // public class GetPlayersOnline : AbsWebAPI { 7 // public override void HandleRequest (RequestContext _context) { 8 // JsonArray players = new JsonArray (); 9 // 10 // World w = GameManager.Instance.World; 11 // foreach ((int entityId, EntityPlayer entityPlayer) in w.Players.dict) { 12 // ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (entityId); 13 // Player player = PersistentContainer.Instance.Players [ci.InternalId, false]; 14 // 15 // JsonObject pos = new JsonObject (); 16 // pos.Add ("x", new JsonNumber ((int) entityPlayer.GetPosition ().x)); 17 // pos.Add ("y", new JsonNumber ((int) entityPlayer.GetPosition ().y)); 18 // pos.Add ("z", new JsonNumber ((int) entityPlayer.GetPosition ().z)); 19 // 20 // JsonObject p = new JsonObject (); 21 // p.Add ("steamid", new JsonString (ci.PlatformId.CombinedString)); 22 // p.Add ("entityid", new JsonNumber (ci.entityId)); 23 // p.Add ("ip", new JsonString (ci.ip)); 24 // p.Add ("name", new JsonString (entityPlayer.EntityName)); 25 // p.Add ("online", new JsonBoolean (true)); 26 // p.Add ("position", pos); 27 // 28 // p.Add ("level", new JsonNumber (player?.Level ?? -1)); 29 // p.Add ("health", new JsonNumber (entityPlayer.Health)); 30 // p.Add ("stamina", new JsonNumber (entityPlayer.Stamina)); 31 // p.Add ("zombiekills", new JsonNumber (entityPlayer.KilledZombies)); 32 // p.Add ("playerkills", new JsonNumber (entityPlayer.KilledPlayers)); 33 // p.Add ("playerdeaths", new JsonNumber (entityPlayer.Died)); 34 // p.Add ("score", new JsonNumber (entityPlayer.Score)); 35 // 36 // p.Add ("totalplaytime", new JsonNumber (player?.TotalPlayTime ?? -1)); 37 // p.Add ("lastonline", new JsonString (player != null ? player.LastOnline.ToString ("s") : string.Empty)); 38 // p.Add ("ping", new JsonNumber (ci.ping)); 39 // 40 // players.Add (p); 41 // } 42 // 43 // WebUtils.WriteJson (_context.Response, players); 44 // } 45 // } 46 // }
Note:
See TracChangeset
for help on using the changeset viewer.