source: binary-improvements/MapRendering/Web/API/GetPlayersOnline.cs@ 237

Last change on this file since 237 was 233, checked in by alloc, 10 years ago

Fixes for 11.4

File size: 1.8 KB
RevLine 
[230]1using AllocsFixes.JSON;
[233]2using AllocsFixes.PersistentData;
[230]3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 public class GetPlayersOnline : WebAPI
10 {
11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user)
12 {
13 JSONArray players = new JSONArray();
14
15 World w = GameManager.Instance.World;
16 foreach (KeyValuePair<int, EntityPlayer> current in w.Players.dict) {
17 ClientInfo ci = ConnectionManager.Instance.GetClientInfoForEntityId (current.Key);
[233]18 Player player = PersistentContainer.Instance.Players [ci.playerId, false];
[230]19
20 JSONObject pos = new JSONObject();
[233]21 pos.Add ("x", new JSONNumber ((int)current.Value.GetPosition ().x));
22 pos.Add ("y", new JSONNumber ((int)current.Value.GetPosition ().y));
23 pos.Add ("z", new JSONNumber ((int)current.Value.GetPosition ().z));
[230]24
25 JSONObject p = new JSONObject();
[233]26 p.Add ("steamid", new JSONString (ci.playerId));
27 p.Add ("ip", new JSONString (ci != null ? ci.ip : string.Empty));
28 p.Add ("name", new JSONString (current.Value.EntityName));
29 p.Add ("online", new JSONBoolean (true));
30 p.Add ("position", pos);
[230]31
[233]32 p.Add ("experience", new JSONNumber (player != null ? player.Experience : 0));
33 p.Add ("level", new JSONNumber (player != null ? player.Level : -1));
34 p.Add ("health", new JSONNumber (current.Value.Health));
35 p.Add ("stamina", new JSONNumber (current.Value.Stamina));
36 p.Add ("zombiekills", new JSONNumber (current.Value.KilledZombies));
37 p.Add ("playerkills", new JSONNumber (current.Value.KilledPlayers));
38 p.Add ("playerdeaths", new JSONNumber (current.Value.Died));
39 p.Add ("score", new JSONNumber (current.Value.Score));
40
[230]41 players.Add(p);
42 }
43
44 WriteJSON(resp, players);
45 }
46 }
47}
48
Note: See TracBrowser for help on using the repository browser.