1 | using System.Collections.Generic;
|
---|
2 | using AllocsFixes.JSON;
|
---|
3 | using AllocsFixes.PersistentData;
|
---|
4 | using Webserver;
|
---|
5 | using Webserver.Permissions;
|
---|
6 | using Webserver.WebAPI;
|
---|
7 |
|
---|
8 | namespace AllocsFixes.WebAPIs {
|
---|
9 | public class GetPlayersLocation : AbsWebAPI {
|
---|
10 | public override void HandleRequest (RequestContext _context) {
|
---|
11 | AdminTools admTools = GameManager.Instance.adminTools;
|
---|
12 | PlatformUserIdentifierAbs userId = _context.Connection?.UserId;
|
---|
13 |
|
---|
14 | bool listOffline = false;
|
---|
15 | if (_context.Request.QueryString ["offline"] != null) {
|
---|
16 | bool.TryParse (_context.Request.QueryString ["offline"], out listOffline);
|
---|
17 | }
|
---|
18 |
|
---|
19 | bool bViewAll = PermissionUtils.CanViewAllPlayers (_context.PermissionLevel);
|
---|
20 |
|
---|
21 | JSONArray playersJsResult = new JSONArray ();
|
---|
22 |
|
---|
23 | Players playersList = PersistentContainer.Instance.Players;
|
---|
24 |
|
---|
25 | foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) {
|
---|
26 | if (admTools != null) {
|
---|
27 | if (admTools.Blacklist.IsBanned (kvp.Key, out _, out _)) {
|
---|
28 | continue;
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | Player p = kvp.Value;
|
---|
33 |
|
---|
34 | if (listOffline || p.IsOnline) {
|
---|
35 | if (bViewAll || p.InternalId.Equals (userId)) {
|
---|
36 | JSONObject pos = new JSONObject ();
|
---|
37 | pos.Add ("x", new JSONNumber (p.LastPosition.x));
|
---|
38 | pos.Add ("y", new JSONNumber (p.LastPosition.y));
|
---|
39 | pos.Add ("z", new JSONNumber (p.LastPosition.z));
|
---|
40 |
|
---|
41 | JSONObject pJson = new JSONObject ();
|
---|
42 | pJson.Add ("steamid", new JSONString (kvp.Value.PlatformId.CombinedString));
|
---|
43 | pJson.Add ("crossplatformid", new JSONString (kvp.Value.CrossPlatformId?.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 | LegacyApiHelper.WriteJSON (_context.Response, playersJsResult);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|