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; } }