source: binary-improvements/MapRendering/API/GetPlayersOnline.cs@ 454

Last change on this file since 454 was 454, checked in by alloc, 16 months ago

24_29_43
Switched over to vanilla Web infrastructure

File size: 2.0 KB
Line 
1using System.Collections.Generic;
2using AllocsFixes.JSON;
3using AllocsFixes.PersistentData;
4using Webserver;
5using Webserver.WebAPI;
6
7namespace AllocsFixes.WebAPIs {
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 (KeyValuePair<int, EntityPlayer> current in w.Players.dict) {
14 ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (current.Key);
15 Player player = PersistentContainer.Instance.Players.GetByInternalId (ci.InternalId);
16
17 JSONObject pos = new JSONObject ();
18 pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x));
19 pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y));
20 pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z));
21
22 JSONObject p = new JSONObject ();
23 p.Add ("steamid", new JSONString (ci.PlatformId.CombinedString));
24 p.Add ("crossplatformid", new JSONString (ci.CrossplatformId?.CombinedString ?? ""));
25 p.Add ("entityid", new JSONNumber (ci.entityId));
26 p.Add ("ip", new JSONString (ci.ip));
27 p.Add ("name", new JSONString (current.Value.EntityName));
28 p.Add ("online", new JSONBoolean (true));
29 p.Add ("position", pos);
30
31 p.Add ("level", new JSONNumber (player?.Level ?? -1));
32 p.Add ("health", new JSONNumber (current.Value.Health));
33 p.Add ("stamina", new JSONNumber (current.Value.Stamina));
34 p.Add ("zombiekills", new JSONNumber (current.Value.KilledZombies));
35 p.Add ("playerkills", new JSONNumber (current.Value.KilledPlayers));
36 p.Add ("playerdeaths", new JSONNumber (current.Value.Died));
37 p.Add ("score", new JSONNumber (current.Value.Score));
38
39 p.Add ("totalplaytime", new JSONNumber (player?.TotalPlayTime ?? -1));
40 p.Add ("lastonline", new JSONString (player != null ? player.LastOnline.ToString ("s") : string.Empty));
41 p.Add ("ping", new JSONNumber (ci.ping));
42
43 players.Add (p);
44 }
45
46 LegacyApiHelper.WriteJSON (_context.Response, players);
47 }
48 }
49}
Note: See TracBrowser for help on using the repository browser.