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

Last change on this file since 427 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
Line 
1using JetBrains.Annotations;
2using Utf8Json;
3using Webserver.LiveData;
4using Webserver.Permissions;
5
6namespace Webserver.WebAPI.APIs {
7 [UsedImplicitly]
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");
17
18 protected override void HandleRestGet (RequestContext _context) {
19 PrepareEnvelopedResult (out JsonWriter writer);
20
21 writer.WriteRaw (jsonKeyGameTime);
22
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 ();
35
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);
48 }
49
50 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
51 }
52}
Note: See TracBrowser for help on using the repository browser.