1 | using System.Collections.Generic;
|
---|
2 | using System.Net;
|
---|
3 | using AllocsFixes.JSON;
|
---|
4 | using AllocsFixes.PersistentData;
|
---|
5 | using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
|
---|
6 | using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
|
---|
7 |
|
---|
8 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
9 | public class GetPlayersLocation : WebAPI {
|
---|
10 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
11 | int _permissionLevel) {
|
---|
12 | AdminTools admTools = GameManager.Instance.adminTools;
|
---|
13 | PlatformUserIdentifierAbs userId = _user?.UserId;
|
---|
14 |
|
---|
15 | bool listOffline = false;
|
---|
16 | if (_req.QueryString ["offline"] != null) {
|
---|
17 | bool.TryParse (_req.QueryString ["offline"], out listOffline);
|
---|
18 | }
|
---|
19 |
|
---|
20 | bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel);
|
---|
21 |
|
---|
22 | JSONArray playersJsResult = new JSONArray ();
|
---|
23 |
|
---|
24 | Players playersList = PersistentContainer.Instance.Players;
|
---|
25 |
|
---|
26 | foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) {
|
---|
27 | if (admTools != null) {
|
---|
28 | if (admTools.IsBanned (kvp.Key, out _, out _)) {
|
---|
29 | continue;
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | Player p = kvp.Value;
|
---|
34 |
|
---|
35 | if (listOffline || p.IsOnline) {
|
---|
36 | if (bViewAll || p.PlatformId.Equals (userId)) {
|
---|
37 | JSONObject pos = new JSONObject ();
|
---|
38 | pos.Add ("x", new JSONNumber (p.LastPosition.x));
|
---|
39 | pos.Add ("y", new JSONNumber (p.LastPosition.y));
|
---|
40 | pos.Add ("z", new JSONNumber (p.LastPosition.z));
|
---|
41 |
|
---|
42 | JSONObject pJson = new JSONObject ();
|
---|
43 | pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString));
|
---|
44 |
|
---|
45 | // pJson.Add("entityid", new JSONNumber (p.EntityID));
|
---|
46 | // pJson.Add("ip", new JSONString (p.IP));
|
---|
47 | pJson.Add ("name", new JSONString (p.Name));
|
---|
48 | pJson.Add ("online", new JSONBoolean (p.IsOnline));
|
---|
49 | pJson.Add ("position", pos);
|
---|
50 |
|
---|
51 | // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime));
|
---|
52 | // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s")));
|
---|
53 | // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1));
|
---|
54 |
|
---|
55 | playersJsResult.Add (pJson);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | WriteJSON (_resp, playersJsResult);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|