- Timestamp:
- Aug 7, 2023, 12:26:05 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/src/WebAPI/APIs/ServerState/ServerInfo.cs
r437 r457 6 6 namespace Webserver.WebAPI.APIs.ServerState { 7 7 [UsedImplicitly] 8 public class ServerInfo : AbsRestApi { 9 private static readonly UnityEngine.Profiling.CustomSampler buildSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_ServerInfo_BuildSampler"); 8 public class ServerInfo : KeyValueListAbs { 9 public ServerInfo () : base ("ServerInfo") { 10 } 10 11 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 12 protected override void iterateList (ref JsonWriter _writer, ref bool _first) { 24 13 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo; 25 26 bool first = true;27 14 28 15 IList<GameInfoString> list = EnumUtils.Values<GameInfoString> (); 29 16 for (int i = 0; i < list.Count; i++) { 30 17 GameInfoString stringGamePref = list [i]; 31 32 if (!first) { 33 writer.WriteValueSeparator (); 34 } 35 36 first = false; 37 38 writer.WritePropertyName (stringGamePref.ToStringCached ()); 39 40 writer.WriteRaw (keyType); 41 writer.WriteString ("string"); 42 43 writer.WriteRaw (keyValue); 44 writer.WriteString (gsi.GetValue (stringGamePref)); 45 46 writer.WriteEndObject (); 18 addItem (ref _writer, ref _first, stringGamePref.ToStringCached (), gsi.GetValue (stringGamePref)); 47 19 } 48 20 … … 50 22 for (int i = 0; i < ints.Count; i++) { 51 23 GameInfoInt intGamePref = ints [i]; 52 53 if (!first) { 54 writer.WriteValueSeparator (); 55 } 56 57 first = false; 58 59 writer.WritePropertyName (intGamePref.ToStringCached ()); 60 61 writer.WriteRaw (keyType); 62 writer.WriteString ("int"); 63 64 writer.WriteRaw (keyValue); 65 writer.WriteInt32 (gsi.GetValue (intGamePref)); 66 67 writer.WriteEndObject (); 24 addItem (ref _writer, ref _first, intGamePref.ToStringCached (), gsi.GetValue (intGamePref)); 68 25 } 69 26 … … 71 28 for (int i = 0; i < prefs.Count; i++) { 72 29 GameInfoBool boolGamePref = prefs [i]; 73 74 if (!first) { 75 writer.WriteValueSeparator (); 76 } 77 78 first = false; 79 80 writer.WritePropertyName (boolGamePref.ToStringCached ()); 81 82 writer.WriteRaw (keyType); 83 writer.WriteString ("bool"); 84 85 writer.WriteRaw (keyValue); 86 writer.WriteBoolean (gsi.GetValue (boolGamePref)); 87 88 writer.WriteEndObject (); 30 addItem (ref _writer, ref _first, boolGamePref.ToStringCached (), gsi.GetValue (boolGamePref)); 89 31 } 90 91 writer.WriteEndObject ();92 93 buildSampler.End ();94 95 int bufferContentSize = writer.CurrentOffset + 128;96 if (bufferContentSize > largestBuffer) {97 largestBuffer = bufferContentSize;98 }99 100 SendEnvelopedResult (_context, ref writer);101 32 } 102 33
Note:
See TracChangeset
for help on using the changeset viewer.