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