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