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, WebConnection user, int permissionLevel)
|
---|
12 | {
|
---|
13 | AdminTools admTools = GameManager.Instance.adminTools;
|
---|
14 | user = user ?? new WebConnection ("", "", 0L);
|
---|
15 |
|
---|
16 | bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel);
|
---|
17 |
|
---|
18 | JSONArray playersJsResult = new JSONArray ();
|
---|
19 |
|
---|
20 | Players playersList = PersistentContainer.Instance.Players;
|
---|
21 |
|
---|
22 | foreach (string sid in playersList.SteamIDs) {
|
---|
23 | if (admTools != null)
|
---|
24 | if (admTools.IsBanned (sid))
|
---|
25 | continue;
|
---|
26 |
|
---|
27 | Player p = playersList [sid, false];
|
---|
28 |
|
---|
29 | ulong player_steam_ID = 0L;
|
---|
30 | if (!ulong.TryParse (sid, out player_steam_ID))
|
---|
31 | player_steam_ID = 0L;
|
---|
32 |
|
---|
33 | if ((player_steam_ID == user.SteamID) || bViewAll) {
|
---|
34 | JSONObject pos = new JSONObject ();
|
---|
35 | pos.Add("x", new JSONNumber (p.LastPosition.x));
|
---|
36 | pos.Add("y", new JSONNumber (p.LastPosition.y));
|
---|
37 | pos.Add("z", new JSONNumber (p.LastPosition.z));
|
---|
38 |
|
---|
39 | JSONObject pJson = new JSONObject ();
|
---|
40 | pJson.Add("steamid", new JSONString (sid));
|
---|
41 | pJson.Add("ip", new JSONString (p.IP));
|
---|
42 | pJson.Add("name", new JSONString (p.Name));
|
---|
43 | pJson.Add("online", new JSONBoolean (p.IsOnline));
|
---|
44 | pJson.Add("position", pos);
|
---|
45 |
|
---|
46 | playersJsResult.Add (pJson);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | WriteJSON (resp, playersJsResult);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|