1 | using JetBrains.Annotations;
|
---|
2 | using Utf8Json;
|
---|
3 | using Webserver.LiveData;
|
---|
4 | using Webserver.Permissions;
|
---|
5 |
|
---|
6 | namespace Webserver.WebAPI.APIs.ServerState {
|
---|
7 | [UsedImplicitly]
|
---|
8 | public class ServerStats : AbsRestApi {
|
---|
9 | private static readonly byte[] jsonKeyGameTime = JsonWriter.GetEncodedPropertyNameWithBeginObject ("gameTime");
|
---|
10 | private static readonly byte[] jsonKeyPlayers = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("players");
|
---|
11 | private static readonly byte[] jsonKeyHostiles = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hostiles");
|
---|
12 | private static readonly byte[] jsonKeyAnimals = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("animals");
|
---|
13 |
|
---|
14 |
|
---|
15 | protected override void HandleRestGet (RequestContext _context) {
|
---|
16 | PrepareEnvelopedResult (out JsonWriter writer);
|
---|
17 |
|
---|
18 | writer.WriteRaw (jsonKeyGameTime);
|
---|
19 | (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
|
---|
20 | JsonCommons.WriteGameTimeObject (ref writer, days, hours, minutes);
|
---|
21 |
|
---|
22 | writer.WriteRaw (jsonKeyPlayers);
|
---|
23 | writer.WriteInt32 (GameManager.Instance.World.Players.Count);
|
---|
24 |
|
---|
25 | writer.WriteRaw (jsonKeyHostiles);
|
---|
26 | writer.WriteInt32 (Hostiles.Instance.GetCount ());
|
---|
27 |
|
---|
28 | writer.WriteRaw (jsonKeyAnimals);
|
---|
29 | writer.WriteInt32 (Animals.Instance.GetCount ());
|
---|
30 |
|
---|
31 | writer.WriteEndObject ();
|
---|
32 |
|
---|
33 | SendEnvelopedResult (_context, ref writer);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
|
---|
37 | }
|
---|
38 | }
|
---|