source: binary-improvements2/WebServer/src/WebAPI/GetWebUIUpdates.cs@ 392

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

Major refactoring/cleanup

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