Changeset 435
- Timestamp:
- May 18, 2023, 12:20:16 PM (18 months ago)
- Location:
- binary-improvements2
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/CommandExtensions/ModInfo.xml
r434 r435 5 5 <Description value="Additional commands for server operation" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/MapRendering/ModInfo.xml
r434 r435 5 5 <Description value="Render the game map to image map tiles as it is uncovered" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/MarkersMod/ModInfo.xml
r434 r435 5 5 <Description value="Allows placing custom markers on the web map" /> 6 6 <Author value="Catalysm and Alloc" /> 7 <Version value="21.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/WebServer/ModInfo.xml
r434 r435 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.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/WebServer/src/Commands/WebPermissionsCmd.cs
r434 r435 82 82 } 83 83 84 if (permissionLevelString.EqualsCaseInsensitive ( "inherit")) {84 if (permissionLevelString.EqualsCaseInsensitive (AdminWebModules.MethodLevelInheritKeyword)) { 85 85 if (isGlobal) { 86 86 SdtdConsole.Instance.Output ($"Permission level can not use the 'inherit' keyword with the 'global' method keyword."); -
binary-improvements2/WebServer/src/Permissions/AdminWebModules.cs
r434 r435 81 81 82 82 public struct WebModule { 83 private const string methodLevelInheritKeyword = "inherit";84 85 83 public string Name; 86 84 public int LevelGlobal; … … 135 133 permissionElement.AddXmlElement ("method") 136 134 .SetAttrib ("name", method.ToStringCached ()) 137 .SetAttrib ("permission_level", level == MethodLevelInheritGlobal ? methodLevelInheritKeyword : level.ToString ());135 .SetAttrib ("permission_level", level == MethodLevelInheritGlobal ? MethodLevelInheritKeyword : level.ToString ()); 138 136 } 139 137 } … … 195 193 196 194 int methodPermissionLevel; 197 if (permissionLevelString.EqualsCaseInsensitive ( methodLevelInheritKeyword)) {195 if (permissionLevelString.EqualsCaseInsensitive (MethodLevelInheritKeyword)) { 198 196 methodPermissionLevel = MethodLevelInheritGlobal; 199 197 } else if (!int.TryParse (permissionLevelString, out methodPermissionLevel)) { … … 230 228 /// </summary> 231 229 public const int MethodLevelInheritGlobal = int.MinValue; 232 230 231 /// <summary> 232 /// Keyword used to signal inherit level on user facing levels like admins.xml or WebAPIs 233 /// </summary> 234 public const string MethodLevelInheritKeyword = "inherit"; 235 233 236 /// <summary> 234 237 /// Method not supported … … 287 290 288 291 #endregion 292 289 293 } 290 294 } -
binary-improvements2/WebServer/src/WebAPI/APIs/Permissions/WebModules.cs
r434 r435 1 using System; 1 2 using System.Collections.Generic; 2 3 using System.Net; … … 67 68 _writer.WriteInt32 (_module.LevelGlobal); 68 69 _writer.WriteRaw (jsonKeyPermissionLevelPerMethod); 69 70 70 71 _writer.WriteBeginObject (); 71 72 … … 74 75 for (int iMethod = 0; iMethod < _module.LevelPerMethod.Length; iMethod++) { 75 76 int methodLevel = _module.LevelPerMethod [iMethod]; 76 77 77 78 if (methodLevel == AdminWebModules.MethodLevelNotSupported) { 78 79 continue; … … 84 85 85 86 first = false; 86 87 87 88 _writer.WriteRaw (jsonMethodNameKeys [iMethod]); 88 89 if (methodLevel == AdminWebModules.MethodLevelInheritGlobal) { 89 _writer.WriteString ( "inherit");90 _writer.WriteString (AdminWebModules.MethodLevelInheritKeyword); 90 91 } else { 91 92 _writer.WriteInt32 (methodLevel); … … 95 96 96 97 _writer.WriteEndObject (); 97 98 98 99 _writer.WriteRaw (jsonKeyIsDefault); 99 100 _writer.WriteBoolean (_module.IsDefault); 100 101 101 102 _writer.WriteEndObject (); 102 103 } … … 105 106 string id = _context.RequestPath; 106 107 107 // TODO108 109 108 if (string.IsNullOrEmpty (id)) { 110 109 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_MODULE"); … … 112 111 } 113 112 114 if (! JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelGlobal, out int permissionLevel)) {115 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, " NO_OR_INVALID_PERMISSION_LEVEL");113 if (!AdminWebModules.Instance.IsKnownModule (id)) { 114 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_MODULE"); 116 115 return; 117 116 } 118 117 119 // ModulesInstance.AddModule (id, permissionLevel); 118 AdminWebModules.WebModule module = AdminWebModules.Instance.GetModule (id); 119 120 if (_jsonInput.ContainsKey (propertyPermissionLevelGlobal)) { 121 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelGlobal, out int permissionLevelGlobal)) { 122 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_LEVEL_GLOBAL"); 123 return; 124 } 125 126 module.LevelGlobal = permissionLevelGlobal; 127 } 128 129 if (_jsonInput.TryGetValue (propertyPermissionLevelPerMethod, out object perLevelField)) { 130 if (perLevelField is not IDictionary<string, object> perLevelObj) { 131 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_LEVEL_PER_METHOD_PROPERTY"); 132 return; 133 } 134 135 foreach ((string property, object valueObj) in perLevelObj) { 136 if (!EnumUtils.TryParse (property, out ERequestMethod method, true)) { 137 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_METHOD_NAME"); 138 return; 139 } 140 141 if (module.LevelPerMethod == null || module.LevelPerMethod [(int)method] == AdminWebModules.MethodLevelNotSupported) { 142 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "UNSUPPORTED_METHOD"); 143 return; 144 } 145 146 int permissionLevel; 147 148 if (valueObj is string valueString) { 149 if (!valueString.EqualsCaseInsensitive (AdminWebModules.MethodLevelInheritKeyword)) { 150 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_STRING"); 151 return; 152 } 153 154 permissionLevel = AdminWebModules.MethodLevelInheritGlobal; 155 } else if (valueObj is double valueDbl) { 156 try { 157 permissionLevel = (int)valueDbl; 158 } catch (Exception) { 159 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_VALUE"); 160 return; 161 } 162 } else { 163 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_VALUE_TYPE"); 164 return; 165 } 166 167 module.LevelPerMethod [(int)method] = permissionLevel; 168 } 169 } 170 171 module.IsDefault = false; 172 ModulesInstance.AddModule (module); 120 173 121 174 SendEmptyResponse (_context, HttpStatusCode.Created); -
binary-improvements2/bin/Mods/TFP_CommandExtensions/ModInfo.xml
r434 r435 5 5 <Description value="Additional commands for server operation" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/bin/Mods/TFP_MapRendering/ModInfo.xml
r434 r435 5 5 <Description value="Render the game map to image map tiles as it is uncovered" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/bin/Mods/TFP_WebServer/ModInfo.xml
r434 r435 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.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/bin/Mods/Xample_MarkersMod/ModInfo.xml
r434 r435 5 5 <Description value="Allows placing custom markers on the web map" /> 6 6 <Author value="Catalysm and Alloc" /> 7 <Version value="21.0.28 8.0" />7 <Version value="21.0.289.0" /> 8 8 <Website value="" /> 9 9 </xml>
Note:
See TracChangeset
for help on using the changeset viewer.