source: binary-improvements2/WebServer/src/WebAPI/APIs/GetPlayersOnline.cs@ 402

Last change on this file since 402 was 402, checked in by alloc, 22 months ago
  • Major refactoring
  • Using Utf8Json for (de)serialization
  • Moving APIs to REST
  • Removing dependencies from WebServer and MapRenderer to ServerFixes
File size: 2.0 KB
Line 
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 TracBrowser for help on using the repository browser.