Changeset 372 for binary-improvements/MapRendering
- Timestamp:
- Jul 27, 2022, 7:17:17 PM (2 years ago)
- Location:
- binary-improvements/MapRendering
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Commands/WebPermissionsCmd.cs
r326 r372 30 30 ExecuteList (); 31 31 } else { 32 SdtdConsole.Instance.Output ( "Invalid sub command \"" + _params [0] + "\".");32 SdtdConsole.Instance.Output ($"Invalid sub command \"{_params [0]}\"."); 33 33 } 34 34 } else { … … 39 39 private void ExecuteAdd (List<string> _params) { 40 40 if (_params.Count != 3) { 41 SdtdConsole.Instance.Output ( "Wrong number of arguments, expected 3, found " + _params.Count + ".");41 SdtdConsole.Instance.Output ($"Wrong number of arguments, expected 3, found {_params.Count}."); 42 42 return; 43 43 } 44 44 45 45 if (!WebPermissions.Instance.IsKnownModule (_params [1])) { 46 SdtdConsole.Instance.Output ( "\"" + _params [1] + "\" is not a valid web function.");46 SdtdConsole.Instance.Output ($"\"{_params [1]}\" is not a valid web function."); 47 47 return; 48 48 } … … 50 50 int level; 51 51 if (!int.TryParse (_params [2], out level)) { 52 SdtdConsole.Instance.Output ( "\"" + _params [2] + "\" is not a valid integer.");52 SdtdConsole.Instance.Output ($"\"{_params [2]}\" is not a valid integer."); 53 53 return; 54 54 } 55 55 56 56 WebPermissions.Instance.AddModulePermission (_params [1], level); 57 SdtdConsole.Instance.Output ( string.Format ("{0} added with permission level of {1}.", _params [1], level));57 SdtdConsole.Instance.Output ($"{_params [1]} added with permission level of {level}."); 58 58 } 59 59 60 60 private void ExecuteRemove (List<string> _params) { 61 61 if (_params.Count != 2) { 62 SdtdConsole.Instance.Output ( "Wrong number of arguments, expected 2, found " + _params.Count + ".");62 SdtdConsole.Instance.Output ($"Wrong number of arguments, expected 2, found {_params.Count}."); 63 63 return; 64 64 } 65 65 66 66 if (!WebPermissions.Instance.IsKnownModule (_params [1])) { 67 SdtdConsole.Instance.Output ( "\"" + _params [1] + "\" is not a valid web function.");67 SdtdConsole.Instance.Output ($"\"{_params [1]}\" is not a valid web function."); 68 68 return; 69 69 } 70 70 71 71 WebPermissions.Instance.RemoveModulePermission (_params [1]); 72 SdtdConsole.Instance.Output ( string.Format ("{0} removed from permissions list.", _params [1]));72 SdtdConsole.Instance.Output ($"{_params [1]} removed from permissions list."); 73 73 } 74 74 … … 77 77 SdtdConsole.Instance.Output (" Level: Web function"); 78 78 foreach (WebPermissions.WebModulePermission wmp in WebPermissions.Instance.GetModules ()) { 79 SdtdConsole.Instance.Output ( string.Format (" {0,5}: {1}", wmp.permissionLevel, wmp.module));79 SdtdConsole.Instance.Output ($" {wmp.permissionLevel,5}: {wmp.module}"); 80 80 } 81 81 } -
binary-improvements/MapRendering/Web/Handlers/PathHandler.cs
r367 r372 12 12 } 13 13 14 public string ModuleName { 15 get { return moduleName; } 16 } 14 public string ModuleName => moduleName; 17 15 18 16 public abstract void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 19 17 int _permissionLevel); 20 18 21 public bool IsAuthorizedForHandler (WebConnection _user, int _permissionLevel) { 22 if (moduleName != null) { 23 return WebPermissions.Instance.ModuleAllowedWithLevel (moduleName, _permissionLevel); 24 } 25 26 return true; 19 public virtual bool IsAuthorizedForHandler (WebConnection _user, int _permissionLevel) { 20 return moduleName == null || WebPermissions.Instance.ModuleAllowedWithLevel (moduleName, _permissionLevel); 27 21 } 28 22 -
binary-improvements/MapRendering/Web/SSE/EventBase.cs
r367 r372 55 55 stringBuilder.Append ("data: "); 56 56 57 if (data is string dataString) { 58 stringBuilder.AppendLine (dataString); 59 } else if (data is JSONNode dataJson) { 60 dataJson.ToString (stringBuilder); 61 stringBuilder.AppendLine (""); 62 } else { 63 Log.Error ($"SSE ({Name}): Data is neither string nor JSON."); 64 continue; 57 switch (data) { 58 case string dataString: 59 stringBuilder.AppendLine (dataString); 60 break; 61 case JSONNode dataJson: 62 dataJson.ToString (stringBuilder); 63 stringBuilder.AppendLine (""); 64 break; 65 default: 66 logError ("Data is neither string nor JSON.", false); 67 continue; 65 68 } 66 69 … … 76 79 bytesToSend = Encoding.UTF8.GetBytes (output, 0, output.Length, buf, 0); 77 80 } catch (ArgumentException e) { 78 Log.Error ($"SSE ({Name}): Exception while encoding data for output, most likely exceeding buffer size:");81 logError ("Exception while encoding data for output, most likely exceeding buffer size:", false); 79 82 Log.Exception (e); 80 83 return; … … 95 98 totalClosed++; 96 99 97 Log.Out ( 98 $"SSE ({Name}): Can not write to endpoint, closing. (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 100 logError ("Can not write to endpoint, closing", true); 99 101 openStreams.RemoveAt (i); 100 102 resp.Close (); … … 107 109 108 110 if (e.InnerException is SocketException se) { 109 if (se.SocketErrorCode != SocketError.ConnectionAborted ) {110 Log.Error ($"SSE ({Name}): SocketError ({se.SocketErrorCode}) while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}");111 if (se.SocketErrorCode != SocketError.ConnectionAborted && se.SocketErrorCode != SocketError.Shutdown) { 112 logError ($"SocketError ({se.SocketErrorCode}) while trying to write", true); 111 113 } 112 114 } else { 113 Log.Error ( 114 $"SSE ({Name}): IOException while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 115 logError ("IOException while trying to write:", true); 115 116 Log.Exception (e); 116 117 } … … 122 123 123 124 openStreams.RemoveAt (i); 124 Log.Error ( 125 $"SSE ({Name}): Exception while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 125 logError ("Exception while trying to write:", true); 126 126 Log.Exception (e); 127 127 resp.Close (); … … 131 131 } 132 132 133 protected void logError (string _message, bool _printConnections) { 134 Log.Error (_printConnections 135 ? $"SSE ({Name}): {_message} (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed})" 136 : $"SSE ({Name}): {_message}"); 137 } 138 133 139 public virtual int DefaultPermissionLevel () { 134 140 return 0; -
binary-improvements/MapRendering/Web/WebPermissions.cs
r369 r372 18 18 private readonly Dictionary<string, WebModulePermission> modules = new CaseInsensitiveStringDictionary<WebModulePermission> (); 19 19 20 p ublicWebPermissions () {20 private WebPermissions () { 21 21 allModulesList = new List<WebModulePermission> (); 22 22 allModulesListRO = new ReadOnlyCollection<WebModulePermission> (allModulesList); … … 29 29 get { 30 30 lock (typeof (WebPermissions)) { 31 if (instance == null) { 32 instance = new WebPermissions (); 33 } 34 35 return instance; 31 return instance ?? (instance = new WebPermissions ()); 36 32 } 37 33 } … … 52 48 53 49 public WebModulePermission GetModulePermission (string _module) { 54 WebModulePermission result; 55 if (modules.TryGetValue (_module, out result)) { 50 if (modules.TryGetValue (_module, out WebModulePermission result)) { 56 51 return result; 57 52 } … … 192 187 193 188 if (!File.Exists (GetFullPath ())) { 194 Log.Out ( string.Format ("Permissions file '{0}' not found, creating.", GetFileName ()));189 Log.Out ($"Permissions file '{GetFileName ()}' not found, creating."); 195 190 Save (); 196 191 return; 197 192 } 198 193 199 Log.Out ( string.Format ("Loading permissions file at '{0}'", GetFullPath ()));194 Log.Out ($"Loading permissions file at '{GetFullPath ()}'"); 200 195 201 196 XmlDocument xmlDoc = new XmlDocument ();
Note:
See TracChangeset
for help on using the changeset viewer.