1 | using System.Net;
|
---|
2 | using JetBrains.Annotations;
|
---|
3 | using Utf8Json;
|
---|
4 | using Webserver;
|
---|
5 | using Webserver.Permissions;
|
---|
6 | using Webserver.WebAPI;
|
---|
7 |
|
---|
8 | namespace 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 | }
|
---|