[279] | 1 | using System;
|
---|
[455] | 2 | using JetBrains.Annotations;
|
---|
| 3 | using Utf8Json;
|
---|
[454] | 4 | using Webserver;
|
---|
| 5 | using Webserver.WebAPI;
|
---|
[279] | 6 |
|
---|
[454] | 7 | namespace AllocsFixes.WebAPIs {
|
---|
[455] | 8 | [UsedImplicitly]
|
---|
[454] | 9 | public class GetServerInfo : AbsWebAPI {
|
---|
[455] | 10 | private static readonly byte[] jsonKeyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type");
|
---|
| 11 | private static readonly byte[] jsonKeyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value");
|
---|
| 12 |
|
---|
[454] | 13 | public override void HandleRequest (RequestContext _context) {
|
---|
[360] | 14 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
---|
[279] | 15 |
|
---|
[455] | 16 | JsonWriter writer = new JsonWriter ();
|
---|
| 17 | writer.WriteBeginObject ();
|
---|
| 18 |
|
---|
| 19 | bool first = true;
|
---|
| 20 |
|
---|
[325] | 21 | foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) {
|
---|
| 22 | string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref));
|
---|
[455] | 23 |
|
---|
| 24 | if (!first) {
|
---|
| 25 | writer.WriteValueSeparator ();
|
---|
| 26 | }
|
---|
[279] | 27 |
|
---|
[455] | 28 | first = false;
|
---|
[279] | 29 |
|
---|
[455] | 30 | writer.WritePropertyName (stringGamePref);
|
---|
| 31 | writer.WriteRaw (jsonKeyType);
|
---|
| 32 | writer.WriteString ("string");
|
---|
| 33 |
|
---|
| 34 | writer.WriteRaw (jsonKeyValue);
|
---|
| 35 | writer.WriteString (value);
|
---|
| 36 |
|
---|
| 37 | writer.WriteEndObject ();
|
---|
[279] | 38 | }
|
---|
| 39 |
|
---|
[325] | 40 | foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) {
|
---|
| 41 | int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref));
|
---|
[279] | 42 |
|
---|
[455] | 43 | if (!first) {
|
---|
| 44 | writer.WriteValueSeparator ();
|
---|
| 45 | }
|
---|
[279] | 46 |
|
---|
[455] | 47 | first = false;
|
---|
| 48 |
|
---|
| 49 | writer.WritePropertyName (intGamePref);
|
---|
| 50 | writer.WriteRaw (jsonKeyType);
|
---|
| 51 | writer.WriteString ("int");
|
---|
| 52 |
|
---|
| 53 | writer.WriteRaw (jsonKeyValue);
|
---|
| 54 | writer.WriteInt32 (value);
|
---|
| 55 |
|
---|
| 56 | writer.WriteEndObject ();
|
---|
[279] | 57 | }
|
---|
| 58 |
|
---|
[325] | 59 | foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) {
|
---|
| 60 | bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref));
|
---|
[279] | 61 |
|
---|
[455] | 62 | if (!first) {
|
---|
| 63 | writer.WriteValueSeparator ();
|
---|
| 64 | }
|
---|
[279] | 65 |
|
---|
[455] | 66 | first = false;
|
---|
| 67 |
|
---|
| 68 | writer.WritePropertyName (boolGamePref);
|
---|
| 69 | writer.WriteRaw (jsonKeyType);
|
---|
| 70 | writer.WriteString ("bool");
|
---|
| 71 |
|
---|
| 72 | writer.WriteRaw (jsonKeyValue);
|
---|
| 73 | writer.WriteBoolean (value);
|
---|
| 74 |
|
---|
| 75 | writer.WriteEndObject ();
|
---|
[279] | 76 | }
|
---|
[455] | 77 |
|
---|
| 78 | writer.WriteEndObject ();
|
---|
| 79 |
|
---|
| 80 | WebUtils.WriteJsonData (_context.Response, ref writer);
|
---|
[279] | 81 | }
|
---|
| 82 | }
|
---|
[325] | 83 | }
|
---|