diff --git a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs index baeeb3e80..b5693519a 100644 --- a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs @@ -452,6 +452,10 @@ namespace Barotrauma commands.Add(new Command("clientlist", "", (string[] args) => { })); AssignRelayToServer("clientlist", true); + commands.Add(new Command("setmaxplayers|maxplayers", "", (string[] args) => { })); + AssignRelayToServer("setmaxplayers", true); + commands.Add(new Command("setpassword|password", "", (string[] args) => { })); + AssignRelayToServer("setpassword", true); AssignOnExecute("control", (string[] args) => { diff --git a/Barotrauma/BarotraumaServer/Source/DebugConsole.cs b/Barotrauma/BarotraumaServer/Source/DebugConsole.cs index f097ff73b..bfb5fa573 100644 --- a/Barotrauma/BarotraumaServer/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/Source/DebugConsole.cs @@ -788,11 +788,47 @@ namespace Barotrauma GameMain.Server.SendConsoleMessage("The code words are: " + traitorManager.codeWords + ", response: " + traitorManager.codeResponse + ".", client); }); - commands.Add(new Command("setpassword|setserverpassword", "setpassword [password]: Changes the password of the server that's being hosted.", (string[] args) => + commands.Add(new Command("setpassword|setserverpassword|password", "setpassword [password]: Changes the password of the server that's being hosted.", (string[] args) => + { + if (GameMain.Server == null) { return; } + GameMain.Server.ServerSettings.SetPassword(args.Length > 0 ? args[0] : ""); + NewMessage(GameMain.Server.ServerSettings.HasPassword ? "Changed the server password." : "Removed password protection from the server."); + })); + AssignOnClientRequestExecute("setpassword", (Client client, Vector2 cursorPos, string[] args) => + { + if (GameMain.Server == null) { return; } + GameMain.Server.ServerSettings.SetPassword(args.Length > 0 ? args[0] : ""); + NewMessage(client.Name + " " + (GameMain.Server.ServerSettings.HasPassword ? " changed the server password to \"" + args[0] + "\"." : " removed password protection from the server.")); + GameMain.Server.SendConsoleMessage(GameMain.Server.ServerSettings.HasPassword ? "Changed the server password." : "Removed password protection from the server.", client); + }); + + commands.Add(new Command("setmaxplayers|maxplayers", "setmaxplayers [max players]: Sets the maximum player count of the server that's being hosted.", (string[] args) => { if (GameMain.Server == null || args.Length == 0) return; - GameMain.Server.ServerSettings.SetPassword(args[0]); + if (!int.TryParse(args[0], out int maxPlayers)) + { + NewMessage(args[0] + " is not a valid player count."); + } + else + { + GameMain.Server.ServerSettings.MaxPlayers = maxPlayers; + NewMessage("Set the maximum player count to " + maxPlayers + "."); + } })); + AssignOnClientRequestExecute("setmaxplayers", (Client client, Vector2 cursorPos, string[] args) => + { + if (GameMain.Server == null || args.Length == 0) return; + if (!int.TryParse(args[0], out int maxPlayers)) + { + GameMain.Server.SendConsoleMessage(args[0] + " is not a valid player count.", client); + } + else + { + GameMain.Server.ServerSettings.MaxPlayers = maxPlayers; + NewMessage(client.Name + " set the maximum player count to " + maxPlayers + "."); + GameMain.Server.SendConsoleMessage("Set the maximum player count to " + maxPlayers + ".", client); + } + }); commands.Add(new Command("restart|reset", "restart/reset: Close and restart the server.", (string[] args) => { @@ -1589,12 +1625,6 @@ namespace Barotrauma } })); - commands.Add(new Command("setpassword|setserverpassword", "setpassword [password]: Changes the password of the server that's being hosted.", (string[] args) => - { - if (GameMain.Server == null || args.Length == 0) return; - GameMain.Server.ServerSettings.SetPassword(args[0]); - })); - #if DEBUG commands.Add(new Command("spamevents", "A debug command that creates a ton of entity events.", (string[] args) => { diff --git a/Barotrauma/BarotraumaShared/Source/Networking/ServerSettings.cs b/Barotrauma/BarotraumaShared/Source/Networking/ServerSettings.cs index 30db27a96..739d3946e 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/ServerSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/ServerSettings.cs @@ -611,6 +611,7 @@ namespace Barotrauma.Networking public int MaxPlayers { get { return maxPlayers; } + set { maxPlayers = MathHelper.Clamp(value, 1, NetConfig.MaxPlayers); } } public List AllowedRandomMissionTypes @@ -635,7 +636,14 @@ namespace Barotrauma.Networking public void SetPassword(string password) { - this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password))); + if (string.IsNullOrEmpty(password)) + { + this.password = ""; + } + else + { + this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password))); + } } public bool IsPasswordCorrect(string input, int nonce)