source: binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs@ 368

Last change on this file since 368 was 351, checked in by alloc, 6 years ago

Fixed game version compatibility of GamePrefs
Code style cleanup (mostly argument names)

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