1 | using JetBrains.Annotations;
|
---|
2 | using Utf8Json;
|
---|
3 |
|
---|
4 | namespace Webserver.WebAPI.APIs {
|
---|
5 | [UsedImplicitly]
|
---|
6 | public class ServerInfo : AbsRestApi {
|
---|
7 | private static readonly UnityEngine.Profiling.CustomSampler buildSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_ServerInfo_BuildSampler");
|
---|
8 |
|
---|
9 | private static readonly byte[] keyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type");
|
---|
10 | private static readonly byte[] keyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value");
|
---|
11 |
|
---|
12 | private int largestBuffer;
|
---|
13 |
|
---|
14 | protected override void HandleRestGet (RequestContext _context) {
|
---|
15 | buildSampler.Begin ();
|
---|
16 |
|
---|
17 | PrepareEnvelopedResult (out JsonWriter writer);
|
---|
18 |
|
---|
19 | writer.EnsureCapacity (largestBuffer);
|
---|
20 | writer.WriteBeginObject ();
|
---|
21 |
|
---|
22 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
---|
23 |
|
---|
24 | bool first = true;
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 | foreach (GameInfoString stringGamePref in EnumUtils.Values<GameInfoString> ()) {
|
---|
29 | string value = gsi.GetValue (stringGamePref);
|
---|
30 |
|
---|
31 | if (!first) {
|
---|
32 | writer.WriteValueSeparator ();
|
---|
33 | }
|
---|
34 |
|
---|
35 | first = false;
|
---|
36 |
|
---|
37 | writer.WriteString (stringGamePref.ToStringCached ());
|
---|
38 | writer.WriteNameSeparator ();
|
---|
39 |
|
---|
40 | writer.WriteRaw (keyType);
|
---|
41 | writer.WriteString ("string");
|
---|
42 |
|
---|
43 | writer.WriteRaw (keyValue);
|
---|
44 | writer.WriteString (value);
|
---|
45 |
|
---|
46 | writer.WriteEndObject ();
|
---|
47 | }
|
---|
48 |
|
---|
49 | foreach (GameInfoInt intGamePref in EnumUtils.Values<GameInfoInt> ()) {
|
---|
50 | int value = gsi.GetValue (intGamePref);
|
---|
51 |
|
---|
52 | if (!first) {
|
---|
53 | writer.WriteValueSeparator ();
|
---|
54 | }
|
---|
55 |
|
---|
56 | first = false;
|
---|
57 |
|
---|
58 | writer.WriteString (intGamePref.ToStringCached ());
|
---|
59 | writer.WriteNameSeparator ();
|
---|
60 |
|
---|
61 | writer.WriteRaw (keyType);
|
---|
62 | writer.WriteString ("int");
|
---|
63 |
|
---|
64 | writer.WriteRaw (keyValue);
|
---|
65 | writer.WriteInt32 (value);
|
---|
66 |
|
---|
67 | writer.WriteEndObject ();
|
---|
68 | }
|
---|
69 |
|
---|
70 | foreach (GameInfoBool boolGamePref in EnumUtils.Values<GameInfoBool> ()) {
|
---|
71 | bool value = gsi.GetValue (boolGamePref);
|
---|
72 |
|
---|
73 | if (!first) {
|
---|
74 | writer.WriteValueSeparator ();
|
---|
75 | }
|
---|
76 |
|
---|
77 | first = false;
|
---|
78 |
|
---|
79 | writer.WriteString (boolGamePref.ToStringCached ());
|
---|
80 | writer.WriteNameSeparator ();
|
---|
81 |
|
---|
82 | writer.WriteRaw (keyType);
|
---|
83 | writer.WriteString ("bool");
|
---|
84 |
|
---|
85 | writer.WriteRaw (keyValue);
|
---|
86 | writer.WriteBoolean (value);
|
---|
87 |
|
---|
88 | writer.WriteEndObject ();
|
---|
89 | }
|
---|
90 |
|
---|
91 | writer.WriteEndObject ();
|
---|
92 |
|
---|
93 | buildSampler.End ();
|
---|
94 |
|
---|
95 | int bufferContentSize = writer.CurrentOffset + 128;
|
---|
96 | if (bufferContentSize > largestBuffer) {
|
---|
97 | largestBuffer = bufferContentSize;
|
---|
98 | }
|
---|
99 |
|
---|
100 | SendEnvelopedResult (_context, ref writer);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|