[154] | 1 | using AllocsFixes.JSON;
|
---|
| 2 | using AllocsFixes.PersistentData;
|
---|
| 3 | using System;
|
---|
| 4 | using System.Collections.Generic;
|
---|
| 5 | using System.Net;
|
---|
| 6 |
|
---|
| 7 | namespace AllocsFixes.NetConnections.Servers.Web.API
|
---|
| 8 | {
|
---|
| 9 | public class GetPlayersLocation : WebAPI
|
---|
| 10 | {
|
---|
| 11 | public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user)
|
---|
| 12 | {
|
---|
| 13 | JSONArray playersJsResult = new JSONArray ();
|
---|
| 14 |
|
---|
| 15 | Players playersList = PersistentContainer.Instance.Players;
|
---|
| 16 |
|
---|
| 17 | foreach (string sid in playersList.SteamIDs) {
|
---|
| 18 | Player p = playersList[sid];
|
---|
| 19 |
|
---|
| 20 | JSONObject pos = new JSONObject();
|
---|
| 21 | pos.Add("x", new JSONNumber(p.LastPosition.x));
|
---|
| 22 | pos.Add("y", new JSONNumber(p.LastPosition.y));
|
---|
| 23 | pos.Add("z", new JSONNumber(p.LastPosition.z));
|
---|
| 24 |
|
---|
| 25 | JSONObject pJson = new JSONObject();
|
---|
| 26 | pJson.Add("steamid", new JSONString(sid));
|
---|
| 27 | pJson.Add("ip", new JSONString(p.IP));
|
---|
| 28 | pJson.Add("name", new JSONString(p.Name));
|
---|
| 29 | pJson.Add("online", new JSONBoolean(p.IsOnline));
|
---|
| 30 | pJson.Add("position", pos);
|
---|
| 31 |
|
---|
| 32 | playersJsResult.Add(pJson);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | WriteJSON(resp, playersJsResult);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|