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