1 | using System.Collections.Generic;
|
---|
2 | using System.Net;
|
---|
3 | using AllocsFixes.JSON;
|
---|
4 | using AllocsFixes.PersistentData;
|
---|
5 | using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
|
---|
6 | using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
|
---|
7 |
|
---|
8 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
9 | public class GetPlayersOnline : WebAPI {
|
---|
10 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
11 | int _permissionLevel) {
|
---|
12 | JSONArray players = new JSONArray ();
|
---|
13 |
|
---|
14 | World w = GameManager.Instance.World;
|
---|
15 | foreach (KeyValuePair<int, EntityPlayer> current in w.Players.dict) {
|
---|
16 | ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (current.Key);
|
---|
17 | Player player = PersistentContainer.Instance.Players [ci.InternalId, false];
|
---|
18 |
|
---|
19 | JSONObject pos = new JSONObject ();
|
---|
20 | pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x));
|
---|
21 | pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y));
|
---|
22 | pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z));
|
---|
23 |
|
---|
24 | JSONObject p = new JSONObject ();
|
---|
25 | p.Add ("steamid", new JSONString (ci.PlatformId.CombinedString));
|
---|
26 | p.Add ("entityid", new JSONNumber (ci.entityId));
|
---|
27 | p.Add ("ip", new JSONString (ci.ip));
|
---|
28 | p.Add ("name", new JSONString (current.Value.EntityName));
|
---|
29 | p.Add ("online", new JSONBoolean (true));
|
---|
30 | p.Add ("position", pos);
|
---|
31 |
|
---|
32 | p.Add ("level", new JSONNumber (player?.Level ?? -1));
|
---|
33 | p.Add ("health", new JSONNumber (current.Value.Health));
|
---|
34 | p.Add ("stamina", new JSONNumber (current.Value.Stamina));
|
---|
35 | p.Add ("zombiekills", new JSONNumber (current.Value.KilledZombies));
|
---|
36 | p.Add ("playerkills", new JSONNumber (current.Value.KilledPlayers));
|
---|
37 | p.Add ("playerdeaths", new JSONNumber (current.Value.Died));
|
---|
38 | p.Add ("score", new JSONNumber (current.Value.Score));
|
---|
39 |
|
---|
40 | p.Add ("totalplaytime", new JSONNumber (player?.TotalPlayTime ?? -1));
|
---|
41 | p.Add ("lastonline", new JSONString (player != null ? player.LastOnline.ToString ("s") : string.Empty));
|
---|
42 | p.Add ("ping", new JSONNumber (ci.ping));
|
---|
43 |
|
---|
44 | players.Add (p);
|
---|
45 | }
|
---|
46 |
|
---|
47 | WriteJSON (_resp, players);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|