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

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

fixes

File size: 1.2 KB
RevLine 
[154]1using AllocsFixes.JSON;
2using System;
3using System.Collections.Generic;
4using System.Net;
5
6namespace AllocsFixes.NetConnections.Servers.Web.API
7{
8 public class GetPlayersOnline : WebAPI
9 {
10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user)
11 {
12 JSONArray players = new JSONArray();
13
14 World w = CommonMappingFunctions.GetGameManager ().World;
15 foreach (KeyValuePair<int, EntityPlayer> current in w.playerEntities.dict) {
16 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromEntityID (current.Key);
17 string ip = string.Empty;
18 if (ci != null) {
19 ip = ci.networkPlayer.ipAddress;
20 }
21
22 JSONObject pos = new JSONObject();
23 pos.Add("x", new JSONNumber((int)current.Value.GetPosition().x));
24 pos.Add("y", new JSONNumber((int)current.Value.GetPosition().y));
25 pos.Add("z", new JSONNumber((int)current.Value.GetPosition().z));
26
27 JSONObject p = new JSONObject();
28 p.Add("steamid", new JSONString(CommonMappingFunctions.GetSteamID (ci)));
29 p.Add("ip", new JSONString(ip));
30 p.Add("name", new JSONString(current.Value.EntityName));
31 p.Add("online", new JSONBoolean(true));
32 p.Add("position", pos);
33
34 players.Add(p);
35 }
36
37 WriteJSON(resp, players);
38 }
39 }
40}
41
Note: See TracBrowser for help on using the repository browser.