Fix client-side commands working when they shouldn't
This commit is contained in:
@@ -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();
|
||||
}));
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user