source: binary-improvements2/WebServer/src/WebAPI/APIs/ServerStats.cs@ 435

Last change on this file since 435 was 426, checked in by alloc, 19 months ago

*Updated web permissions system
*Fixed webpermissions command
*Moved API "webmods" to "mods", also lists non-webmod mods

File size: 2.0 KB
RevLine 
[391]1using JetBrains.Annotations;
[402]2using Utf8Json;
3using Webserver.LiveData;
[426]4using Webserver.Permissions;
[391]5
[402]6namespace Webserver.WebAPI.APIs {
[391]7 [UsedImplicitly]
[402]8 public class ServerStats : AbsRestApi {
9 private static readonly byte[] jsonKeyGameTime = JsonWriter.GetEncodedPropertyNameWithBeginObject ("gameTime");
10 private static readonly byte[] jsonKeyPlayers = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("players");
11 private static readonly byte[] jsonKeyHostiles = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hostiles");
12 private static readonly byte[] jsonKeyAnimals = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("animals");
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");
[391]17
[402]18 protected override void HandleRestGet (RequestContext _context) {
19 PrepareEnvelopedResult (out JsonWriter writer);
20
21 writer.WriteRaw (jsonKeyGameTime);
[391]22
[402]23 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
24
25 writer.WriteRaw (jsonKeyDays);
26 writer.WriteInt32 (days);
27
28 writer.WriteRaw (jsonKeyHours);
29 writer.WriteInt32 (hours);
30
31 writer.WriteRaw (jsonKeyMinutes);
32 writer.WriteInt32 (minutes);
33
34 writer.WriteEndObject ();
[391]35
[402]36 writer.WriteRaw (jsonKeyPlayers);
37 writer.WriteInt32 (GameManager.Instance.World.Players.Count);
38
39 writer.WriteRaw (jsonKeyHostiles);
40 writer.WriteInt32 (Hostiles.Instance.GetCount ());
41
42 writer.WriteRaw (jsonKeyAnimals);
43 writer.WriteInt32 (Animals.Instance.GetCount ());
44
45 writer.WriteEndObject ();
46
47 SendEnvelopedResult (_context, ref writer);
[391]48 }
49
[426]50 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
[391]51 }
52}
Note: See TracBrowser for help on using the repository browser.