- 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/ServerStats.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 GetStats : AbsWebAPI { 8 public override void HandleRequest (RequestContext _context) { 9 JsonObject result = new JsonObject (); 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"); 10 16 11 JsonObject time = new JsonObject (); 12 time.Add ("days", new JsonNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime))); 13 time.Add ("hours", new JsonNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime))); 14 time.Add ("minutes", new JsonNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime))); 15 result.Add ("gametime", time); 17 protected override void HandleRestGet (RequestContext _context) { 18 PrepareEnvelopedResult (out JsonWriter writer); 19 20 writer.WriteRaw (jsonKeyGameTime); 16 21 17 result.Add ("players", new JsonNumber (GameManager.Instance.World.Players.Count)); 18 result.Add ("hostiles", new JsonNumber (Hostiles.Instance.GetCount ())); 19 result.Add ("animals", new JsonNumber (Animals.Instance.GetCount ())); 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 (); 20 34 21 WebUtils.WriteJson (_context.Response, result); 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); 22 47 } 23 48
Note:
See TracChangeset
for help on using the changeset viewer.