From a43b8dc278b79e9017a0d2e4fce09d43b36fc43c Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 7 Mar 2018 17:26:42 +0200 Subject: [PATCH] Added a console command for changing the server password. Closes #325 --- Barotrauma/BarotraumaShared/Source/DebugConsole.cs | 6 ++++++ .../BarotraumaShared/Source/Networking/GameServer.cs | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index 5dfb8f46f..8a740d639 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -197,6 +197,12 @@ namespace Barotrauma NewMessage("***************", Color.Cyan); })); + 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.SetPassword(args[0]); + })); + commands.Add(new Command("createfilelist", "", (string[] args) => { UpdaterUtil.SaveFileList("filelist.xml"); diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs index ea27aff60..72a4eca3b 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs @@ -77,9 +77,9 @@ namespace Barotrauma.Networking this.isPublic = isPublic; this.maxPlayers = maxPlayers; this.password = ""; - if (password.Length>0) + if (password.Length > 0) { - this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password))); + SetPassword(password); } config = new NetPeerConfiguration("barotrauma"); @@ -131,6 +131,11 @@ namespace Barotrauma.Networking CoroutineManager.StartCoroutine(StartServer(isPublic)); } + public void SetPassword(string password) + { + this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password))); + } + private IEnumerable StartServer(bool isPublic) { bool error = false;