source: binary-improvements2/WebServer/src/WebAPI/APIs/ServerStats.cs@ 410

Last change on this file since 410 was 408, checked in by alloc, 21 months ago

Few pieces of code cleanup

File size: 1.9 KB
RevLine 
[391]1using JetBrains.Annotations;
[402]2using Utf8Json;
3using Webserver.LiveData;
[391]4
[402]5namespace Webserver.WebAPI.APIs {
[391]6 [UsedImplicitly]
[402]7 public class ServerStats : AbsRestApi {
8 private static readonly byte[] jsonKeyGameTime = JsonWriter.GetEncodedPropertyNameWithBeginObject ("gameTime");
9 private static readonly byte[] jsonKeyPlayers = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("players");
10 private static readonly byte[] jsonKeyHostiles = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hostiles");
11 private static readonly byte[] jsonKeyAnimals = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("animals");
12
13 private static readonly byte[] jsonKeyDays = JsonWriter.GetEncodedPropertyNameWithBeginObject ("days");
14 private static readonly byte[] jsonKeyHours = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hours");
15 private static readonly byte[] jsonKeyMinutes = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("minutes");
[391]16
[402]17 protected override void HandleRestGet (RequestContext _context) {
18 PrepareEnvelopedResult (out JsonWriter writer);
19
20 writer.WriteRaw (jsonKeyGameTime);
[391]21
[402]22 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
23
24 writer.WriteRaw (jsonKeyDays);
25 writer.WriteInt32 (days);
26
27 writer.WriteRaw (jsonKeyHours);
28 writer.WriteInt32 (hours);
29
30 writer.WriteRaw (jsonKeyMinutes);
31 writer.WriteInt32 (minutes);
32
33 writer.WriteEndObject ();
[391]34
[402]35 writer.WriteRaw (jsonKeyPlayers);
36 writer.WriteInt32 (GameManager.Instance.World.Players.Count);
37
38 writer.WriteRaw (jsonKeyHostiles);
39 writer.WriteInt32 (Hostiles.Instance.GetCount ());
40
41 writer.WriteRaw (jsonKeyAnimals);
42 writer.WriteInt32 (Animals.Instance.GetCount ());
43
44 writer.WriteEndObject ();
45
46 SendEnvelopedResult (_context, ref writer);
[391]47 }
48
[408]49 public override int DefaultPermissionLevel () => 2000;
[391]50 }
51}
Note: See TracBrowser for help on using the repository browser.