source: TFP-WebServer/MapRendering/src/Api/Map.cs@ 485

Last change on this file since 485 was 444, checked in by alloc, 17 months ago

Added more details to API map/config
Updated web files to 0.7.0

File size: 2.0 KB
RevLine 
[425]1using System.Net;
2using JetBrains.Annotations;
3using Utf8Json;
4using Webserver;
[426]5using Webserver.Permissions;
[425]6using Webserver.WebAPI;
7
8namespace MapRendering.Api {
9 [UsedImplicitly]
10 public class Map : AbsRestApi {
11
12 protected override void HandleRestGet (RequestContext _context) {
13 string id = _context.RequestPath;
14
15 PrepareEnvelopedResult (out JsonWriter writer);
16
17 switch (id) {
18 case "config":
[444]19 writeConfig (ref writer);
[425]20 break;
21 default:
[434]22 SendEmptyResponse (_context, HttpStatusCode.NotImplemented, _errorCode: "INVALID_ID");
[425]23 return;
24 }
25
26 SendEnvelopedResult (_context, ref writer);
27 }
28
[444]29 private static readonly byte[] jsonKeyEnabled = JsonWriter.GetEncodedPropertyNameWithBeginObject ("enabled");
30 private static readonly byte[] jsonKeyMapBlockSize = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("mapBlockSize");
31 private static readonly byte[] jsonKeyMaxZoom = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("maxZoom");
32 private static readonly byte[] jsonKeyMapSize = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("mapSize");
33
34 private void writeConfig (ref JsonWriter writer) {
35 writer.WriteRaw (jsonKeyEnabled);
36 writer.WriteBoolean (MapRenderer.Enabled);
37
38 writer.WriteRaw (jsonKeyMapBlockSize);
39 writer.WriteInt32 (Constants.MapBlockSize);
40
41 writer.WriteRaw (jsonKeyMaxZoom);
42 writer.WriteInt32 (Constants.Zoomlevels - 1);
43
44 GameManager.Instance.World.GetWorldExtent (out Vector3i worldMinPos, out Vector3i worldMaxPos);
45 Vector3i worldSize = worldMaxPos - worldMinPos;
46
47 writer.WriteRaw (jsonKeyMapSize);
48 JsonCommons.WriteVector3I (ref writer, worldSize);
49
50 writer.WriteEndObject ();
51 }
52
[426]53 public override int[] DefaultMethodPermissionLevels () => new[] {
54 AdminWebModules.MethodLevelNotSupported,
55 AdminWebModules.PermissionLevelGuest,
56 AdminWebModules.MethodLevelInheritGlobal,
57 AdminWebModules.MethodLevelInheritGlobal,
58 AdminWebModules.MethodLevelInheritGlobal
59 };
[425]60 }
61}
Note: See TracBrowser for help on using the repository browser.