1 | using AllocsFixes.LiveData;
|
---|
2 | using JetBrains.Annotations;
|
---|
3 | using Utf8Json;
|
---|
4 | using Webserver;
|
---|
5 | using Webserver.WebAPI;
|
---|
6 |
|
---|
7 | namespace 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 | }
|
---|