Started overhauling the client permission system to make it a bit more flexible. Now the clients can have the permission to use specific console commands (atm these commands are relayed to the server as-is).

TODO: make it possible to give clients console command permissions via the menus and the console, save command permissions, deal with commands that don't work as intended when simply relayed to the server and executed server-side, add "ranks" (preconfigured or custom sets of permissions, e.g. moderator, admin, etc).
This commit is contained in:
Joonas Rikkonen
2017-12-03 22:54:28 +02:00
parent f0225e4312
commit 0840a29ff3
6 changed files with 80 additions and 13 deletions
@@ -27,12 +27,14 @@ namespace Barotrauma
static partial class DebugConsole
{
class Command
public class Command
{
public readonly string[] names;
public readonly string help;
private Action<string[]> onExecute;
private bool relayToServer;
public Command(string name, string help, Action<string[]> onExecute)
{
names = name.Split('|');
@@ -40,7 +42,7 @@ namespace Barotrauma
this.onExecute = onExecute;
}
public void Execute(string[] args)
{
onExecute(args);
@@ -967,10 +969,19 @@ namespace Barotrauma
}
#if !DEBUG && CLIENT
if (GameMain.Client != null && !IsCommandPermitted(splitCommand[0].ToLowerInvariant(), GameMain.Client))
if (GameMain.Client != null)
{
ThrowError("You're not permitted to use the command \"" + splitCommand[0].ToLowerInvariant() + "\"!");
return;
if (GameMain.Client.HasConsoleCommandPermission(splitCommand[0].ToLowerInvariant()))
{
GameMain.Client.SendConsoleCommand(command);
NewMessage("Server command: "+command, Color.White);
return;
}
if (!IsCommandPermitted(splitCommand[0].ToLowerInvariant(), GameMain.Client))
{
ThrowError("You're not permitted to use the command \"" + splitCommand[0].ToLowerInvariant() + "\"!");
return;
}
}
#endif
@@ -987,7 +998,7 @@ namespace Barotrauma
if (!commandFound)
{
ThrowError("Command \""+splitCommand[0]+"\" not found.");
ThrowError("Command \"" + splitCommand[0] + "\" not found.");
}
}