From b35ab05d479cfc1977cec28501b447ab6584d3d1 Mon Sep 17 00:00:00 2001 From: CaptainSqrBeard Date: Tue, 18 Mar 2025 23:21:46 +0600 Subject: [PATCH 1/3] Added hooks to bypass some checks in console --- .../ServerSource/DebugConsole.cs | 34 +++++++++++++++---- .../SharedSource/DebugConsole.cs | 4 ++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 87e7e12af9..7ab1dabdaf 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) { - 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("console.bypassCommandPermissionCheck", client, splitCommand, 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..7e9a4d9e40 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("console.bypassClientSendCheck", firstCommand, 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); From 187d9a6edd504513ad67e241accd0f89eb04433d Mon Sep 17 00:00:00 2001 From: CaptainSqrBeard Date: Thu, 20 Mar 2025 20:57:18 +0600 Subject: [PATCH 2/3] rename hooks and tweak behaviour a bit --- Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs | 4 ++-- Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 7ab1dabdaf..36f1c18a38 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -2810,12 +2810,12 @@ public static void ExecuteClientCommand(Client client, Vector2 cursorWorldPos, s 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) { passedCommandPermissionCheck = false; } - var bypass = GameMain.LuaCs.Hook.Call("console.bypassCommandPermissionCheck", client, splitCommand, passedConsolePermissionCheck, passedCommandPermissionCheck) ?? false; + var bypass = GameMain.LuaCs.Hook.Call("onConsoleCommand", client, splitCommand, passedConsolePermissionCheck, passedCommandPermissionCheck) ?? false; if (!bypass) { diff --git a/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs b/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs index 7e9a4d9e40..ffdfa13cf4 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs @@ -2429,7 +2429,7 @@ public static void ExecuteCommand(string inputtedCommands) { Command matchingCommand = commands.Find(c => c.Names.Contains(firstCommand)); - var bypass = GameMain.LuaCs.Hook.Call("console.bypassClientSendCheck", firstCommand, matchingCommand) ?? false; + var bypass = GameMain.LuaCs.Hook.Call("onClientConsoleCommand", firstCommand, 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 From eb9675fb0ecc0d7cf0ec1fbaf1917e770ccfc748 Mon Sep 17 00:00:00 2001 From: CaptainSqrBeard Date: Thu, 20 Mar 2025 21:06:45 +0600 Subject: [PATCH 3/3] changed arguments passed into hook --- Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs | 2 +- Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 36f1c18a38..78f5ea7ba7 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -2815,7 +2815,7 @@ public static void ExecuteClientCommand(Client client, Vector2 cursorWorldPos, s passedCommandPermissionCheck = false; } - var bypass = GameMain.LuaCs.Hook.Call("onConsoleCommand", client, splitCommand, passedConsolePermissionCheck, passedCommandPermissionCheck) ?? false; + var bypass = GameMain.LuaCs.Hook.Call("onConsoleCommand", client, splitCommand, matchingCommand, passedConsolePermissionCheck, passedCommandPermissionCheck) ?? false; if (!bypass) { diff --git a/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs b/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs index ffdfa13cf4..0d375c8395 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs @@ -2429,7 +2429,7 @@ public static void ExecuteCommand(string inputtedCommands) { Command matchingCommand = commands.Find(c => c.Names.Contains(firstCommand)); - var bypass = GameMain.LuaCs.Hook.Call("onClientConsoleCommand", firstCommand, matchingCommand) ?? false; + 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