| 1 | using System.Collections.Generic;
|
|---|
| 2 | using AllocsFixes.JSON;
|
|---|
| 3 | using AllocsFixes.PersistentData;
|
|---|
| 4 |
|
|---|
| 5 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
|---|
| 6 | public class GetPlayersLocation : AbsWebAPI {
|
|---|
| 7 | public override void HandleRequest (RequestContext _context) {
|
|---|
| 8 | AdminTools admTools = GameManager.Instance.adminTools;
|
|---|
| 9 | PlatformUserIdentifierAbs userId = _context.Connection?.UserId;
|
|---|
| 10 |
|
|---|
| 11 | bool listOffline = false;
|
|---|
| 12 | if (_context.Request.QueryString ["offline"] != null) {
|
|---|
| 13 | bool.TryParse (_context.Request.QueryString ["offline"], out listOffline);
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | bool bViewAll = WebConnection.CanViewAllPlayers (_context.PermissionLevel);
|
|---|
| 17 |
|
|---|
| 18 | JSONArray playersJsResult = new JSONArray ();
|
|---|
| 19 |
|
|---|
| 20 | Players playersList = PersistentContainer.Instance.Players;
|
|---|
| 21 |
|
|---|
| 22 | foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) {
|
|---|
| 23 | if (admTools != null) {
|
|---|
| 24 | if (admTools.IsBanned (kvp.Key, out _, out _)) {
|
|---|
| 25 | continue;
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | Player p = kvp.Value;
|
|---|
| 30 |
|
|---|
| 31 | if (listOffline || p.IsOnline) {
|
|---|
| 32 | if (bViewAll || p.PlatformId.Equals (userId)) {
|
|---|
| 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));
|
|---|
| 37 |
|
|---|
| 38 | JSONObject pJson = new JSONObject ();
|
|---|
| 39 | pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString));
|
|---|
| 40 |
|
|---|
| 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);
|
|---|
| 46 |
|
|---|
| 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 |
|
|---|
| 51 | playersJsResult.Add (pJson);
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | WebUtils.WriteJson (_context.Response, playersJsResult);
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|