diff --git a/Application/Misc/ScriptPlugin.cs b/Application/Misc/ScriptPlugin.cs index 655e93896..4ca319a08 100644 --- a/Application/Misc/ScriptPlugin.cs +++ b/Application/Misc/ScriptPlugin.cs @@ -112,13 +112,16 @@ namespace IW4MAdmin.Application.Misc } _scriptEngine = new Engine(cfg => - cfg.AllowClr(new[] + cfg.AddExtensionMethods(typeof(Utilities), typeof(Enumerable), typeof(Queryable)) + .AllowClr(new[] { typeof(System.Net.Http.HttpClient).Assembly, typeof(EFClient).Assembly, typeof(Utilities).Assembly, typeof(Encoding).Assembly, - typeof(CancellationTokenSource).Assembly + typeof(CancellationTokenSource).Assembly, + typeof(Data.Models.Client.EFClient).Assembly, + typeof(IW4MAdmin.Plugins.Stats.Plugin).Assembly }) .CatchClrExceptions() .AddObjectConverter(new PermissionLevelToStringConverter())); @@ -392,6 +395,11 @@ namespace IW4MAdmin.Application.Misc string name = dynamicCommand.name; string alias = dynamicCommand.alias; string description = dynamicCommand.description; + + if (dynamicCommand.permission is Data.Models.Client.EFClient.Permission perm) + { + dynamicCommand.permission = perm.ToString(); + } string permission = dynamicCommand.permission; List supportedGames = null; var targetRequired = false; @@ -475,7 +483,6 @@ namespace IW4MAdmin.Application.Misc throw new PluginException("An error occured while executing action for script plugin"); } - finally { if (_onProcessing.CurrentCount == 0) @@ -499,11 +506,6 @@ namespace IW4MAdmin.Application.Misc try { var (success, value) = (ValueTuple)result.AsyncState; - - _logger.LogDebug("Waiting for onDvarActionComplete -> get"); - _onDvarActionComplete.Wait(); - _logger.LogDebug("Completed wait for onDvarActionComplete -> get"); - onCompleted.DynamicInvoke(JsValue.Undefined, new[] { @@ -517,7 +519,7 @@ namespace IW4MAdmin.Application.Misc { using (LogContext.PushProperty("Server", server.ToString())) { - _logger.LogError(ex, "Could complete BeginGetDvar for {Filename} {@Location}", + _logger.LogError(ex, "Could not complete BeginGetDvar for {Filename} {@Location}", Path.GetFileName(_fileName), ex.Location); } } @@ -525,17 +527,10 @@ namespace IW4MAdmin.Application.Misc { _logger.LogError(ex, "Could not complete {BeginGetDvar} for {Class}", nameof(BeginGetDvar), Name); } - finally - { - if (_onDvarActionComplete.CurrentCount == 0) - { - _onDvarActionComplete.Release(); - } - } } var tokenSource = new CancellationTokenSource(); - tokenSource.CancelAfter(TimeSpan.FromSeconds(15)); + tokenSource.CancelAfter(TimeSpan.FromSeconds(5)); server.BeginGetDvar(dvarName, result => { @@ -561,17 +556,13 @@ namespace IW4MAdmin.Application.Misc private void BeginSetDvar(Server server, string dvarName, string dvarValue, Delegate onCompleted) { var tokenSource = new CancellationTokenSource(); - tokenSource.CancelAfter(TimeSpan.FromSeconds(15)); + tokenSource.CancelAfter(TimeSpan.FromSeconds(5)); void OnComplete(IAsyncResult result) { try { var success = (bool)result.AsyncState; - - _logger.LogDebug("Waiting for onDvarActionComplete -> set"); - _onDvarActionComplete.Wait(); - _logger.LogDebug("Completed wait for onDvarActionComplete -> set"); onCompleted.DynamicInvoke(JsValue.Undefined, new[] { @@ -593,13 +584,6 @@ namespace IW4MAdmin.Application.Misc { _logger.LogError(ex, "Could not complete {BeginSetDvar} for {Class}", nameof(BeginSetDvar), Name); } - finally - { - if (_onDvarActionComplete.CurrentCount == 0) - { - _onDvarActionComplete.Release(); - } - } } server.BeginSetDvar(dvarName, dvarValue, result => diff --git a/Application/RConParsers/BaseRConParser.cs b/Application/RConParsers/BaseRConParser.cs index 5ae819b7f..4f077ba0a 100644 --- a/Application/RConParsers/BaseRConParser.cs +++ b/Application/RConParsers/BaseRConParser.cs @@ -147,7 +147,7 @@ namespace IW4MAdmin.Application.RConParsers { GetDvarAsync(connection, dvarName, token: token).ContinueWith(action => { - if (action.Exception is null && !action.IsCanceled) + if (action.IsCompletedSuccessfully) { callback?.Invoke(new AsyncResult { diff --git a/Integrations/Cod/CodRConConnection.cs b/Integrations/Cod/CodRConConnection.cs index 0942cad75..b3582cc07 100644 --- a/Integrations/Cod/CodRConConnection.cs +++ b/Integrations/Cod/CodRConConnection.cs @@ -243,7 +243,11 @@ namespace Integrations.Cod CancellationToken = token }; - connectionState.ConnectionAttempts++; + if (!token.IsCancellationRequested) + { + connectionState.ConnectionAttempts++; + } + connectionState.BytesReadPerSegment.Clear(); _log.LogDebug(