Changeset 455 for binary-improvements/MapRendering/API/GetServerInfo.cs
- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetServerInfo.cs
r454 r455 1 1 using System; 2 using AllocsFixes.JSON; 2 using JetBrains.Annotations; 3 using Utf8Json; 3 4 using Webserver; 4 5 using Webserver.WebAPI; 5 6 6 7 namespace AllocsFixes.WebAPIs { 8 [UsedImplicitly] 7 9 public class GetServerInfo : AbsWebAPI { 10 private static readonly byte[] jsonKeyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type"); 11 private static readonly byte[] jsonKeyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value"); 12 8 13 public override void HandleRequest (RequestContext _context) { 9 JSONObject serverInfo = new JSONObject ();14 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo; 10 15 11 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo; 16 JsonWriter writer = new JsonWriter (); 17 writer.WriteBeginObject (); 18 19 bool first = true; 12 20 13 21 foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) { 14 22 string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref)); 23 24 if (!first) { 25 writer.WriteValueSeparator (); 26 } 15 27 16 JSONObject singleStat = new JSONObject (); 17 singleStat.Add ("type", new JSONString ("string")); 18 singleStat.Add ("value", new JSONString (value)); 28 first = false; 19 29 20 serverInfo.Add (stringGamePref, singleStat); 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 (); 21 38 } 22 39 … … 24 41 int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref)); 25 42 26 JSONObject singleStat = new JSONObject ();27 singleStat.Add ("type", new JSONString ("int"));28 singleStat.Add ("value", new JSONNumber (value));43 if (!first) { 44 writer.WriteValueSeparator (); 45 } 29 46 30 serverInfo.Add (intGamePref, singleStat); 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 (); 31 57 } 32 58 … … 34 60 bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref)); 35 61 36 JSONObject singleStat = new JSONObject ();37 singleStat.Add ("type", new JSONString ("bool"));38 singleStat.Add ("value", new JSONBoolean (value));62 if (!first) { 63 writer.WriteValueSeparator (); 64 } 39 65 40 serverInfo.Add (boolGamePref, singleStat); 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 (); 41 76 } 42 43 44 LegacyApiHelper.WriteJSON (_context.Response, serverInfo); 77 78 writer.WriteEndObject (); 79 80 WebUtils.WriteJsonData (_context.Response, ref writer); 45 81 } 46 82 }
Note:
See TracChangeset
for help on using the changeset viewer.