source: binary-improvements2/MapRendering/Web/API/GetStats.cs@ 382

Last change on this file since 382 was 382, checked in by alloc, 2 years ago

Switched to use SpaceWizards.HttpListener

File size: 1.2 KB
Line 
1using System.Net;
2using AllocsFixes.JSON;
3using AllocsFixes.LiveData;
4using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
5using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API {
8 public class GetStats : WebAPI {
9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
10 int _permissionLevel) {
11 JSONObject result = new JSONObject ();
12
13 JSONObject time = new JSONObject ();
14 time.Add ("days", new JSONNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime)));
15 time.Add ("hours", new JSONNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime)));
16 time.Add ("minutes", new JSONNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime)));
17 result.Add ("gametime", time);
18
19 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count));
20 result.Add ("hostiles", new JSONNumber (Hostiles.Instance.GetCount ()));
21 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ()));
22
23 WriteJSON (_resp, result);
24 }
25
26 public override int DefaultPermissionLevel () {
27 return 2000;
28 }
29 }
30}
Note: See TracBrowser for help on using the repository browser.