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