source: binary-improvements2/WebServer/src/WebAPI/APIs/WebUiUpdates.cs@ 434

Last change on this file since 434 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
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 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) {
[391]21 if (_context.Request.QueryString ["latestLine"] == null ||
22 !int.TryParse (_context.Request.QueryString ["latestLine"], out int latestLine)) {
23 latestLine = 0;
24 }
[402]25
26 PrepareEnvelopedResult (out JsonWriter writer);
27
28 writer.WriteRaw (jsonKeyGameTime);
[391]29
[402]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 ();
[391]42
[402]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);
[391]54
[402]55 writer.WriteEndObject ();
[391]56
[402]57 SendEnvelopedResult (_context, ref writer);
[391]58 }
59
[426]60 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
[391]61 }
62}
Note: See TracBrowser for help on using the repository browser.