- 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/GameStats.cs
r437 r457 4 4 namespace Webserver.WebAPI.APIs.ServerState { 5 5 [UsedImplicitly] 6 public class GameStats : AbsRestApi{7 p rivate static readonly byte[] keyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type");8 private static readonly byte[] keyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value");6 public class GameStats : KeyValueListAbs { 7 public GameStats () : base ("GameStats") { 8 } 9 9 10 private int largestBuffer; 11 12 protected override void HandleRestGet (RequestContext _context) { 13 PrepareEnvelopedResult (out JsonWriter writer); 14 15 writer.EnsureCapacity (largestBuffer); 16 writer.WriteBeginObject (); 17 18 bool first = true; 10 protected override void iterateList (ref JsonWriter _writer, ref bool _first) { 19 11 foreach (EnumGameStats stat in EnumUtils.Values<EnumGameStats> ()) { 20 12 string name = stat.ToStringCached (); 21 13 global::GameStats.EnumType? type = global::GameStats.GetStatType (stat); 22 14 23 if (!first) {24 writer.WriteValueSeparator ();25 }26 27 first = false;28 29 writer.WritePropertyName (name);30 31 writer.WriteRaw (keyType);32 writer.WriteString (type.HasValue ? type.Value.ToStringCached () : "noType");33 34 writer.WriteRaw (keyValue);35 15 switch (type) { 36 16 case global::GameStats.EnumType.Int: 37 writer.WriteInt32 (global::GameStats.GetInt (stat));17 addItem (ref _writer, ref _first, name, global::GameStats.GetInt (stat)); 38 18 break; 39 19 case global::GameStats.EnumType.Float: 40 writer.WriteSingle (global::GameStats.GetFloat (stat));20 addItem (ref _writer, ref _first, name, global::GameStats.GetFloat (stat)); 41 21 break; 42 22 case global::GameStats.EnumType.String: 43 writer.WriteString (global::GameStats.GetString (stat));23 addItem (ref _writer, ref _first, name, global::GameStats.GetString (stat)); 44 24 break; 45 25 case global::GameStats.EnumType.Bool: 46 writer.WriteBoolean (global::GameStats.GetBool (stat)); 47 break; 48 default: 49 writer.WriteNull (); 26 addItem (ref _writer, ref _first, name, global::GameStats.GetBool (stat)); 50 27 break; 51 28 } 52 53 writer.WriteEndObject ();54 29 } 55 56 writer.WriteEndObject ();57 58 int bufferContentSize = writer.CurrentOffset + 128;59 if (bufferContentSize > largestBuffer) {60 largestBuffer = bufferContentSize;61 }62 63 SendEnvelopedResult (_context, ref writer);64 30 } 65 31 }
Note:
See TracChangeset
for help on using the changeset viewer.