source: binary-improvements2/WebServer/src/WebAPI/GetStats.cs@ 400

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

Major refactoring/cleanup

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