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

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

Big refactoring in Web to pass around a Context instead of a bunch of individual arguments all the time

File size: 1.0 KB
RevLine 
[251]1using AllocsFixes.JSON;
2using AllocsFixes.LiveData;
3
[325]4namespace AllocsFixes.NetConnections.Servers.Web.API {
[387]5 public class GetStats : AbsWebAPI {
6 public override void HandleRequest (RequestContext _context) {
[251]7 JSONObject result = new JSONObject ();
8
9 JSONObject time = new JSONObject ();
10 time.Add ("days", new JSONNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime)));
11 time.Add ("hours", new JSONNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime)));
12 time.Add ("minutes", new JSONNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime)));
13 result.Add ("gametime", time);
14
15 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count));
[313]16 result.Add ("hostiles", new JSONNumber (Hostiles.Instance.GetCount ()));
17 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ()));
[251]18
[387]19 WebUtils.WriteJson (_context.Response, result);
[251]20 }
[279]21
22 public override int DefaultPermissionLevel () {
23 return 2000;
24 }
[251]25 }
[325]26}
Note: See TracBrowser for help on using the repository browser.