Clients can execute permitted console commands server-side now. The console commands have three different actions: the default action, one that's executed client-side when a client uses it, and one that's executed server-side when a clients requests it. If the client-side action is omitted, the client relays the command to the server as-is. If the third action is omitted, the server executes the default action.

This commit is contained in:
Joonas Rikkonen
2017-12-06 19:52:57 +02:00
parent 91a8e6d0c6
commit 9bc0931be5
8 changed files with 551 additions and 175 deletions
@@ -608,15 +608,17 @@ namespace Barotrauma.Networking
}
}
if (newPermissions != permissions)
{
SetPermissions(newPermissions, permittedConsoleCommands);
}
SetPermissions(newPermissions, permittedConsoleCommands);
}
private void SetPermissions(ClientPermissions newPermissions, List<string> permittedConsoleCommands)
{
if (newPermissions == permissions) return;
if (!(this.permittedConsoleCommands.Any(c => !permittedConsoleCommands.Contains(c)) ||
permittedConsoleCommands.Any(c => !this.permittedConsoleCommands.Contains(c))))
{
if (newPermissions == permissions) return;
}
GUIMessageBox.MessageBoxes.RemoveAll(mb => mb.UserData as string == "permissions");
string msg = "";
@@ -637,7 +639,9 @@ namespace Barotrauma.Networking
//TODO: display permitted console commands
}
permissions = newPermissions;
this.permittedConsoleCommands = new List<string>(permittedConsoleCommands);
new GUIMessageBox("Permissions changed", msg).UserData = "permissions";
GameMain.NetLobbyScreen.SubList.Enabled = Voting.AllowSubVoting || HasPermission(ClientPermissions.SelectSub);
@@ -1384,6 +1388,9 @@ namespace Barotrauma.Networking
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
msg.Write((byte)ClientPermissions.ConsoleCommands);
msg.Write(command);
Vector2 cursorWorldPos = GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
msg.Write(cursorWorldPos.X);
msg.Write(cursorWorldPos.Y);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
}