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

Last change on this file since 434 was 371, checked in by alloc, 2 years ago

Fixed stuff using InternalId for every storage/lookup instead of a mix of both Native+Internal

File size: 2.0 KB
Line 
1using System.Collections.Generic;
2using System.Net;
3using AllocsFixes.JSON;
4using AllocsFixes.PersistentData;
5
6namespace AllocsFixes.NetConnections.Servers.Web.API {
7 public class GetPlayersOnline : WebAPI {
8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
9 int _permissionLevel) {
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 [ci.InternalId, false];
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 ("entityid", new JSONNumber (ci.entityId));
25 p.Add ("ip", new JSONString (ci.ip));
26 p.Add ("name", new JSONString (current.Value.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 (current.Value.Health));
32 p.Add ("stamina", new JSONNumber (current.Value.Stamina));
33 p.Add ("zombiekills", new JSONNumber (current.Value.KilledZombies));
34 p.Add ("playerkills", new JSONNumber (current.Value.KilledPlayers));
35 p.Add ("playerdeaths", new JSONNumber (current.Value.Died));
36 p.Add ("score", new JSONNumber (current.Value.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 WriteJSON (_resp, players);
46 }
47 }
48}
Note: See TracBrowser for help on using the repository browser.