1 | using JetBrains.Annotations;
|
---|
2 | using Utf8Json;
|
---|
3 | using Webserver.LiveData;
|
---|
4 |
|
---|
5 | namespace Webserver.WebAPI.APIs {
|
---|
6 | [UsedImplicitly]
|
---|
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");
|
---|
16 |
|
---|
17 | protected override void HandleRestGet (RequestContext _context) {
|
---|
18 | PrepareEnvelopedResult (out JsonWriter writer);
|
---|
19 |
|
---|
20 | writer.WriteRaw (jsonKeyGameTime);
|
---|
21 |
|
---|
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 ();
|
---|
34 |
|
---|
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);
|
---|
47 | }
|
---|
48 |
|
---|
49 | public override int DefaultPermissionLevel () => 2000;
|
---|
50 | }
|
---|
51 | }
|
---|