source: binary-improvements/MapRendering/API/GetStats.cs

Last change on this file was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 1.5 KB
Line 
1using AllocsFixes.LiveData;
2using JetBrains.Annotations;
3using Utf8Json;
4using Webserver;
5using Webserver.WebAPI;
6
7namespace AllocsFixes.WebAPIs {
8 [UsedImplicitly]
9 public class GetStats : AbsWebAPI {
10 private static readonly byte[] jsonKeyGameTime = JsonWriter.GetEncodedPropertyNameWithBeginObject ("gametime");
11
12 private static readonly byte[] jsonKeyPlayers = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("players");
13 private static readonly byte[] jsonKeyHostiles = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hostiles");
14 private static readonly byte[] jsonKeyAnimals = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("animals");
15
16 public override void HandleRequest (RequestContext _context) {
17 JsonWriter writer = new JsonWriter ();
18
19 writer.WriteRaw (jsonKeyGameTime);
20 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
21 JsonCommons.WriteGameTimeObject (ref writer, days, hours, minutes);
22
23 writer.WriteRaw (jsonKeyPlayers);
24 writer.WriteInt32 (GameManager.Instance.World.Players.Count);
25
26 writer.WriteRaw (jsonKeyHostiles);
27 writer.WriteInt32 (Hostiles.Instance.GetCount ());
28
29 writer.WriteRaw (jsonKeyAnimals);
30 writer.WriteInt32 (Animals.Instance.GetCount ());
31
32 writer.WriteEndObject ();
33
34 WebUtils.WriteJsonData (_context.Response, ref writer);
35 }
36
37 public override int DefaultPermissionLevel () {
38 return 2000;
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.