source: binary-improvements2/WebServer/src/WebAPI/APIs/WebUiUpdates.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.4 KB
Line 
1using JetBrains.Annotations;
2using Utf8Json;
3using Webserver.LiveData;
4using Webserver.Permissions;
5
6namespace Webserver.WebAPI.APIs {
7 [UsedImplicitly]
8 public class WebUiUpdates : 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 private static readonly byte[] jsonKeyNewLogs = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("newLogs");
14
15 private static readonly byte[] jsonKeyDays = JsonWriter.GetEncodedPropertyNameWithBeginObject ("days");
16 private static readonly byte[] jsonKeyHours = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hours");
17 private static readonly byte[] jsonKeyMinutes = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("minutes");
18
19
20 protected override void HandleRestGet (RequestContext _context) {
21 if (_context.Request.QueryString ["latestLine"] == null ||
22 !int.TryParse (_context.Request.QueryString ["latestLine"], out int latestLine)) {
23 latestLine = 0;
24 }
25
26 PrepareEnvelopedResult (out JsonWriter writer);
27
28 writer.WriteRaw (jsonKeyGameTime);
29
30 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime);
31
32 writer.WriteRaw (jsonKeyDays);
33 writer.WriteInt32 (days);
34
35 writer.WriteRaw (jsonKeyHours);
36 writer.WriteInt32 (hours);
37
38 writer.WriteRaw (jsonKeyMinutes);
39 writer.WriteInt32 (minutes);
40
41 writer.WriteEndObject ();
42
43 writer.WriteRaw (jsonKeyPlayers);
44 writer.WriteInt32 (GameManager.Instance.World.Players.Count);
45
46 writer.WriteRaw (jsonKeyHostiles);
47 writer.WriteInt32 (Hostiles.Instance.GetCount ());
48
49 writer.WriteRaw (jsonKeyAnimals);
50 writer.WriteInt32 (Animals.Instance.GetCount ());
51
52 writer.WriteRaw (jsonKeyNewLogs);
53 writer.WriteInt32 (LogBuffer.Instance.LatestLine - latestLine);
54
55 writer.WriteEndObject ();
56
57 SendEnvelopedResult (_context, ref writer);
58 }
59
60 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
61 }
62}
Note: See TracBrowser for help on using the repository browser.