[251] | 1 | using AllocsFixes.LiveData;
|
---|
[455] | 2 | using JetBrains.Annotations;
|
---|
| 3 | using Utf8Json;
|
---|
[454] | 4 | using Webserver;
|
---|
| 5 | using Webserver.WebAPI;
|
---|
[251] | 6 |
|
---|
[454] | 7 | namespace AllocsFixes.WebAPIs {
|
---|
[455] | 8 | [UsedImplicitly]
|
---|
[454] | 9 | public class GetStats : AbsWebAPI {
|
---|
[455] | 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 |
|
---|
[454] | 16 | public override void HandleRequest (RequestContext _context) {
|
---|
[455] | 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);
|
---|
[251] | 35 | }
|
---|
[279] | 36 |
|
---|
| 37 | public override int DefaultPermissionLevel () {
|
---|
| 38 | return 2000;
|
---|
| 39 | }
|
---|
[251] | 40 | }
|
---|
[325] | 41 | }
|
---|