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

Last change on this file since 347 was 332, checked in by alloc, 6 years ago

*Latest optimizations

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 {
8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
9 int permissionLevel) {
10 AdminTools admTools = GameManager.Instance.adminTools;
[332]11 user = user ?? new WebConnection ("", IPAddress.None, 0L);
[253]12
[315]13 bool listOffline = false;
14 if (req.QueryString ["offline"] != null) {
15 bool.TryParse (req.QueryString ["offline"], out listOffline);
16 }
17
[325]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
[325]39 if (player_steam_ID == user.SteamID || bViewAll) {
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
63 WriteJSON (resp, playersJsResult);
64 }
65 }
[325]66}
Note: See TracBrowser for help on using the repository browser.