Fix client-side commands working when they shouldn't

This commit is contained in:
EvilFactory
2022-10-28 15:14:43 -03:00
parent d88a6b5ef0
commit 09979cb4c9
4 changed files with 30 additions and 9 deletions

View File

@@ -220,6 +220,8 @@ namespace Barotrauma
private static bool IsCommandPermitted(string command, GameClient client)
{
if (GameMain.LuaCs.Game.IsCustomCommandPermitted(command)) { return true; }
switch (command)
{
case "kick":
@@ -3256,8 +3258,7 @@ namespace Barotrauma
}
});
const string CMD_CL_LUA = "cl_lua";
commands.Add(new Command(CMD_CL_LUA, $"{CMD_CL_LUA}: runs a string on the client", (string[] args) =>
commands.Add(new Command("cl_lua", $"cl_lua: Runs a string on the client.", (string[] args) =>
{
if (GameMain.Client != null && !GameMain.Client.HasPermission(ClientPermissions.ConsoleCommands))
{
@@ -3275,8 +3276,7 @@ namespace Barotrauma
}
}));
const string CMD_CL_CS = "cl_cs";
commands.Add(new Command(CMD_CL_CS, $"{CMD_CL_CS}: runs a string on the client", (string[] args) =>
commands.Add(new Command("cl_cs", $"cl_cs: Runs a string on the client.", (string[] args) =>
{
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }
@@ -3290,7 +3290,7 @@ namespace Barotrauma
GameMain.LuaCs.RecreateCsScript();
}));
commands.Add(new Command("cl_reloadlua", "reloads lua on the client", (string[] args) =>
commands.Add(new Command("cl_reloadlua|cl_reloadcs|cl_reloadluacs", "Re-initializes the LuaCs environment.", (string[] args) =>
{
GameMain.LuaCs.Initialize();
}));

View File

@@ -1251,7 +1251,7 @@ namespace Barotrauma
}));
commands.Add(new Command("lua", "lua: runs a string", (string[] args) =>
commands.Add(new Command("lua", "lua: Runs a string.", (string[] args) =>
{
try
{
@@ -1262,7 +1262,7 @@ namespace Barotrauma
GameMain.LuaCs.HandleException(ex, LuaCsMessageOrigin.LuaMod);
}
}));
commands.Add(new Command("cs", "cs: Runs a string", (string[] args) =>
commands.Add(new Command("cs", "cs: Runs a string.", (string[] args) =>
{
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }

View File

@@ -1956,8 +1956,8 @@ namespace Barotrauma
#if DEBUG
AddWarning($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\". Executing the command anyway because this is a debug build.");
#else
//ThrowError($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\"!");
//return;
ThrowError($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\"!");
return;
#endif
}
}

View File

@@ -388,6 +388,27 @@ namespace Barotrauma
}
private List<DebugConsole.Command> luaAddedCommand = new List<DebugConsole.Command>();
public IEnumerable<DebugConsole.Command> LuaAddedCommand { get { return luaAddedCommand; } }
public bool IsCustomCommandPermitted(string command)
{
DebugConsole.Command[] permitted = new DebugConsole.Command[]
{
DebugConsole.FindCommand("cl_reloadluacs"),
DebugConsole.FindCommand("cl_lua"),
DebugConsole.FindCommand("cl_cs"),
};
foreach (var consoleCommand in LuaAddedCommand.Concat(permitted.AsEnumerable()))
{
if (consoleCommand.names.Contains(command))
{
return true;
}
}
return false;
}
public void RemoveCommand(string name)
{