From ecb9a7c0df9ac8413e33ae3bea1bf74eafa1f1c4 Mon Sep 17 00:00:00 2001 From: dolphinspired Date: Tue, 30 Jan 2024 22:46:34 -0500 Subject: [PATCH 1/2] Add options to bypass password validation --- ValheimServerGUI/Forms/MainWindow.cs | 1 + .../Forms/PreferencesForm.Designer.cs | 35 +++++++--- ValheimServerGUI/Forms/PreferencesForm.cs | 3 + ValheimServerGUI/Forms/PreferencesForm.resx | 70 ++++++++++++++++++- ValheimServerGUI/Game/UserPreferences.cs | 4 ++ ValheimServerGUI/Game/UserPreferencesFile.cs | 3 + ValheimServerGUI/Game/ValheimServerOptions.cs | 21 +++--- 7 files changed, 117 insertions(+), 20 deletions(-) diff --git a/ValheimServerGUI/Forms/MainWindow.cs b/ValheimServerGUI/Forms/MainWindow.cs index 240c461..cb90654 100644 --- a/ValheimServerGUI/Forms/MainWindow.cs +++ b/ValheimServerGUI/Forms/MainWindow.cs @@ -1151,6 +1151,7 @@ private ValheimServerOptions GetServerOptionsFromFormState() { Name = serverPrefs.Name, Password = serverPrefs.Password, + PasswordValidation = userPrefs.EnablePasswordValidation, WorldName = serverPrefs.WorldName, // Server automatically creates a new world if a world doesn't yet exist w/ that name Public = serverPrefs.Public, Port = serverPrefs.Port, diff --git a/ValheimServerGUI/Forms/PreferencesForm.Designer.cs b/ValheimServerGUI/Forms/PreferencesForm.Designer.cs index 111777a..d0d7914 100644 --- a/ValheimServerGUI/Forms/PreferencesForm.Designer.cs +++ b/ValheimServerGUI/Forms/PreferencesForm.Designer.cs @@ -38,6 +38,7 @@ private void InitializeComponent() StartWithWindowsField = new ValheimServerGUI.Controls.CheckboxFormField(); StartMinimizedField = new ValheimServerGUI.Controls.CheckboxFormField(); WriteLogFileField = new ValheimServerGUI.Controls.CheckboxFormField(); + PasswordValidationField = new ValheimServerGUI.Controls.CheckboxFormField(); SuspendLayout(); // // ButtonCancel @@ -77,9 +78,9 @@ private void InitializeComponent() // CheckForUpdatesField.HelpText = resources.GetString("CheckForUpdatesField.HelpText"); CheckForUpdatesField.LabelText = "Automatically check for updates"; - CheckForUpdatesField.Location = new System.Drawing.Point(12, 35); + CheckForUpdatesField.Location = new System.Drawing.Point(12, 12); CheckForUpdatesField.Name = "CheckForUpdatesField"; - CheckForUpdatesField.Size = new System.Drawing.Size(334, 17); + CheckForUpdatesField.Size = new System.Drawing.Size(335, 17); CheckForUpdatesField.TabIndex = 1; CheckForUpdatesField.Value = false; // @@ -87,9 +88,9 @@ private void InitializeComponent() // SaveProfileOnStartField.HelpText = "If enabled, any changes you made to your server profile\r\nwill be saved when you click Start Server. Otherwise, you\r\nmust manually save changes with File > Save."; SaveProfileOnStartField.LabelText = "Auto save profile when starting server"; - SaveProfileOnStartField.Location = new System.Drawing.Point(12, 12); + SaveProfileOnStartField.Location = new System.Drawing.Point(12, 35); SaveProfileOnStartField.Name = "SaveProfileOnStartField"; - SaveProfileOnStartField.Size = new System.Drawing.Size(334, 17); + SaveProfileOnStartField.Size = new System.Drawing.Size(335, 17); SaveProfileOnStartField.TabIndex = 0; SaveProfileOnStartField.Value = false; // @@ -97,19 +98,19 @@ private void InitializeComponent() // StartWithWindowsField.HelpText = "To start your server(s) on Windows startup, enable this setting \r\nalong with \"Start this server when ValheimServerGUI starts\"\r\nunder Advanced Controls for each server."; StartWithWindowsField.LabelText = "Start ValheimServerGUI with Windows"; - StartWithWindowsField.Location = new System.Drawing.Point(12, 81); + StartWithWindowsField.Location = new System.Drawing.Point(12, 104); StartWithWindowsField.Name = "StartWithWindowsField"; - StartWithWindowsField.Size = new System.Drawing.Size(334, 17); + StartWithWindowsField.Size = new System.Drawing.Size(335, 17); StartWithWindowsField.TabIndex = 3; StartWithWindowsField.Value = false; // // StartMinimizedField // - StartMinimizedField.HelpText = ""; + StartMinimizedField.HelpText = "Enable this setting to minimize VSG to the Windows system\r\ntray when it starts up."; StartMinimizedField.LabelText = "Start ValheimServerGUI minimized"; - StartMinimizedField.Location = new System.Drawing.Point(12, 104); + StartMinimizedField.Location = new System.Drawing.Point(12, 127); StartMinimizedField.Name = "StartMinimizedField"; - StartMinimizedField.Size = new System.Drawing.Size(334, 17); + StartMinimizedField.Size = new System.Drawing.Size(335, 17); StartMinimizedField.TabIndex = 4; StartMinimizedField.Value = false; // @@ -117,17 +118,28 @@ private void InitializeComponent() // WriteLogFileField.HelpText = resources.GetString("WriteLogFileField.HelpText"); WriteLogFileField.LabelText = "Write application logs to file"; - WriteLogFileField.Location = new System.Drawing.Point(12, 58); + WriteLogFileField.Location = new System.Drawing.Point(12, 81); WriteLogFileField.Name = "WriteLogFileField"; - WriteLogFileField.Size = new System.Drawing.Size(334, 17); + WriteLogFileField.Size = new System.Drawing.Size(335, 17); WriteLogFileField.TabIndex = 2; WriteLogFileField.Value = false; // + // PasswordValidationField + // + PasswordValidationField.HelpText = resources.GetString("PasswordValidationField.HelpText"); + PasswordValidationField.LabelText = "Validate password when starting server"; + PasswordValidationField.Location = new System.Drawing.Point(12, 58); + PasswordValidationField.Name = "PasswordValidationField"; + PasswordValidationField.Size = new System.Drawing.Size(335, 17); + PasswordValidationField.TabIndex = 8; + PasswordValidationField.Value = false; + // // PreferencesForm // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; ClientSize = new System.Drawing.Size(359, 217); + Controls.Add(PasswordValidationField); Controls.Add(WriteLogFileField); Controls.Add(StartMinimizedField); Controls.Add(StartWithWindowsField); @@ -154,5 +166,6 @@ private void InitializeComponent() private ValheimServerGUI.Controls.CheckboxFormField StartWithWindowsField; private ValheimServerGUI.Controls.CheckboxFormField StartMinimizedField; private ValheimServerGUI.Controls.CheckboxFormField WriteLogFileField; + private ValheimServerGUI.Controls.CheckboxFormField PasswordValidationField; } } \ No newline at end of file diff --git a/ValheimServerGUI/Forms/PreferencesForm.cs b/ValheimServerGUI/Forms/PreferencesForm.cs index 720cbe4..0a4ed31 100644 --- a/ValheimServerGUI/Forms/PreferencesForm.cs +++ b/ValheimServerGUI/Forms/PreferencesForm.cs @@ -40,6 +40,7 @@ private void InitializeFormFields() StartWithWindowsField.Value = prefs.StartWithWindows; StartMinimizedField.Value = prefs.StartMinimized; WriteLogFileField.Value = prefs.WriteApplicationLogsToFile; + PasswordValidationField.Value = prefs.EnablePasswordValidation; var startupInterval = TimeSpan.Parse(Resources.UpdateCheckInterval); CheckForUpdatesField.HelpText = CheckForUpdatesField.HelpText?.Replace("{startupInterval}", $"{startupInterval.TotalHours} hours"); @@ -54,6 +55,7 @@ private void ButtonOK_Click(object sender, EventArgs e) prefs.StartWithWindows = StartWithWindowsField.Value; prefs.StartMinimized = StartMinimizedField.Value; prefs.WriteApplicationLogsToFile = WriteLogFileField.Value; + prefs.EnablePasswordValidation = PasswordValidationField.Value; StartupHelper.ApplyStartupSetting(prefs.StartWithWindows, Logger); @@ -75,6 +77,7 @@ private void ButtonDefaults_Click(object sender, EventArgs e) StartWithWindowsField.Value = prefs.StartWithWindows; StartMinimizedField.Value = prefs.StartMinimized; WriteLogFileField.Value = prefs.WriteApplicationLogsToFile; + PasswordValidationField.Value = prefs.EnablePasswordValidation; } } } diff --git a/ValheimServerGUI/Forms/PreferencesForm.resx b/ValheimServerGUI/Forms/PreferencesForm.resx index 519bc4c..adcc57b 100644 --- a/ValheimServerGUI/Forms/PreferencesForm.resx +++ b/ValheimServerGUI/Forms/PreferencesForm.resx @@ -1,4 +1,64 @@ - + + + @@ -72,4 +132,12 @@ Note: this setting does not affect your server's logs. You can toggle server logs under the Advanced Controls tab for each server profile. + + Valheim Dedicated Server will not start if certain password +requirements aren't met, and VSG enforces these requirements. + +Only disable this setting if you are running a mod that bypasses +server password requirements, and you would like VSG to stop +validating passwords as well. + \ No newline at end of file diff --git a/ValheimServerGUI/Game/UserPreferences.cs b/ValheimServerGUI/Game/UserPreferences.cs index 3739470..edc38c9 100644 --- a/ValheimServerGUI/Game/UserPreferences.cs +++ b/ValheimServerGUI/Game/UserPreferences.cs @@ -25,6 +25,8 @@ public class UserPreferences public bool WriteApplicationLogsToFile { get; set; } = true; + public bool EnablePasswordValidation { get; set; } = true; + public List Servers { get; set; } = new(); public List Worlds { get; set; } = new(); @@ -42,6 +44,7 @@ public static UserPreferences FromFile(UserPreferencesFile file) prefs.StartMinimized = file.StartMinimized ?? prefs.StartMinimized; prefs.SaveProfileOnStart = file.SaveProfileOnStart ?? prefs.SaveProfileOnStart; prefs.WriteApplicationLogsToFile = file.WriteApplicationLogsToFile ?? prefs.WriteApplicationLogsToFile; + prefs.EnablePasswordValidation = file.EnablePasswordValidation ?? prefs.EnablePasswordValidation; if (file.Servers != null) { @@ -75,6 +78,7 @@ public UserPreferencesFile ToFile() StartMinimized = StartMinimized, SaveProfileOnStart = SaveProfileOnStart, WriteApplicationLogsToFile = WriteApplicationLogsToFile, + EnablePasswordValidation = EnablePasswordValidation, Servers = new(), Worlds = new(), }; diff --git a/ValheimServerGUI/Game/UserPreferencesFile.cs b/ValheimServerGUI/Game/UserPreferencesFile.cs index a8c715e..32b4fb5 100644 --- a/ValheimServerGUI/Game/UserPreferencesFile.cs +++ b/ValheimServerGUI/Game/UserPreferencesFile.cs @@ -41,6 +41,9 @@ public class UserPreferencesFile [JsonProperty("writeApplicationLogsToFile")] public bool? WriteApplicationLogsToFile { get; set; } + [JsonProperty("enablePasswordValidation")] + public bool? EnablePasswordValidation { get; set; } + [JsonProperty("servers")] public List Servers { get; set; } diff --git a/ValheimServerGUI/Game/ValheimServerOptions.cs b/ValheimServerGUI/Game/ValheimServerOptions.cs index 989feee..b476666 100644 --- a/ValheimServerGUI/Game/ValheimServerOptions.cs +++ b/ValheimServerGUI/Game/ValheimServerOptions.cs @@ -10,6 +10,8 @@ public class ValheimServerOptions : IValheimServerOptions public string Password { get; set; } + public bool PasswordValidation { get; set; } + public string WorldName { get; set; } public bool Public { get; set; } @@ -52,15 +54,18 @@ public void Validate() if (Name == WorldName) throw new ArgumentException($"The server name cannot be the same as the world name ({WorldName})."); // Password validation - if (string.IsNullOrWhiteSpace(Password)) - { - if (Public) throw new ArgumentException($"A password is required for all public games. Either set a password or disable the Community Server option."); - } - else + if (PasswordValidation) { - if (Password.Length < 5) throw new ArgumentException($"Password must be at least 5 characters."); - if (Password.Contains(Name)) throw new ArgumentException($"Password cannot contain your server name ({Name})."); - if (Password.Contains(WorldName)) throw new ArgumentException($"Password cannot contain your world name ({WorldName})."); + if (string.IsNullOrWhiteSpace(Password)) + { + if (Public) throw new ArgumentException($"A password is required for all public games. Either set a password or disable the Community Server option."); + } + else + { + if (Password.Length < 5) throw new ArgumentException($"Password must be at least 5 characters."); + if (Password.Contains(Name)) throw new ArgumentException($"Password cannot contain your server name ({Name})."); + if (Password.Contains(WorldName)) throw new ArgumentException($"Password cannot contain your world name ({WorldName})."); + } } // Port validation From b4065ab08ab200308b8e46bdf0beb79e210b23f3 Mon Sep 17 00:00:00 2001 From: dolphinspired Date: Tue, 30 Jan 2024 22:47:42 -0500 Subject: [PATCH 2/2] v2.3.0-rc.2 --- ValheimServerGUI/ValheimServerGUI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ValheimServerGUI/ValheimServerGUI.csproj b/ValheimServerGUI/ValheimServerGUI.csproj index a8476be..d96a0c9 100644 --- a/ValheimServerGUI/ValheimServerGUI.csproj +++ b/ValheimServerGUI/ValheimServerGUI.csproj @@ -10,7 +10,7 @@ A simple user interface for running Valheim Dedicated Server on Windows. 2022 GNU GPLv3 - 2.3.0-rc.1 + 2.3.0-rc.2 build$([System.DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"))