[404] | 1 | using System.Collections.Generic;
|
---|
[391] | 2 | using JetBrains.Annotations;
|
---|
[402] | 3 | using Utf8Json;
|
---|
[437] | 4 | using Webserver.Permissions;
|
---|
[391] | 5 |
|
---|
[437] | 6 | namespace Webserver.WebAPI.APIs.ServerState {
|
---|
[391] | 7 | [UsedImplicitly]
|
---|
[402] | 8 | public class ServerInfo : AbsRestApi {
|
---|
| 9 | private static readonly UnityEngine.Profiling.CustomSampler buildSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_ServerInfo_BuildSampler");
|
---|
[391] | 10 |
|
---|
[402] | 11 | private static readonly byte[] keyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type");
|
---|
| 12 | private static readonly byte[] keyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value");
|
---|
| 13 |
|
---|
| 14 | private int largestBuffer;
|
---|
| 15 |
|
---|
| 16 | protected override void HandleRestGet (RequestContext _context) {
|
---|
| 17 | buildSampler.Begin ();
|
---|
| 18 |
|
---|
| 19 | PrepareEnvelopedResult (out JsonWriter writer);
|
---|
| 20 |
|
---|
| 21 | writer.EnsureCapacity (largestBuffer);
|
---|
| 22 | writer.WriteBeginObject ();
|
---|
| 23 |
|
---|
[391] | 24 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
---|
| 25 |
|
---|
[437] | 26 | bool first = true;
|
---|
| 27 |
|
---|
[404] | 28 | IList<GameInfoString> list = EnumUtils.Values<GameInfoString> ();
|
---|
| 29 | for (int i = 0; i < list.Count; i++) {
|
---|
| 30 | GameInfoString stringGamePref = list [i];
|
---|
[391] | 31 |
|
---|
[437] | 32 | if (!first) {
|
---|
[402] | 33 | writer.WriteValueSeparator ();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[437] | 36 | first = false;
|
---|
[404] | 37 |
|
---|
[437] | 38 | writer.WritePropertyName (stringGamePref.ToStringCached ());
|
---|
| 39 |
|
---|
[402] | 40 | writer.WriteRaw (keyType);
|
---|
| 41 | writer.WriteString ("string");
|
---|
[404] | 42 |
|
---|
[402] | 43 | writer.WriteRaw (keyValue);
|
---|
[404] | 44 | writer.WriteString (gsi.GetValue (stringGamePref));
|
---|
| 45 |
|
---|
[402] | 46 | writer.WriteEndObject ();
|
---|
[391] | 47 | }
|
---|
| 48 |
|
---|
[404] | 49 | IList<GameInfoInt> ints = EnumUtils.Values<GameInfoInt> ();
|
---|
| 50 | for (int i = 0; i < ints.Count; i++) {
|
---|
| 51 | GameInfoInt intGamePref = ints [i];
|
---|
[391] | 52 |
|
---|
[437] | 53 | if (!first) {
|
---|
[402] | 54 | writer.WriteValueSeparator ();
|
---|
| 55 | }
|
---|
[391] | 56 |
|
---|
[437] | 57 | first = false;
|
---|
[404] | 58 |
|
---|
[437] | 59 | writer.WritePropertyName (intGamePref.ToStringCached ());
|
---|
| 60 |
|
---|
[402] | 61 | writer.WriteRaw (keyType);
|
---|
| 62 | writer.WriteString ("int");
|
---|
[404] | 63 |
|
---|
[402] | 64 | writer.WriteRaw (keyValue);
|
---|
[404] | 65 | writer.WriteInt32 (gsi.GetValue (intGamePref));
|
---|
| 66 |
|
---|
[402] | 67 | writer.WriteEndObject ();
|
---|
[391] | 68 | }
|
---|
| 69 |
|
---|
[404] | 70 | IList<GameInfoBool> prefs = EnumUtils.Values<GameInfoBool> ();
|
---|
| 71 | for (int i = 0; i < prefs.Count; i++) {
|
---|
| 72 | GameInfoBool boolGamePref = prefs [i];
|
---|
[391] | 73 |
|
---|
[437] | 74 | if (!first) {
|
---|
[402] | 75 | writer.WriteValueSeparator ();
|
---|
| 76 | }
|
---|
[391] | 77 |
|
---|
[437] | 78 | first = false;
|
---|
[404] | 79 |
|
---|
[437] | 80 | writer.WritePropertyName (boolGamePref.ToStringCached ());
|
---|
| 81 |
|
---|
[402] | 82 | writer.WriteRaw (keyType);
|
---|
| 83 | writer.WriteString ("bool");
|
---|
[404] | 84 |
|
---|
[402] | 85 | writer.WriteRaw (keyValue);
|
---|
[404] | 86 | writer.WriteBoolean (gsi.GetValue (boolGamePref));
|
---|
| 87 |
|
---|
[402] | 88 | writer.WriteEndObject ();
|
---|
[391] | 89 | }
|
---|
[404] | 90 |
|
---|
[402] | 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 | }
|
---|
[437] | 102 |
|
---|
| 103 | public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
|
---|
[391] | 104 | }
|
---|
| 105 | }
|
---|