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:
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ namespace Barotrauma.Networking
|
||||
[Description("Select game mode")]
|
||||
SelectMode = 16,
|
||||
[Description("Manage campaign")]
|
||||
ManageCampaign = 32
|
||||
ManageCampaign = 32,
|
||||
[Description("Console commands")]
|
||||
ConsoleCommands = 64
|
||||
}
|
||||
|
||||
class Client
|
||||
@@ -79,6 +81,7 @@ namespace Barotrauma.Networking
|
||||
public float DeleteDisconnectedTimer;
|
||||
|
||||
public ClientPermissions Permissions = ClientPermissions.None;
|
||||
public List<DebugConsole.Command> PermittedConsoleCommands = new List<DebugConsole.Command>();
|
||||
|
||||
public bool SpectateOnly;
|
||||
|
||||
|
||||
@@ -1928,6 +1928,18 @@ namespace Barotrauma.Networking
|
||||
var msg = server.CreateMessage();
|
||||
msg.Write((byte)ServerPacketHeader.PERMISSIONS);
|
||||
msg.Write((byte)client.Permissions);
|
||||
if (client.Permissions.HasFlag(ClientPermissions.ConsoleCommands))
|
||||
{
|
||||
msg.Write((UInt16)client.PermittedConsoleCommands.Sum(c => c.names.Length));
|
||||
foreach (DebugConsole.Command command in client.PermittedConsoleCommands)
|
||||
{
|
||||
foreach (string commandName in command.names)
|
||||
{
|
||||
msg.Write(commandName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
|
||||
|
||||
SaveClientPermissions();
|
||||
|
||||
@@ -316,6 +316,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void LoadClientPermissions()
|
||||
{
|
||||
//TODO: load console command permissions
|
||||
|
||||
if (!File.Exists(ClientPermissionsFile)) return;
|
||||
|
||||
string[] lines;
|
||||
@@ -348,13 +350,15 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void SaveClientPermissions()
|
||||
{
|
||||
GameServer.Log("Saving client permissions", ServerLog.MessageType.ServerMessage);
|
||||
//TODO: save console command permissions
|
||||
|
||||
Log("Saving client permissions", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
foreach (SavedClientPermission clientPermission in clientPermissions)
|
||||
{
|
||||
lines.Add(clientPermission.Name + "|" + clientPermission.IP+"|"+clientPermission.Permissions.ToString());
|
||||
lines.Add(clientPermission.Name + "|" + clientPermission.IP + "|" + clientPermission.Permissions.ToString());
|
||||
}
|
||||
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user