[391] | 1 | using JetBrains.Annotations;
|
---|
[402] | 2 | using Utf8Json;
|
---|
| 3 | using Webserver.LiveData;
|
---|
[426] | 4 | using Webserver.Permissions;
|
---|
[391] | 5 |
|
---|
[402] | 6 | namespace Webserver.WebAPI.APIs {
|
---|
[391] | 7 | [UsedImplicitly]
|
---|
[402] | 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 | private static readonly byte[] jsonKeyDays = JsonWriter.GetEncodedPropertyNameWithBeginObject ("days");
|
---|
| 15 | private static readonly byte[] jsonKeyHours = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hours");
|
---|
| 16 | private static readonly byte[] jsonKeyMinutes = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("minutes");
|
---|
[391] | 17 |
|
---|
[402] | 18 | protected override void HandleRestGet (RequestContext _context) {
|
---|
| 19 | PrepareEnvelopedResult (out JsonWriter writer);
|
---|
| 20 |
|
---|
| 21 | writer.WriteRaw (jsonKeyGameTime);
|
---|
[391] | 22 |
|
---|
[402] | 23 | (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
|
---|
| 24 |
|
---|
| 25 | writer.WriteRaw (jsonKeyDays);
|
---|
| 26 | writer.WriteInt32 (days);
|
---|
| 27 |
|
---|
| 28 | writer.WriteRaw (jsonKeyHours);
|
---|
| 29 | writer.WriteInt32 (hours);
|
---|
| 30 |
|
---|
| 31 | writer.WriteRaw (jsonKeyMinutes);
|
---|
| 32 | writer.WriteInt32 (minutes);
|
---|
| 33 |
|
---|
| 34 | writer.WriteEndObject ();
|
---|
[391] | 35 |
|
---|
[402] | 36 | writer.WriteRaw (jsonKeyPlayers);
|
---|
| 37 | writer.WriteInt32 (GameManager.Instance.World.Players.Count);
|
---|
| 38 |
|
---|
| 39 | writer.WriteRaw (jsonKeyHostiles);
|
---|
| 40 | writer.WriteInt32 (Hostiles.Instance.GetCount ());
|
---|
| 41 |
|
---|
| 42 | writer.WriteRaw (jsonKeyAnimals);
|
---|
| 43 | writer.WriteInt32 (Animals.Instance.GetCount ());
|
---|
| 44 |
|
---|
| 45 | writer.WriteEndObject ();
|
---|
| 46 |
|
---|
| 47 | SendEnvelopedResult (_context, ref writer);
|
---|
[391] | 48 | }
|
---|
| 49 |
|
---|
[426] | 50 | public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
|
---|
[391] | 51 | }
|
---|
| 52 | }
|
---|