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)
|
private static bool IsCommandPermitted(string command, GameClient client)
|
||||||
{
|
{
|
||||||
|
if (GameMain.LuaCs.Game.IsCustomCommandPermitted(command)) { return true; }
|
||||||
|
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case "kick":
|
case "kick":
|
||||||
@@ -3256,8 +3258,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const string CMD_CL_LUA = "cl_lua";
|
commands.Add(new Command("cl_lua", $"cl_lua: Runs a string on the client.", (string[] args) =>
|
||||||
commands.Add(new Command(CMD_CL_LUA, $"{CMD_CL_LUA}: runs a string on the client", (string[] args) =>
|
|
||||||
{
|
{
|
||||||
if (GameMain.Client != null && !GameMain.Client.HasPermission(ClientPermissions.ConsoleCommands))
|
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("cl_cs", $"cl_cs: Runs a string on the client.", (string[] args) =>
|
||||||
commands.Add(new Command(CMD_CL_CS, $"{CMD_CL_CS}: runs a string on the client", (string[] args) =>
|
|
||||||
{
|
{
|
||||||
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }
|
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }
|
||||||
|
|
||||||
@@ -3290,7 +3290,7 @@ namespace Barotrauma
|
|||||||
GameMain.LuaCs.RecreateCsScript();
|
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();
|
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
|
try
|
||||||
{
|
{
|
||||||
@@ -1262,7 +1262,7 @@ namespace Barotrauma
|
|||||||
GameMain.LuaCs.HandleException(ex, LuaCsMessageOrigin.LuaMod);
|
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; }
|
if (LuaCsSetup.GetPackage(LuaCsSetup.CsForBarotraumaId, false, true) == null) { return; }
|
||||||
|
|
||||||
|
|||||||
@@ -1956,8 +1956,8 @@ namespace Barotrauma
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
AddWarning($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\". Executing the command anyway because this is a debug build.");
|
AddWarning($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\". Executing the command anyway because this is a debug build.");
|
||||||
#else
|
#else
|
||||||
//ThrowError($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\"!");
|
ThrowError($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\"!");
|
||||||
//return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,6 +388,27 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<DebugConsole.Command> luaAddedCommand = new List<DebugConsole.Command>();
|
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)
|
public void RemoveCommand(string name)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user