Changeset 486 for TFP-WebServer
- Timestamp:
- Feb 26, 2024, 6:25:48 PM (9 months ago)
- Location:
- TFP-WebServer
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/ModInfo.xml
r485 r486 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="22.0.1. 0" />7 <Version value="22.0.1.1" /> 8 8 <Website value="" /> 9 9 </xml> -
TFP-WebServer/WebServer/WebServer.csproj
r485 r486 151 151 <Compile Include="src\WebAPI\APIs\WorldState\Hostile.cs" /> 152 152 <Compile Include="src\WebAPI\APIs\WorldState\Player.cs" /> 153 <Compile Include="src\WebAPI\EApiErrorCode.cs" /> 153 154 <Compile Include="src\WebAPI\JsonCommons.cs" /> 154 155 <Compile Include="src\WebAPI\Null.cs" /> -
TFP-WebServer/WebServer/src/WebAPI/APIs/Command.cs
r485 r486 92 92 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 93 93 if (!JsonCommons.TryGetJsonField (_jsonInput, "command", out string commandString)) { 94 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_COMMAND");94 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_COMMAND); 95 95 return; 96 96 } … … 115 115 116 116 if (command == null) { 117 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, "UNKNOWN_COMMAND");117 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, EApiErrorCode.UNKNOWN_COMMAND); 118 118 return; 119 119 } … … 122 122 123 123 if (_context.PermissionLevel > commandPermissionLevel) { 124 SendEmptyResponse (_context, HttpStatusCode.Forbidden, _jsonInputData, "NO_PERMISSION");124 SendEmptyResponse (_context, HttpStatusCode.Forbidden, _jsonInputData, EApiErrorCode.NO_PERMISSION); 125 125 return; 126 126 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/Blacklist.cs
r485 r486 68 68 69 69 if (!JsonCommons.TryReadDateTime (_jsonInput, propertyBannedUntil, out DateTime bannedUntil)) { 70 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_BANNED_UNTIL");70 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_BANNED_UNTIL); 71 71 return; 72 72 } … … 96 96 97 97 if (string.IsNullOrEmpty (id)) { 98 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_USER");98 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_USER); 99 99 return false; 100 100 } 101 101 102 102 if (!PlatformUserIdentifierAbs.TryFromCombinedString (id, out _userId)) { 103 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_USER");103 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_USER); 104 104 return false; 105 105 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/CommandPermissions.cs
r434 r486 58 58 59 59 if (string.IsNullOrEmpty (id)) { 60 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_COMMAND");60 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_COMMAND); 61 61 return; 62 62 } … … 64 64 IConsoleCommand cmd = SdtdConsole.Instance.GetCommand (id); 65 65 if (cmd == null) { 66 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, "INVALID_COMMAND");66 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, EApiErrorCode.UNKNOWN_COMMAND); 67 67 return; 68 68 } 69 69 70 70 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevel, out int permissionLevel)) { 71 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_PERMISSION_LEVEL");71 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_PERMISSION_LEVEL); 72 72 return; 73 73 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/CommandPermissions.openapi.yaml
r485 r486 120 120 $ref: './openapi.yaml#/components/responses/HttpEmptyEnvelopedResponse' 121 121 404: 122 description: Specified command not found, errorCode will be ' INVALID_COMMAND'122 description: Specified command not found, errorCode will be 'UNKNOWN_COMMAND' 123 123 $ref: './openapi.yaml#/components/responses/HttpEmptyEnvelopedResponse' 124 124 403: -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/RegisterUser.cs
r485 r486 27 27 28 28 if (string.IsNullOrEmpty (token)) { 29 SendEmptyResponse (_context, HttpStatusCode.BadRequest, null, "NO_TOKEN");29 SendEmptyResponse (_context, HttpStatusCode.BadRequest, null, EApiErrorCode.MISSING_TOKEN); 30 30 return; 31 31 } 32 32 33 33 if (!UserRegistrationTokens.TryValidate (token, out UserRegistrationTokens.RegistrationData regData)) { 34 SendEmptyResponse (_context, HttpStatusCode.NotFound, null, "INVALID_OR_EXPIRED_TOKEN");34 SendEmptyResponse (_context, HttpStatusCode.NotFound, null, EApiErrorCode.INVALID_OR_EXPIRED_TOKEN); 35 35 return; 36 36 } … … 51 51 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 52 52 if (!JsonCommons.TryGetJsonField (_jsonInput, "token", out string token)) { 53 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_TOKEN");53 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.MISSING_TOKEN); 54 54 return; 55 55 } 56 56 57 57 if (!JsonCommons.TryGetJsonField (_jsonInput, "username", out string username)) { 58 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_USERNAME");58 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.MISSING_USERNAME); 59 59 return; 60 60 } 61 61 62 62 if (!JsonCommons.TryGetJsonField (_jsonInput, "password", out string password)) { 63 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "MISSING_PASSWORD");63 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.MISSING_PASSWORD); 64 64 return; 65 65 } 66 66 67 67 if (!UserRegistrationTokens.TryValidate (token, out UserRegistrationTokens.RegistrationData regData)) { 68 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, null, "INVALID_OR_EXPIRED_TOKEN");68 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, null, EApiErrorCode.INVALID_OR_EXPIRED_TOKEN); 69 69 return; 70 70 } 71 71 72 72 if (!userValidationRegex.IsMatch (username)) { 73 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, "INVALID_USERNAME");73 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, EApiErrorCode.INVALID_USERNAME); 74 74 return; 75 75 } 76 76 77 77 if (!passValidationRegex.IsMatch (password)) { 78 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, "INVALID_PASSWORD");78 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, EApiErrorCode.INVALID_PASSWORD); 79 79 return; 80 80 } … … 86 86 !Equals (existingMapping.CrossPlatformUser, regData.CrossPlatformUserId)) { 87 87 // Username already in use by another player 88 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, "DUPLICATE_USERNAME");88 SendEmptyResponse (_context, HttpStatusCode.Unauthorized, _jsonInputData, EApiErrorCode.DUPLICATE_USERNAME); 89 89 return; 90 90 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/RegisterUser.openapi.yaml
r462 r486 102 102 - meta 103 103 400: 104 description: Invalid request, errorCode will be ' NO_TOKEN'104 description: Invalid request, errorCode will be 'MISSING_TOKEN' 105 105 $ref: './openapi.yaml#/components/responses/HttpEmptyEnvelopedResponse' 106 106 404: -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/UserPermissions.cs
r434 r486 111 111 if (userId != null) { 112 112 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevel, out int permissionLevel)) { 113 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_PERMISSION_LEVEL");113 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_PERMISSION_LEVEL); 114 114 return; 115 115 } … … 120 120 } else { 121 121 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelMods, out int permissionLevelMods)) { 122 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_PERMISSION_LEVEL_MODS");122 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_PERMISSION_LEVEL_MODS); 123 123 return; 124 124 } 125 125 126 126 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelNormal, out int permissionLevelNormal)) { 127 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_PERMISSION_LEVEL_NORMAL");127 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_PERMISSION_LEVEL_NORMAL); 128 128 return; 129 129 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/WebApiTokens.cs
r434 r486 62 62 63 63 if (string.IsNullOrEmpty (id)) { 64 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_NAME");64 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_NAME); 65 65 return; 66 66 } 67 67 68 68 if (!JsonCommons.TryGetJsonField (_jsonInput, propertySecret, out string secret)) { 69 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_SECRET");69 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_SECRET); 70 70 return; 71 71 } 72 72 73 73 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevel, out int permissionLevel)) { 74 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_PERMISSION_LEVEL");74 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_PERMISSION_LEVEL); 75 75 return; 76 76 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/WebModules.cs
r435 r486 107 107 108 108 if (string.IsNullOrEmpty (id)) { 109 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_MODULE");109 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_MODULE); 110 110 return; 111 111 } 112 112 113 113 if (!AdminWebModules.Instance.IsKnownModule (id)) { 114 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_MODULE");114 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_MODULE); 115 115 return; 116 116 } … … 120 120 if (_jsonInput.ContainsKey (propertyPermissionLevelGlobal)) { 121 121 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelGlobal, out int permissionLevelGlobal)) { 122 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_LEVEL_GLOBAL");122 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_PERMISSION_LEVEL_GLOBAL); 123 123 return; 124 124 } … … 129 129 if (_jsonInput.TryGetValue (propertyPermissionLevelPerMethod, out object perLevelField)) { 130 130 if (perLevelField is not IDictionary<string, object> perLevelObj) { 131 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_LEVEL_PER_METHOD_PROPERTY");131 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_PERMISSION_LEVEL_PER_METHOD_PROPERTY); 132 132 return; 133 133 } … … 135 135 foreach ((string property, object valueObj) in perLevelObj) { 136 136 if (!EnumUtils.TryParse (property, out ERequestMethod method, true)) { 137 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_METHOD_NAME");137 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_METHOD_NAME); 138 138 return; 139 139 } 140 140 141 141 if (module.LevelPerMethod == null || module.LevelPerMethod [(int)method] == AdminWebModules.MethodLevelNotSupported) { 142 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "UNSUPPORTED_METHOD");142 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.UNSUPPORTED_METHOD); 143 143 return; 144 144 } … … 148 148 if (valueObj is string valueString) { 149 149 if (!valueString.EqualsCaseInsensitive (AdminWebModules.MethodLevelInheritKeyword)) { 150 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_STRING");150 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_PERMISSION_STRING); 151 151 return; 152 152 } … … 157 157 permissionLevel = (int)valueDbl; 158 158 } catch (Exception) { 159 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_VALUE");159 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_PERMISSION_VALUE); 160 160 return; 161 161 } 162 162 } else { 163 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_VALUE_TYPE");163 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_PERMISSION_VALUE_TYPE); 164 164 return; 165 165 } -
TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/WebUsers.cs
r434 r486 64 64 65 65 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPassword, out string password)) { 66 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_PASSWORD");66 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_OR_INVALID_PASSWORD); 67 67 return; 68 68 } 69 69 70 70 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPlatformUserId, out IDictionary<string, object> userIdField)) { 71 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_PLATFORM_USER_ID");71 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_PLATFORM_USER_ID); 72 72 return; 73 73 } 74 74 75 75 if (!JsonCommons.TryReadPlatformUserIdentifier (userIdField, out PlatformUserIdentifierAbs platformUserId)) { 76 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PLATFORM_USER_ID");76 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_PLATFORM_USER_ID); 77 77 return; 78 78 } … … 82 82 if (JsonCommons.TryGetJsonField (_jsonInput, propertyCrossplatformUserId, out userIdField)) { 83 83 if (!JsonCommons.TryReadPlatformUserIdentifier (userIdField, out crossplatformUserId)) { 84 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_CROSSPLATFORM_USER_ID");84 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.INVALID_CROSSPLATFORM_USER_ID); 85 85 return; 86 86 } … … 107 107 108 108 if (string.IsNullOrEmpty (id)) { 109 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_USERNAME");109 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, EApiErrorCode.NO_USERNAME); 110 110 return false; 111 111 } -
TFP-WebServer/WebServer/src/WebAPI/AbsRestApi.cs
r434 r486 174 174 } 175 175 176 protected static void SendEmptyResponse (RequestContext _context, HttpStatusCode _statusCode, byte[] _jsonInputData, EApiErrorCode _errorCode, Exception _exception = null) { 177 SendEmptyResponse (_context, _statusCode, _jsonInputData, _errorCode.ToStringCached (), _exception); 178 } 179 176 180 #endregion 177 181 } -
TFP-WebServer/bin/Mods/TFP_WebServer/ModInfo.xml
r485 r486 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="22.0.1. 0" />7 <Version value="22.0.1.1" /> 8 8 <Website value="" /> 9 9 </xml>
Note:
See TracChangeset
for help on using the changeset viewer.