diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 1993137a9..bfd679a2b 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -158,8 +158,6 @@ namespace IW4MAdmin await E.Origin.Lock(); } - var canExecuteCommand = true; - try { if (!await ProcessEvent(E)) @@ -188,32 +186,31 @@ namespace IW4MAdmin } } - try + var canExecuteCommand = Manager.CommandInterceptors.All(interceptor => { - var loginPlugin = Manager.Plugins.FirstOrDefault(plugin => plugin.Name == "Login"); - - if (loginPlugin != null) + try { - await loginPlugin.OnEventAsync(E, this); + return interceptor(E); } + catch + { + return true; + } + }); + + if (!canExecuteCommand) + { + E.Origin.Tell(_translationLookup["SERVER_COMMANDS_INTERCEPTED"]); } - catch (AuthorizationException e) + else if (E.Type == GameEvent.EventType.Command && E.Extra is Command cmd) { - E.Origin.Tell($"{loc["COMMAND_NOTAUTHORIZED"]} - {e.Message}"); - canExecuteCommand = false; - } - - // hack: this prevents commands from getting executing that 'shouldn't' be - if (E.Type == GameEvent.EventType.Command && E.Extra is Command cmd && - (canExecuteCommand || E.Origin?.Level == Permission.Console)) - { - ServerLogger.LogInformation("Executing command {Command} for {Client}", cmd.Name, E.Origin.ToString()); + ServerLogger.LogInformation("Executing command {Command} for {Client}", cmd.Name, + E.Origin.ToString()); await cmd.ExecuteAsync(E); } var pluginTasks = Manager.Plugins - .Where(plugin => plugin.Name != "Login") .Select(async plugin => await CreatePluginTask(plugin, E)); await Task.WhenAll(pluginTasks); diff --git a/Data/Data.csproj b/Data/Data.csproj index 49f5e201d..490d46565 100644 --- a/Data/Data.csproj +++ b/Data/Data.csproj @@ -8,7 +8,7 @@ RaidMax.IW4MAdmin.Data RaidMax.IW4MAdmin.Data - 1.2.0 + 2022.10.11.1 diff --git a/Plugins/AutomessageFeed/AutomessageFeed.csproj b/Plugins/AutomessageFeed/AutomessageFeed.csproj index 6c0fcce20..d18d1184f 100644 --- a/Plugins/AutomessageFeed/AutomessageFeed.csproj +++ b/Plugins/AutomessageFeed/AutomessageFeed.csproj @@ -10,7 +10,7 @@ - + diff --git a/Plugins/LiveRadar/LiveRadar.csproj b/Plugins/LiveRadar/LiveRadar.csproj index b95df7199..b59e3a570 100644 --- a/Plugins/LiveRadar/LiveRadar.csproj +++ b/Plugins/LiveRadar/LiveRadar.csproj @@ -16,7 +16,7 @@ - + diff --git a/Plugins/Login/Login.csproj b/Plugins/Login/Login.csproj index e7b0ff1eb..99de86429 100644 --- a/Plugins/Login/Login.csproj +++ b/Plugins/Login/Login.csproj @@ -19,7 +19,7 @@ - + diff --git a/Plugins/Login/Plugin.cs b/Plugins/Login/Plugin.cs index b5a0d8eac..5b8116761 100644 --- a/Plugins/Login/Plugin.cs +++ b/Plugins/Login/Plugin.cs @@ -26,49 +26,22 @@ namespace IW4MAdmin.Plugins.Login _configHandler = configurationHandlerFactory.GetConfigurationHandler("LoginPluginSettings"); } - public Task OnEventAsync(GameEvent E, Server S) + public Task OnEventAsync(GameEvent gameEvent, Server server) { - if (E.IsRemote || _configHandler.Configuration().RequirePrivilegedClientLogin == false) + if (gameEvent.IsRemote || _configHandler.Configuration().RequirePrivilegedClientLogin == false) return Task.CompletedTask; - if (E.Type == GameEvent.EventType.Connect) + if (gameEvent.Type == GameEvent.EventType.Connect) { - AuthorizedClients.TryAdd(E.Origin.ClientId, false); - E.Origin.SetAdditionalProperty("IsLoggedIn", false); + AuthorizedClients.TryAdd(gameEvent.Origin.ClientId, false); + gameEvent.Origin.SetAdditionalProperty("IsLoggedIn", false); } - if (E.Type == GameEvent.EventType.Disconnect) + if (gameEvent.Type == GameEvent.EventType.Disconnect) { - AuthorizedClients.TryRemove(E.Origin.ClientId, out bool value); + AuthorizedClients.TryRemove(gameEvent.Origin.ClientId, out _); } - - if (E.Type == GameEvent.EventType.Command) - { - if (E.Origin.Level < EFClient.Permission.Moderator || - E.Origin.Level == EFClient.Permission.Console) - return Task.CompletedTask; - - if (E.Extra.GetType() == typeof(SetPasswordCommand) && - E.Origin?.Password == null) - return Task.CompletedTask; - - if (E.Extra.GetType() == typeof(LoginCommand)) - return Task.CompletedTask; - - if (E.Extra.GetType() == typeof(RequestTokenCommand)) - return Task.CompletedTask; - - if (!AuthorizedClients[E.Origin.ClientId]) - { - throw new AuthorizationException(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_LOGIN_AUTH"]); - } - - else - { - E.Origin.SetAdditionalProperty("IsLoggedIn", true); - } - } - + return Task.CompletedTask; } @@ -76,6 +49,36 @@ namespace IW4MAdmin.Plugins.Login { AuthorizedClients = new ConcurrentDictionary(); + manager.CommandInterceptors.Add(gameEvent => + { + if (gameEvent.Type != GameEvent.EventType.Command) + { + return true; + } + + if (gameEvent.Origin.Level < EFClient.Permission.Moderator || + gameEvent.Origin.Level == EFClient.Permission.Console) + return true; + + if (gameEvent.Extra.GetType() == typeof(SetPasswordCommand) && + gameEvent.Origin?.Password == null) + return true; + + if (gameEvent.Extra.GetType() == typeof(LoginCommand)) + return true; + + if (gameEvent.Extra.GetType() == typeof(RequestTokenCommand)) + return true; + + if (!AuthorizedClients[gameEvent.Origin.ClientId]) + { + return false; + } + + gameEvent.Origin.SetAdditionalProperty("IsLoggedIn", true); + return true; + }); + await _configHandler.BuildAsync(); if (_configHandler.Configuration() == null) { diff --git a/Plugins/Mute/Mute.csproj b/Plugins/Mute/Mute.csproj index 570c8bd9a..0ee030440 100644 --- a/Plugins/Mute/Mute.csproj +++ b/Plugins/Mute/Mute.csproj @@ -11,7 +11,7 @@ - + diff --git a/Plugins/ProfanityDeterment/ProfanityDeterment.csproj b/Plugins/ProfanityDeterment/ProfanityDeterment.csproj index a1afea40b..cda32fc43 100644 --- a/Plugins/ProfanityDeterment/ProfanityDeterment.csproj +++ b/Plugins/ProfanityDeterment/ProfanityDeterment.csproj @@ -16,7 +16,7 @@ - + diff --git a/Plugins/Stats/Stats.csproj b/Plugins/Stats/Stats.csproj index d7a6c3941..4f8469bea 100644 --- a/Plugins/Stats/Stats.csproj +++ b/Plugins/Stats/Stats.csproj @@ -17,7 +17,7 @@ - + diff --git a/Plugins/Welcome/Welcome.csproj b/Plugins/Welcome/Welcome.csproj index 79181edf5..02d13f336 100644 --- a/Plugins/Welcome/Welcome.csproj +++ b/Plugins/Welcome/Welcome.csproj @@ -20,7 +20,7 @@ - + diff --git a/SharedLibraryCore/SharedLibraryCore.csproj b/SharedLibraryCore/SharedLibraryCore.csproj index c3bf7db05..b65393196 100644 --- a/SharedLibraryCore/SharedLibraryCore.csproj +++ b/SharedLibraryCore/SharedLibraryCore.csproj @@ -4,7 +4,7 @@ Library net6.0 RaidMax.IW4MAdmin.SharedLibraryCore - 2022.9.8.1 + 2022.10.11.1 RaidMax Forever None Debug;Release;Prerelease @@ -19,7 +19,7 @@ true MIT Shared Library for IW4MAdmin - 2022.9.8.1 + 2022.10.11.1 true $(NoWarn);1591