[391] | 1 | using JetBrains.Annotations;
|
---|
[402] | 2 | using Utf8Json;
|
---|
[391] | 3 |
|
---|
[402] | 4 | namespace Webserver.WebAPI.APIs {
|
---|
[391] | 5 | [UsedImplicitly]
|
---|
[402] | 6 | public class ServerInfo : AbsRestApi {
|
---|
| 7 | private static readonly UnityEngine.Profiling.CustomSampler buildSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_ServerInfo_BuildSampler");
|
---|
[391] | 8 |
|
---|
[402] | 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 |
|
---|
[391] | 22 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
---|
| 23 |
|
---|
[402] | 24 | bool first = true;
|
---|
| 25 |
|
---|
| 26 |
|
---|
[391] | 27 |
|
---|
[402] | 28 | foreach (GameInfoString stringGamePref in EnumUtils.Values<GameInfoString> ()) {
|
---|
| 29 | string value = gsi.GetValue (stringGamePref);
|
---|
[391] | 30 |
|
---|
[402] | 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 ();
|
---|
[391] | 47 | }
|
---|
| 48 |
|
---|
[402] | 49 | foreach (GameInfoInt intGamePref in EnumUtils.Values<GameInfoInt> ()) {
|
---|
| 50 | int value = gsi.GetValue (intGamePref);
|
---|
[391] | 51 |
|
---|
[402] | 52 | if (!first) {
|
---|
| 53 | writer.WriteValueSeparator ();
|
---|
| 54 | }
|
---|
[391] | 55 |
|
---|
[402] | 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 ();
|
---|
[391] | 68 | }
|
---|
| 69 |
|
---|
[402] | 70 | foreach (GameInfoBool boolGamePref in EnumUtils.Values<GameInfoBool> ()) {
|
---|
| 71 | bool value = gsi.GetValue (boolGamePref);
|
---|
[391] | 72 |
|
---|
[402] | 73 | if (!first) {
|
---|
| 74 | writer.WriteValueSeparator ();
|
---|
| 75 | }
|
---|
[391] | 76 |
|
---|
[402] | 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 ();
|
---|
[391] | 89 | }
|
---|
[402] | 90 |
|
---|
| 91 | writer.WriteEndObject ();
|
---|
| 92 |
|
---|
| 93 | buildSampler.End ();
|
---|
[391] | 94 |
|
---|
[402] | 95 | int bufferContentSize = writer.CurrentOffset + 128;
|
---|
| 96 | if (bufferContentSize > largestBuffer) {
|
---|
| 97 | largestBuffer = bufferContentSize;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | SendEnvelopedResult (_context, ref writer);
|
---|
[391] | 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|