using AllocsFixes.JSON; using AllocsFixes.PersistentData; using System; using System.Collections.Generic; using System.Net; namespace AllocsFixes.NetConnections.Servers.Web.API { public class GetPlayersOnline : WebAPI { public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { JSONArray players = new JSONArray(); World w = GameManager.Instance.World; foreach (KeyValuePair current in w.Players.dict) { ClientInfo ci = ConnectionManager.Instance.GetClientInfoForEntityId (current.Key); Player player = PersistentContainer.Instance.Players [ci.playerId, false]; JSONObject pos = new JSONObject(); pos.Add ("x", new JSONNumber ((int)current.Value.GetPosition ().x)); pos.Add ("y", new JSONNumber ((int)current.Value.GetPosition ().y)); pos.Add ("z", new JSONNumber ((int)current.Value.GetPosition ().z)); JSONObject p = new JSONObject(); p.Add ("steamid", new JSONString (ci.playerId)); p.Add ("ip", new JSONString (ci != null ? ci.ip : string.Empty)); p.Add ("name", new JSONString (current.Value.EntityName)); p.Add ("online", new JSONBoolean (true)); p.Add ("position", pos); p.Add ("experience", new JSONNumber (player != null ? player.Experience : 0)); p.Add ("level", new JSONNumber (player != null ? player.Level : -1)); p.Add ("health", new JSONNumber (current.Value.Health)); p.Add ("stamina", new JSONNumber (current.Value.Stamina)); p.Add ("zombiekills", new JSONNumber (current.Value.KilledZombies)); p.Add ("playerkills", new JSONNumber (current.Value.KilledPlayers)); p.Add ("playerdeaths", new JSONNumber (current.Value.Died)); p.Add ("score", new JSONNumber (current.Value.Score)); players.Add(p); } WriteJSON(resp, players); } } }