Changeset 457
- Timestamp:
- Aug 7, 2023, 12:26:05 PM (17 months ago)
- Location:
- TFP-WebServer
- Files:
-
- 1 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/ModInfo.xml
r453 r457 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.1. 9.0" />7 <Version value="21.1.15.0" /> 8 8 <Website value="" /> 9 9 </xml> -
TFP-WebServer/WebServer/WebServer.csproj
r453 r457 135 135 <Compile Include="src\WebAPI\APIs\ServerState\GamePrefs.cs" /> 136 136 <Compile Include="src\WebAPI\APIs\ServerState\GameStats.cs" /> 137 <Compile Include="src\WebAPI\APIs\ServerState\KeyValueListAbs.cs" /> 137 138 <Compile Include="src\WebAPI\APIs\ServerState\ServerInfo.cs" /> 138 139 <Compile Include="src\WebAPI\APIs\ServerState\ServerStats.cs" /> … … 193 194 </ProjectReference> 194 195 </ItemGroup> 196 <ItemGroup> 197 <Content Include="src\WebAPI\APIs\WorldState\Animal.openapi.json" /> 198 </ItemGroup> 195 199 </Project> -
TFP-WebServer/WebServer/src/UrlHandlers/SessionHandler.cs
r453 r457 98 98 } 99 99 100 varloginResult = HandleUserIdLogin (_connectionHandler, _context, _remoteEndpointString, userPassLoginName, webUser.Name, webUser.PlatformUser, webUser.CrossPlatformUser);100 bool loginResult = HandleUserIdLogin (_connectionHandler, _context, _remoteEndpointString, userPassLoginName, webUser.Name, webUser.PlatformUser, webUser.CrossPlatformUser); 101 101 if (loginResult) { 102 102 WebUtils.WriteText (_context.Response, ""); -
TFP-WebServer/WebServer/src/WebAPI/APIs/ServerState/GamePrefs.cs
r438 r457 5 5 namespace Webserver.WebAPI.APIs.ServerState { 6 6 [UsedImplicitly] 7 public class GamePrefs : AbsRestApi { 8 private static readonly byte[] keyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type"); 9 private static readonly byte[] keyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value"); 10 private static readonly byte[] keyDefault = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("default"); 7 public class GamePrefs : KeyValueListAbs { 8 public GamePrefs () : base ("GamePrefs") { 9 } 11 10 12 private int largestBuffer; 13 14 protected override void HandleRestGet (RequestContext _context) { 15 PrepareEnvelopedResult (out JsonWriter writer); 16 17 writer.EnsureCapacity (largestBuffer); 18 writer.WriteBeginObject (); 19 20 bool first = true; 11 protected override void iterateList (ref JsonWriter _writer, ref bool _first) { 21 12 foreach (EnumGamePrefs stat in EnumUtils.Values<EnumGamePrefs> ()) { 22 13 string name = stat.ToStringCached (); 23 global::GamePrefs.EnumType? type = global::GamePrefs.GetPrefType (stat);24 14 25 15 if (name.Contains ("Password", StringComparison.Ordinal)) { … … 27 17 } 28 18 29 if (!first) { 30 writer.WriteValueSeparator (); 31 } 19 global::GamePrefs.EnumType? type = global::GamePrefs.GetPrefType (stat); 20 object defaultValue = global::GamePrefs.GetDefault (stat); 32 21 33 first = false;34 35 writer.WritePropertyName (name);36 37 writer.WriteRaw (keyType);38 writer.WriteString (type.HasValue ? type.Value.ToStringCached () : "noType");39 40 writer.WriteRaw (keyValue);41 22 switch (type) { 42 23 case global::GamePrefs.EnumType.Int: 43 writer.WriteInt32 (global::GamePrefs.GetInt (stat)); 24 int? defaultInt = defaultValue as int?; 25 addItem (ref _writer, ref _first, name, global::GamePrefs.GetInt (stat), defaultInt); 44 26 break; 45 27 case global::GamePrefs.EnumType.Float: 46 writer.WriteSingle (global::GamePrefs.GetFloat (stat)); 28 float? defaultFloat = defaultValue as float?; 29 addItem (ref _writer, ref _first, name, global::GamePrefs.GetFloat (stat), defaultFloat); 47 30 break; 48 31 case global::GamePrefs.EnumType.String: 49 writer.WriteString (global::GamePrefs.GetString (stat)); 32 string defaultString = defaultValue as string; 33 addItem (ref _writer, ref _first, name, global::GamePrefs.GetString (stat), defaultString); 50 34 break; 51 35 case global::GamePrefs.EnumType.Bool: 52 writer.WriteBoolean (global::GamePrefs.GetBool (stat)); 53 break; 54 default: 55 writer.WriteNull (); 36 bool? defaultBool = defaultValue as bool?; 37 addItem (ref _writer, ref _first, name, global::GamePrefs.GetBool (stat), defaultBool); 56 38 break; 57 39 } 58 59 writer.WriteRaw (keyDefault); 60 object defaultValue = global::GamePrefs.GetDefault (stat); 61 switch (type) { 62 case global::GamePrefs.EnumType.Int: 63 if (defaultValue is int defaultInt) { 64 writer.WriteInt32 (defaultInt); 65 } else { 66 writer.WriteNull (); 67 } 40 } 41 } 68 42 69 break;70 case global::GamePrefs.EnumType.Float:71 if (defaultValue is float defaultFloat) {72 writer.WriteSingle (defaultFloat);73 } else {74 writer.WriteNull ();75 }76 77 break;78 case global::GamePrefs.EnumType.String:79 if (defaultValue is string defaultString) {80 writer.WriteString (defaultString);81 } else {82 writer.WriteNull ();83 }84 85 break;86 case global::GamePrefs.EnumType.Bool:87 if (defaultValue is bool defaultBool) {88 writer.WriteBoolean (defaultBool);89 } else {90 writer.WriteNull ();91 }92 93 break;94 default:95 writer.WriteNull ();96 break;97 }98 99 writer.WriteEndObject ();100 }101 102 writer.WriteEndObject ();103 104 int bufferContentSize = writer.CurrentOffset + 128;105 if (bufferContentSize > largestBuffer) {106 largestBuffer = bufferContentSize;107 }108 109 SendEnvelopedResult (_context, ref writer);110 }111 43 } 112 44 } -
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 } -
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 -
TFP-WebServer/bin/Mods/TFP_WebServer/ModInfo.xml
r453 r457 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.1. 9.0" />7 <Version value="21.1.15.0" /> 8 8 <Website value="" /> 9 9 </xml>
Note:
See TracChangeset
for help on using the changeset viewer.