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

Last change on this file since 461 was 444, checked in by alloc, 18 months ago

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

File size: 2.0 KB
Line 
1using System.Net;
2using JetBrains.Annotations;
3using Utf8Json;
4using Webserver;
5using Webserver.Permissions;
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":
19 writeConfig (ref writer);
20 break;
21 default:
22 SendEmptyResponse (_context, HttpStatusCode.NotImplemented, _errorCode: "INVALID_ID");
23 return;
24 }
25
26 SendEnvelopedResult (_context, ref writer);
27 }
28
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
53 public override int[] DefaultMethodPermissionLevels () => new[] {
54 AdminWebModules.MethodLevelNotSupported,
55 AdminWebModules.PermissionLevelGuest,
56 AdminWebModules.MethodLevelInheritGlobal,
57 AdminWebModules.MethodLevelInheritGlobal,
58 AdminWebModules.MethodLevelInheritGlobal
59 };
60 }
61}
Note: See TracBrowser for help on using the repository browser.