- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- Location:
- binary-improvements2/WebServer/src/WebAPI/APIs
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/WebAPI/APIs/WebUiUpdates.cs
r401 r402 1 using AllocsFixes.JSON;2 using AllocsFixes.LiveData;3 1 using JetBrains.Annotations; 2 using Utf8Json; 3 using Webserver.LiveData; 4 4 5 namespace Webserver.WebAPI {5 namespace Webserver.WebAPI.APIs { 6 6 [UsedImplicitly] 7 public class GetWebUIUpdates : AbsWebAPI { 8 public override void HandleRequest (RequestContext _context) { 7 public class WebUiUpdates : 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 private static readonly byte[] jsonKeyNewLogs = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("newLogs"); 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"); 17 18 19 protected override void HandleRestGet (RequestContext _context) { 9 20 if (_context.Request.QueryString ["latestLine"] == null || 10 21 !int.TryParse (_context.Request.QueryString ["latestLine"], out int latestLine)) { 11 22 latestLine = 0; 12 23 } 24 25 PrepareEnvelopedResult (out JsonWriter writer); 26 27 writer.WriteRaw (jsonKeyGameTime); 13 28 14 JsonObject result = new JsonObject (); 29 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime); 30 31 writer.WriteRaw (jsonKeyDays); 32 writer.WriteInt32 (days); 33 34 writer.WriteRaw (jsonKeyHours); 35 writer.WriteInt32 (hours); 36 37 writer.WriteRaw (jsonKeyMinutes); 38 writer.WriteInt32 (minutes); 39 40 writer.WriteEndObject (); 15 41 16 JsonObject time = new JsonObject (); 17 time.Add ("days", new JsonNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime))); 18 time.Add ("hours", new JsonNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime))); 19 time.Add ("minutes", new JsonNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime))); 20 result.Add ("gametime", time); 42 writer.WriteRaw (jsonKeyPlayers); 43 writer.WriteInt32 (GameManager.Instance.World.Players.Count); 44 45 writer.WriteRaw (jsonKeyHostiles); 46 writer.WriteInt32 (Hostiles.Instance.GetCount ()); 47 48 writer.WriteRaw (jsonKeyAnimals); 49 writer.WriteInt32 (Animals.Instance.GetCount ()); 50 51 writer.WriteRaw (jsonKeyNewLogs); 52 writer.WriteInt32 (LogBuffer.Instance.LatestLine - latestLine); 21 53 22 result.Add ("players", new JsonNumber (GameManager.Instance.World.Players.Count)); 23 result.Add ("hostiles", new JsonNumber (Hostiles.Instance.GetCount ())); 24 result.Add ("animals", new JsonNumber (Animals.Instance.GetCount ())); 54 writer.WriteEndObject (); 25 55 26 result.Add ("newlogs", new JsonNumber (LogBuffer.Instance.LatestLine - latestLine)); 27 28 WebUtils.WriteJson (_context.Response, result); 56 SendEnvelopedResult (_context, ref writer); 29 57 } 30 58
Note:
See TracChangeset
for help on using the changeset viewer.