From 4f7a15f9bf9def857ef9b0ce8c8b46e13fe68af3 Mon Sep 17 00:00:00 2001 From: White Date: Sat, 31 Dec 2016 11:33:48 +1030 Subject: [PATCH] Ensures Netplay.ServerPassword is always empty. This prevents an issue in which packets are sent in an unexpected order resulting in clients being unable to connect when a CLI-defined password is used. A CLI-defined password will now override any TShock config-defined password. --- TShockAPI/TShock.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index fcd30a65..1efab2a3 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -822,6 +822,7 @@ namespace TShockAPI /// AuthToken - The auth token used by the /auth system to grant temporary superadmin access to new admins. public static int AuthToken = -1; + private string _cliPassword = null; /// OnPostInit - Fired when the server loads a map, to perform world specific operations. /// args - The EventArgs object. @@ -829,6 +830,16 @@ namespace TShockAPI { SetConsoleTitle(false); + //This is to prevent a bug where a CLI-defined password causes packets to be + //sent in an unexpected order, resulting in clients being unable to connect + if (!string.IsNullOrEmpty(Netplay.ServerPassword)) + { + //CLI defined password overrides a config password + _cliPassword = Netplay.ServerPassword; + Netplay.ServerPassword = ""; + Config.ServerPassword = _cliPassword; + } + // Disable the auth system if "auth.lck" is present or a superadmin exists if (File.Exists(Path.Combine(SavePath, "auth.lck")) || Users.GetUsers().Exists(u => u.Group == new SuperAdminGroup().Name)) { @@ -2172,7 +2183,14 @@ namespace TShockAPI if (file.MaxSlots > 235) file.MaxSlots = 235; Main.maxNetPlayers = file.MaxSlots + 20; + Netplay.ServerPassword = ""; + if (!string.IsNullOrEmpty(_cliPassword)) + { + //This prevents a config reload from removing/updating a CLI-defined password + file.ServerPassword = _cliPassword; + } + Netplay.spamCheck = false; } }