source: binary-improvements2/MapRendering/Web/API/GetPlayersOnline.cs@ 384

Last change on this file since 384 was 383, checked in by alloc, 2 years ago

Fixed a bunch of warnings

File size: 2.1 KB
RevLine 
[325]1using System.Collections.Generic;
[230]2using AllocsFixes.JSON;
[233]3using AllocsFixes.PersistentData;
[382]4using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
5using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
[230]6
[325]7namespace AllocsFixes.NetConnections.Servers.Web.API {
8 public class GetPlayersOnline : WebAPI {
[351]9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
10 int _permissionLevel) {
[325]11 JSONArray players = new JSONArray ();
[230]12
13 World w = GameManager.Instance.World;
14 foreach (KeyValuePair<int, EntityPlayer> current in w.Players.dict) {
[324]15 ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (current.Key);
[371]16 Player player = PersistentContainer.Instance.Players [ci.InternalId, false];
[230]17
[325]18 JSONObject pos = new JSONObject ();
19 pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x));
20 pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y));
21 pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z));
[230]22
[325]23 JSONObject p = new JSONObject ();
[369]24 p.Add ("steamid", new JSONString (ci.PlatformId.CombinedString));
[256]25 p.Add ("entityid", new JSONNumber (ci.entityId));
[309]26 p.Add ("ip", new JSONString (ci.ip));
[233]27 p.Add ("name", new JSONString (current.Value.EntityName));
28 p.Add ("online", new JSONBoolean (true));
29 p.Add ("position", pos);
[230]30
[369]31 p.Add ("level", new JSONNumber (player?.Level ?? -1));
[233]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
[369]39 p.Add ("totalplaytime", new JSONNumber (player?.TotalPlayTime ?? -1));
[268]40 p.Add ("lastonline", new JSONString (player != null ? player.LastOnline.ToString ("s") : string.Empty));
[326]41 p.Add ("ping", new JSONNumber (ci.ping));
[268]42
[325]43 players.Add (p);
[230]44 }
45
[351]46 WriteJSON (_resp, players);
[230]47 }
48 }
[325]49}
Note: See TracBrowser for help on using the repository browser.