1 | using AllocsFixes.JSON;
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Net;
|
---|
5 |
|
---|
6 | namespace 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.Players.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 |
|
---|