[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 GetWebUIUpdates : 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 | private static readonly byte[] jsonKeyNewLogs = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("newlogs");
|
---|
| 16 |
|
---|
[454] | 17 | public override void HandleRequest (RequestContext _context) {
|
---|
[251] | 18 | int latestLine;
|
---|
[454] | 19 | if (_context.Request.QueryString ["latestLine"] == null ||
|
---|
| 20 | !int.TryParse (_context.Request.QueryString ["latestLine"], out latestLine)) {
|
---|
[251] | 21 | latestLine = 0;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[455] | 24 | JsonWriter writer = new JsonWriter ();
|
---|
[251] | 25 |
|
---|
[455] | 26 | writer.WriteRaw (jsonKeyGameTime);
|
---|
| 27 | (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
|
---|
| 28 | JsonCommons.WriteGameTimeObject (ref writer, days, hours, minutes);
|
---|
| 29 |
|
---|
| 30 | writer.WriteRaw (jsonKeyPlayers);
|
---|
| 31 | writer.WriteInt32 (GameManager.Instance.World.Players.Count);
|
---|
| 32 |
|
---|
| 33 | writer.WriteRaw (jsonKeyHostiles);
|
---|
| 34 | writer.WriteInt32 (Hostiles.Instance.GetCount ());
|
---|
| 35 |
|
---|
| 36 | writer.WriteRaw (jsonKeyAnimals);
|
---|
| 37 | writer.WriteInt32 (Animals.Instance.GetCount ());
|
---|
| 38 |
|
---|
| 39 | writer.WriteRaw (jsonKeyNewLogs);
|
---|
| 40 | writer.WriteInt32 (LogBuffer.Instance.LatestLine - latestLine);
|
---|
| 41 |
|
---|
| 42 | writer.WriteEndObject ();
|
---|
| 43 |
|
---|
| 44 | WebUtils.WriteJsonData (_context.Response, ref writer);
|
---|
[251] | 45 | }
|
---|
[279] | 46 |
|
---|
| 47 | public override int DefaultPermissionLevel () {
|
---|
| 48 | return 2000;
|
---|
| 49 | }
|
---|
[251] | 50 | }
|
---|
[325] | 51 | }
|
---|