Changeset 434 for binary-improvements2/WebServer/src/WebAPI/APIs
- Timestamp:
- May 17, 2023, 11:05:59 PM (19 months ago)
- Location:
- binary-improvements2/WebServer/src/WebAPI/APIs
- Files:
-
- 8 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/WebAPI/APIs/Command.cs
r426 r434 91 91 92 92 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 93 if (! TryGetJsonField (_jsonInput, "command", out string commandString)) {94 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_COMMAND");93 if (!JsonCommons.TryGetJsonField (_jsonInput, "command", out string commandString)) { 94 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_COMMAND"); 95 95 return; 96 96 } … … 98 98 WebCommandResult.ResultType responseType = WebCommandResult.ResultType.Full; 99 99 100 if ( TryGetJsonField (_jsonInput, "format", out string formatString)) {100 if (JsonCommons.TryGetJsonField (_jsonInput, "format", out string formatString)) { 101 101 if (formatString.EqualsCaseInsensitive ("raw")) { 102 102 responseType = WebCommandResult.ResultType.Raw; … … 115 115 116 116 if (command == null) { 117 SendE rrorResult(_context, HttpStatusCode.NotFound, _jsonInputData, "UNKNOWN_COMMAND");117 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, "UNKNOWN_COMMAND"); 118 118 return; 119 119 } … … 122 122 123 123 if (_context.PermissionLevel > commandPermissionLevel) { 124 SendE rrorResult(_context, HttpStatusCode.Forbidden, _jsonInputData, "NO_PERMISSION");124 SendEmptyResponse (_context, HttpStatusCode.Forbidden, _jsonInputData, "NO_PERMISSION"); 125 125 return; 126 126 } -
binary-improvements2/WebServer/src/WebAPI/APIs/GameData/Item.cs
r433 r434 3 3 using Webserver.Permissions; 4 4 5 namespace Webserver.WebAPI.APIs {5 namespace Webserver.WebAPI.APIs.GameData { 6 6 [UsedImplicitly] 7 7 internal class Item : AbsRestApi { -
binary-improvements2/WebServer/src/WebAPI/APIs/GameData/Mods.cs
r433 r434 3 3 using Webserver.Permissions; 4 4 5 namespace Webserver.WebAPI.APIs {5 namespace Webserver.WebAPI.APIs.GameData { 6 6 [UsedImplicitly] 7 7 public class Mods : AbsRestApi { … … 12 12 writer.WriteBeginArray (); 13 13 14 for (int i = 0; i < _parent. webMods.Count; i++) {15 WebMod webMod = _parent. webMods [i];14 for (int i = 0; i < _parent.WebMods.Count; i++) { 15 WebMod webMod = _parent.WebMods [i]; 16 16 17 17 if (i > 0) { … … 62 62 _writer.WriteValueSeparator (); 63 63 _writer.WritePropertyName ("displayName"); 64 JsonCommons.WriteStringOrNull (ref _writer,_webMod.ParentMod.DisplayName);64 _writer.WriteString (_webMod.ParentMod.DisplayName); 65 65 66 66 _writer.WriteValueSeparator (); 67 67 _writer.WritePropertyName ("description"); 68 JsonCommons.WriteStringOrNull (ref _writer,_webMod.ParentMod.Description);68 _writer.WriteString (_webMod.ParentMod.Description); 69 69 70 70 _writer.WriteValueSeparator (); 71 71 _writer.WritePropertyName ("author"); 72 JsonCommons.WriteStringOrNull (ref _writer,_webMod.ParentMod.Author);72 _writer.WriteString (_webMod.ParentMod.Author); 73 73 74 74 _writer.WriteValueSeparator (); 75 75 _writer.WritePropertyName ("version"); 76 JsonCommons.WriteStringOrNull (ref _writer,_webMod.ParentMod.VersionString);76 _writer.WriteString (_webMod.ParentMod.VersionString); 77 77 78 78 _writer.WriteValueSeparator (); 79 79 _writer.WritePropertyName ("website"); 80 JsonCommons.WriteStringOrNull (ref _writer,_webMod.ParentMod.Website);80 _writer.WriteString (_webMod.ParentMod.Website); 81 81 } 82 82 -
binary-improvements2/WebServer/src/WebAPI/APIs/Log.cs
r408 r434 55 55 56 56 writer.WriteRaw (jsonMsgKey); 57 writer.WriteString (logEntry. message);57 writer.WriteString (logEntry.Message); 58 58 59 59 writer.WriteRaw (jsonTypeKey); 60 writer.WriteString (logEntry. type.ToStringCached ());60 writer.WriteString (logEntry.Type.ToStringCached ()); 61 61 62 62 writer.WriteRaw (jsonTraceKey); 63 writer.WriteString (logEntry. trace);63 writer.WriteString (logEntry.Trace); 64 64 65 65 writer.WriteRaw (jsonIsotimeKey); 66 writer.WriteString (logEntry. isoTime);66 writer.WriteString (logEntry.IsoTime); 67 67 68 68 writer.WriteRaw (jsonUptimeKey); 69 writer.WriteString (logEntry. uptime.ToString ());69 writer.WriteString (logEntry.Uptime.ToString ()); 70 70 71 71 writer.WriteEndObject (); -
binary-improvements2/WebServer/src/WebAPI/APIs/Permissions/RegisterUser.cs
r433 r434 9 9 using Webserver.UrlHandlers; 10 10 11 namespace Webserver.WebAPI.APIs {11 namespace Webserver.WebAPI.APIs.Permissions { 12 12 [UsedImplicitly] 13 13 public class RegisterUser : AbsRestApi { … … 27 27 28 28 if (string.IsNullOrEmpty (token)) { 29 SendE rrorResult(_context, HttpStatusCode.BadRequest, null, "NO_TOKEN");29 SendEmptyResponse (_context, HttpStatusCode.BadRequest, null, "NO_TOKEN"); 30 30 return; 31 31 } 32 32 33 33 if (!UserRegistrationTokens.TryValidate (token, out UserRegistrationTokens.RegistrationData regData)) { 34 SendE rrorResult(_context, HttpStatusCode.NotFound, null, "INVALID_OR_EXPIRED_TOKEN");34 SendEmptyResponse (_context, HttpStatusCode.NotFound, null, "INVALID_OR_EXPIRED_TOKEN"); 35 35 return; 36 36 } … … 50 50 51 51 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 52 if (! TryGetJsonField (_jsonInput, "token", out string token)) {53 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_TOKEN");52 if (!JsonCommons.TryGetJsonField (_jsonInput, "token", out string token)) { 53 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_TOKEN"); 54 54 return; 55 55 } 56 56 57 if (! TryGetJsonField (_jsonInput, "username", out string username)) {58 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_USERNAME");57 if (!JsonCommons.TryGetJsonField (_jsonInput, "username", out string username)) { 58 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_USERNAME"); 59 59 return; 60 60 } 61 61 62 if (! TryGetJsonField (_jsonInput, "password", out string password)) {63 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_PASSWORD");62 if (!JsonCommons.TryGetJsonField (_jsonInput, "password", out string password)) { 63 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_PASSWORD"); 64 64 return; 65 65 } 66 66 67 67 if (!UserRegistrationTokens.TryValidate (token, out UserRegistrationTokens.RegistrationData regData)) { 68 SendE rrorResult(_context, HttpStatusCode.Unauthorized, null, "INVALID_OR_EXPIRED_TOKEN");68 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, null, "INVALID_OR_EXPIRED_TOKEN"); 69 69 return; 70 70 } 71 71 72 72 if (!userValidationRegex.IsMatch (username)) { 73 SendE rrorResult(_context, HttpStatusCode.Unauthorized, _jsonInputData, "INVALID_USERNAME");73 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, "INVALID_USERNAME"); 74 74 return; 75 75 } 76 76 77 77 if (!passValidationRegex.IsMatch (password)) { 78 SendE rrorResult(_context, HttpStatusCode.Unauthorized, _jsonInputData, "INVALID_PASSWORD");78 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, "INVALID_PASSWORD"); 79 79 return; 80 80 } … … 86 86 !PlatformUserIdentifierAbs.Equals (existingMapping.CrossPlatformUser, regData.CrossPlatformUserId)) { 87 87 // Username already in use by another player 88 SendE rrorResult(_context, HttpStatusCode.Unauthorized, _jsonInputData, "DUPLICATE_USERNAME");88 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, "DUPLICATE_USERNAME"); 89 89 return; 90 90 } -
binary-improvements2/WebServer/src/WebAPI/APIs/WorldState/Animal.cs
r433 r434 4 4 using Webserver.LiveData; 5 5 6 namespace Webserver.WebAPI.APIs {6 namespace Webserver.WebAPI.APIs.WorldState { 7 7 [UsedImplicitly] 8 8 internal class Animal : AbsRestApi { -
binary-improvements2/WebServer/src/WebAPI/APIs/WorldState/Hostile.cs
r433 r434 4 4 using Webserver.LiveData; 5 5 6 namespace Webserver.WebAPI.APIs {6 namespace Webserver.WebAPI.APIs.WorldState { 7 7 [UsedImplicitly] 8 8 internal class Hostile : AbsRestApi { -
binary-improvements2/WebServer/src/WebAPI/APIs/WorldState/Player.cs
r433 r434 6 6 using Webserver.Permissions; 7 7 8 namespace Webserver.WebAPI.APIs {8 namespace Webserver.WebAPI.APIs.WorldState { 9 9 [UsedImplicitly] 10 10 public class Player : AbsRestApi { … … 216 216 217 217 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 218 if (! TryGetJsonField (_jsonInput, "command", out string commandString)) {219 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_COMMAND");218 if (!JsonCommons.TryGetJsonField (_jsonInput, "command", out string commandString)) { 219 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_COMMAND"); 220 220 return; 221 221 } … … 223 223 WebCommandResult.ResultType responseType = WebCommandResult.ResultType.Full; 224 224 225 if ( TryGetJsonField (_jsonInput, "format", out string formatString)) {225 if (JsonCommons.TryGetJsonField (_jsonInput, "format", out string formatString)) { 226 226 if (formatString.EqualsCaseInsensitive ("raw")) { 227 227 responseType = WebCommandResult.ResultType.Raw; … … 240 240 241 241 if (command == null) { 242 SendE rrorResult(_context, HttpStatusCode.NotFound, _jsonInputData, "UNKNOWN_COMMAND");242 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, "UNKNOWN_COMMAND"); 243 243 return; 244 244 } … … 247 247 248 248 if (_context.PermissionLevel > commandPermissionLevel) { 249 SendE rrorResult(_context, HttpStatusCode.Forbidden, _jsonInputData, "NO_PERMISSION");249 SendEmptyResponse (_context, HttpStatusCode.Forbidden, _jsonInputData, "NO_PERMISSION"); 250 250 return; 251 251 }
Note:
See TracChangeset
for help on using the changeset viewer.