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

Last change on this file since 322 was 315, checked in by alloc, 7 years ago

Fixes

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