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