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