| 1 | using System; | 
|---|
| 2 | using JetBrains.Annotations; | 
|---|
| 3 | using Utf8Json; | 
|---|
| 4 | using Webserver; | 
|---|
| 5 | using Webserver.WebAPI; | 
|---|
| 6 |  | 
|---|
| 7 | namespace AllocsFixes.WebAPIs { | 
|---|
| 8 | [UsedImplicitly] | 
|---|
| 9 | public class GetServerInfo : AbsWebAPI { | 
|---|
| 10 | private static readonly byte[] jsonKeyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type"); | 
|---|
| 11 | private static readonly byte[] jsonKeyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value"); | 
|---|
| 12 |  | 
|---|
| 13 | public override void HandleRequest (RequestContext _context) { | 
|---|
| 14 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo; | 
|---|
| 15 |  | 
|---|
| 16 | JsonWriter writer = new JsonWriter (); | 
|---|
| 17 | writer.WriteBeginObject (); | 
|---|
| 18 |  | 
|---|
| 19 | bool first = true; | 
|---|
| 20 |  | 
|---|
| 21 | foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) { | 
|---|
| 22 | string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref)); | 
|---|
| 23 |  | 
|---|
| 24 | if (!first) { | 
|---|
| 25 | writer.WriteValueSeparator (); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | first = false; | 
|---|
| 29 |  | 
|---|
| 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 (); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) { | 
|---|
| 41 | int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref)); | 
|---|
| 42 |  | 
|---|
| 43 | if (!first) { | 
|---|
| 44 | writer.WriteValueSeparator (); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 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 (); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) { | 
|---|
| 60 | bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref)); | 
|---|
| 61 |  | 
|---|
| 62 | if (!first) { | 
|---|
| 63 | writer.WriteValueSeparator (); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 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 (); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | writer.WriteEndObject (); | 
|---|
| 79 |  | 
|---|
| 80 | WebUtils.WriteJsonData (_context.Response, ref writer); | 
|---|
| 81 | } | 
|---|
| 82 | } | 
|---|
| 83 | } | 
|---|