Changeset 404 for binary-improvements2/WebServer/src/WebAPI
- Timestamp:
- Feb 16, 2023, 3:50:53 PM (21 months ago)
- Location:
- binary-improvements2/WebServer/src/WebAPI
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/WebAPI/APIs/Command.cs
r402 r404 25 25 26 26 if (string.IsNullOrEmpty (id)) { 27 bool first = true; 28 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) { 29 if (!first) { 27 IList<IConsoleCommand> ccs = SdtdConsole.Instance.GetCommands (); 28 for (int i = 0; i < ccs.Count; i++) { 29 IConsoleCommand cc = ccs [i]; 30 31 if (i > 0) { 30 32 writer.WriteValueSeparator (); 31 33 } 32 33 first = false;34 34 35 35 writeCommandJson (ref writer, cc, permissionLevel); … … 81 81 _writer.WriteString (_command.GetHelp ()); 82 82 83 int commandPermissionLevel = GameManager.Instance.adminTools. GetCommandPermissionLevel (_command.GetCommands ());83 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (_command.GetCommands ()); 84 84 _writer.WriteRaw (jsonAllowedKey); 85 85 _writer.WriteBoolean (_userPermissionLevel <= commandPermissionLevel); … … 117 117 } 118 118 119 int commandPermissionLevel = GameManager.Instance.adminTools. GetCommandPermissionLevel (command.GetCommands ());119 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (command.GetCommands ()); 120 120 121 121 if (_context.PermissionLevel > commandPermissionLevel) { -
binary-improvements2/WebServer/src/WebAPI/APIs/ServerInfo.cs
r402 r404 1 using System.Collections.Generic; 1 2 using JetBrains.Annotations; 2 3 using Utf8Json; … … 22 23 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo; 23 24 24 bool first = true;25 26 25 IList<GameInfoString> list = EnumUtils.Values<GameInfoString> (); 26 for (int i = 0; i < list.Count; i++) { 27 GameInfoString stringGamePref = list [i]; 27 28 28 foreach (GameInfoString stringGamePref in EnumUtils.Values<GameInfoString> ()) { 29 string value = gsi.GetValue (stringGamePref); 30 31 if (!first) { 29 if (i > 0) { 32 30 writer.WriteValueSeparator (); 33 31 } 34 32 35 first = false;36 37 33 writer.WriteString (stringGamePref.ToStringCached ()); 38 34 writer.WriteNameSeparator (); 39 35 40 36 writer.WriteRaw (keyType); 41 37 writer.WriteString ("string"); 42 38 43 39 writer.WriteRaw (keyValue); 44 writer.WriteString ( value);45 40 writer.WriteString (gsi.GetValue (stringGamePref)); 41 46 42 writer.WriteEndObject (); 47 43 } 48 44 49 foreach (GameInfoInt intGamePref in EnumUtils.Values<GameInfoInt> ()) { 50 int value = gsi.GetValue (intGamePref); 45 IList<GameInfoInt> ints = EnumUtils.Values<GameInfoInt> (); 46 for (int i = 0; i < ints.Count; i++) { 47 GameInfoInt intGamePref = ints [i]; 51 48 52 if ( !first) {49 if (i > 0) { 53 50 writer.WriteValueSeparator (); 54 51 } 55 52 56 first = false;57 58 53 writer.WriteString (intGamePref.ToStringCached ()); 59 54 writer.WriteNameSeparator (); 60 55 61 56 writer.WriteRaw (keyType); 62 57 writer.WriteString ("int"); 63 58 64 59 writer.WriteRaw (keyValue); 65 writer.WriteInt32 ( value);66 60 writer.WriteInt32 (gsi.GetValue (intGamePref)); 61 67 62 writer.WriteEndObject (); 68 63 } 69 64 70 foreach (GameInfoBool boolGamePref in EnumUtils.Values<GameInfoBool> ()) { 71 bool value = gsi.GetValue (boolGamePref); 65 IList<GameInfoBool> prefs = EnumUtils.Values<GameInfoBool> (); 66 for (int i = 0; i < prefs.Count; i++) { 67 GameInfoBool boolGamePref = prefs [i]; 72 68 73 if ( !first) {69 if (i > 0) { 74 70 writer.WriteValueSeparator (); 75 71 } 76 72 77 first = false;78 79 73 writer.WriteString (boolGamePref.ToStringCached ()); 80 74 writer.WriteNameSeparator (); 81 75 82 76 writer.WriteRaw (keyType); 83 77 writer.WriteString ("bool"); 84 78 85 79 writer.WriteRaw (keyValue); 86 writer.WriteBoolean ( value);87 80 writer.WriteBoolean (gsi.GetValue (boolGamePref)); 81 88 82 writer.WriteEndObject (); 89 83 } 90 84 91 85 writer.WriteEndObject (); 92 86 -
binary-improvements2/WebServer/src/WebAPI/AbsRestApi.cs
r402 r404 95 95 } 96 96 97 protected void SendErrorResult (RequestContext _context, HttpStatusCode _statusCode, byte[] _jsonInputData = null, string _errorCode = null, Exception _exception = null) {98 PrepareEnvelopedResult (out JsonWriter writer);99 writer.WriteRaw (JsonEmptyData);100 SendEnvelopedResult (_context, ref writer, _statusCode, _jsonInputData, _errorCode, _exception);101 }102 103 97 static AbsRestApi () { 104 98 JsonWriter writer = new JsonWriter (); … … 108 102 } 109 103 104 protected virtual void HandleRestGet (RequestContext _context) { 105 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 106 } 107 108 protected virtual void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 109 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 110 } 111 112 protected virtual void HandleRestPut (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 113 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 114 } 115 116 protected virtual void HandleRestDelete (RequestContext _context) { 117 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 118 } 119 120 121 #region Helpers 122 110 123 protected static readonly byte[] JsonEmptyData; 111 124 112 protected void PrepareEnvelopedResult (out JsonWriter _writer) {125 protected static void PrepareEnvelopedResult (out JsonWriter _writer) { 113 126 WebUtils.PrepareEnvelopedResult (out _writer); 114 127 } 115 128 116 protected void SendEnvelopedResult (RequestContext _context, ref JsonWriter _writer, HttpStatusCode _statusCode = HttpStatusCode.OK,129 protected static void SendEnvelopedResult (RequestContext _context, ref JsonWriter _writer, HttpStatusCode _statusCode = HttpStatusCode.OK, 117 130 byte[] _jsonInputData = null, string _errorCode = null, Exception _exception = null) { 118 131 … … 120 133 } 121 134 122 protected bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out int _value) { 135 protected static void SendErrorResult (RequestContext _context, HttpStatusCode _statusCode, byte[] _jsonInputData = null, string _errorCode = null, Exception _exception = null) { 136 PrepareEnvelopedResult (out JsonWriter writer); 137 writer.WriteRaw (JsonEmptyData); 138 SendEnvelopedResult (_context, ref writer, _statusCode, _jsonInputData, _errorCode, _exception); 139 } 140 141 protected static bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out int _value) { 123 142 _value = default; 124 143 … … 139 158 } 140 159 141 protected bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out double _value) {160 protected static bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out double _value) { 142 161 _value = default; 143 162 … … 158 177 } 159 178 160 protected bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out string _value) {179 protected static bool TryGetJsonField (IDictionary<string, object> _jsonObject, string _fieldName, out string _value) { 161 180 _value = default; 162 181 … … 176 195 } 177 196 } 178 179 protected virtual void HandleRestGet (RequestContext _context) { 180 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 181 } 182 183 protected virtual void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 184 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 185 } 186 187 protected virtual void HandleRestPut (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 188 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, _jsonInputData, "Unsupported"); 189 } 190 191 protected virtual void HandleRestDelete (RequestContext _context) { 192 SendErrorResult (_context, HttpStatusCode.MethodNotAllowed, null, "Unsupported"); 193 } 197 198 199 #endregion 194 200 } 195 201 } -
binary-improvements2/WebServer/src/WebAPI/Null.cs
r391 r404 1 using System.Text; 1 using System; 2 using System.Text; 2 3 3 4 namespace Webserver.WebAPI { … … 10 11 _context.Response.ContentType = "text/plain"; 11 12 _context.Response.ContentEncoding = Encoding.ASCII; 12 _context.Response.OutputStream.Write ( new byte[] { }, 0, 0);13 _context.Response.OutputStream.Write (Array.Empty<byte> (), 0, 0); 13 14 } 14 15 }
Note:
See TracChangeset
for help on using the changeset viewer.