diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 87e7e12af9..78f5ea7ba7 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -2799,22 +2799,42 @@ public static void ExecuteClientCommand(Client client, Vector2 cursorWorldPos, s { if (GameMain.Server == null) return; if (string.IsNullOrWhiteSpace(command)) return; + + var passedConsolePermissionCheck = true; + var passedCommandPermissionCheck = true; + if (!client.HasPermission(ClientPermissions.ConsoleCommands) && client.Connection != GameMain.Server.OwnerConnection) { - GameMain.Server.SendConsoleMessage("You are not permitted to use console commands!", client, Color.Red); - GameServer.Log(GameServer.ClientLogName(client) + " attempted to execute the console command \"" + command + "\" without a permission to use console commands.", ServerLog.MessageType.ConsoleUsage); - return; + passedConsolePermissionCheck = false; } string[] splitCommand = ToolBox.SplitCommand(command); Command matchingCommand = commands.Find(c => c.Names.Contains(splitCommand[0].ToIdentifier())); - if (matchingCommand != null && !client.PermittedConsoleCommands.Contains(matchingCommand) && client.Connection != GameMain.Server.OwnerConnection) + if (matchingCommand == null || !client.PermittedConsoleCommands.Contains(matchingCommand) && client.Connection != GameMain.Server.OwnerConnection) { - GameMain.Server.SendConsoleMessage("You are not permitted to use the command\"" + matchingCommand.Names[0] + "\"!", client, Color.Red); - GameServer.Log(GameServer.ClientLogName(client) + " attempted to execute the console command \"" + command + "\" without a permission to use the command.", ServerLog.MessageType.ConsoleUsage); - return; + passedCommandPermissionCheck = false; } - else if (matchingCommand == null) + + var bypass = GameMain.LuaCs.Hook.Call("onConsoleCommand", client, splitCommand, matchingCommand, passedConsolePermissionCheck, passedCommandPermissionCheck) ?? false; + + if (!bypass) + { + if (!passedConsolePermissionCheck) + { + GameMain.Server.SendConsoleMessage("You are not permitted to use console commands!", client, Color.Red); + GameServer.Log(GameServer.ClientLogName(client) + " attempted to execute the console command \"" + command + "\" without a permission to use console commands.", ServerLog.MessageType.ConsoleUsage); + return; + } + + if (!passedCommandPermissionCheck) + { + GameMain.Server.SendConsoleMessage("You are not permitted to use the command\"" + matchingCommand.Names[0] + "\"!", client, Color.Red); + GameServer.Log(GameServer.ClientLogName(client) + " attempted to execute the console command \"" + command + "\" without a permission to use the command.", ServerLog.MessageType.ConsoleUsage); + return; + } + } + + if (matchingCommand == null) { GameMain.Server.SendConsoleMessage("Command \"" + splitCommand[0] + "\" not found.", client, Color.Red); return; diff --git a/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs b/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs index c7a35c13ac..0d375c8395 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs @@ -2428,7 +2428,9 @@ public static void ExecuteCommand(string inputtedCommands) if (GameMain.Client != null) { Command matchingCommand = commands.Find(c => c.Names.Contains(firstCommand)); - if (matchingCommand == null) + + var bypass = GameMain.LuaCs.Hook.Call("onClientConsoleCommand", splitCommand, matchingCommand) ?? false; + if (matchingCommand == null || bypass) { //if the command is not defined client-side, we'll relay it anyway because it may be a custom command at the server's side GameMain.Client.SendConsoleCommand(command);