Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool?>("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;
Expand Down
4 changes: 3 additions & 1 deletion Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool?>("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);
Expand Down