source: TFP-WebServer/WebServer/src/WebAPI/APIs/GameData/EntityClass.cs@ 485

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

22.0.0.0 Commands release

  • Only A22 compatibility fix

22.0.0.0 MapRendering release (no code changes)

22.0.1.0 WebServer release

  • Updated to dashboard files 0.8.5
  • Added API 'EntityClass'
  • Changed API 'Command' default permissions
  • Added some A22 compatibility changes
  • Fixed some OpenAPI docs

22.0.1.0 MarkersMod release

  • Updated web files
File size: 2.0 KB
Line 
1using JetBrains.Annotations;
2using Utf8Json;
3using Webserver.Permissions;
4
5namespace Webserver.WebAPI.APIs.GameData {
6 [UsedImplicitly]
7 internal class EntityClass : AbsRestApi {
8 private static readonly byte[] jsonKeyName = JsonWriter.GetEncodedPropertyNameWithBeginObject ("name");
9 private static readonly byte[] jsonKeyId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("id");
10 private static readonly byte[] jsonKeyCommandIndex = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("commandId");
11 private static readonly byte[] jsonKeyManualSpawnType = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("manualSpawnType");
12
13 private readonly byte[] allClassesSerialized;
14
15 public EntityClass (Web _parent) {
16 JsonWriter writer = new JsonWriter ();
17
18 writer.WriteBeginArray ();
19
20 int written = 0;
21 int iCommandIndex = 0;
22 foreach ((int id, global::EntityClass entityClass) in global::EntityClass.list.Dict) {
23 if (written > 0) {
24 writer.WriteValueSeparator ();
25 }
26
27 written++;
28
29 string name = entityClass.entityClassName;
30 global::EntityClass.UserSpawnType spawnType = entityClass.userSpawnType;
31
32 writer.WriteRaw (jsonKeyName);
33 writer.WriteString (name);
34
35 writer.WriteRaw (jsonKeyId);
36 writer.WriteInt32 (id);
37
38 if (entityClass.userSpawnType != global::EntityClass.UserSpawnType.None) {
39 iCommandIndex++;
40
41 writer.WriteRaw (jsonKeyCommandIndex);
42 writer.WriteInt32 (iCommandIndex);
43 }
44
45 writer.WriteRaw (jsonKeyManualSpawnType);
46 writer.WriteString (spawnType.ToStringCached ());
47
48 writer.WriteEndObject ();
49 }
50
51 writer.WriteEndArray ();
52
53 allClassesSerialized = writer.ToUtf8ByteArray ();
54 }
55
56 protected override void HandleRestGet (RequestContext _context) {
57 PrepareEnvelopedResult (out JsonWriter writer);
58 writer.WriteRaw (allClassesSerialized);
59 SendEnvelopedResult (_context, ref writer);
60 }
61
62 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
63 }
64}
Note: See TracBrowser for help on using the repository browser.