source: binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/API/GetPlayersLocation.cs@ 159

Last change on this file since 159 was 154, checked in by alloc, 10 years ago

fixes

File size: 1.1 KB
Line 
1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace 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
Note: See TracBrowser for help on using the repository browser.