[391] | 1 | using JetBrains.Annotations;
|
---|
[402] | 2 | using Utf8Json;
|
---|
| 3 | using Webserver.LiveData;
|
---|
[391] | 4 |
|
---|
[402] | 5 | namespace 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 |
|
---|
| 49 | public override int DefaultPermissionLevel () {
|
---|
| 50 | return 2000;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|