diff --git a/SoFii/MainWindow.Designer.cs b/SoFii/MainWindow.Designer.cs index f55277f..b2795f6 100644 --- a/SoFii/MainWindow.Designer.cs +++ b/SoFii/MainWindow.Designer.cs @@ -55,6 +55,8 @@ namespace SoFii this.playerNameInput = new System.Windows.Forms.TextBox(); this.versionLabel = new System.Windows.Forms.Label(); this.mainOpenFileDiag = new System.Windows.Forms.OpenFileDialog(); + this.serverPasswordLabel = new System.Windows.Forms.Label(); + this.serverPasswordInput = new System.Windows.Forms.TextBox(); this.serverBox.SuspendLayout(); this.gameBox.SuspendLayout(); this.mainTabs.SuspendLayout(); @@ -69,13 +71,15 @@ namespace SoFii // this.serverBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.serverBox.Controls.Add(this.serverPasswordLabel); + this.serverBox.Controls.Add(this.serverPasswordInput); this.serverBox.Controls.Add(this.serverUseCustom); this.serverBox.Controls.Add(this.serverAddressLabel); this.serverBox.Controls.Add(this.serverAddressInput); this.serverBox.Controls.Add(this.serverResetButton); this.serverBox.Location = new System.Drawing.Point(6, 65); this.serverBox.Name = "serverBox"; - this.serverBox.Size = new System.Drawing.Size(540, 71); + this.serverBox.Size = new System.Drawing.Size(540, 105); this.serverBox.TabIndex = 300; this.serverBox.TabStop = false; this.serverBox.Text = "Server"; @@ -342,6 +346,24 @@ namespace SoFii this.mainOpenFileDiag.Filter = "SoF2 Multiplayer Executable|SoF2MP.exe"; this.mainOpenFileDiag.RestoreDirectory = true; // + // serverPasswordLabel + // + this.serverPasswordLabel.AutoSize = true; + this.serverPasswordLabel.Location = new System.Drawing.Point(28, 73); + this.serverPasswordLabel.Name = "serverPasswordLabel"; + this.serverPasswordLabel.Size = new System.Drawing.Size(53, 13); + this.serverPasswordLabel.TabIndex = 305; + this.serverPasswordLabel.Text = "Password"; + // + // serverPasswordInput + // + this.serverPasswordInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.serverPasswordInput.Location = new System.Drawing.Point(87, 70); + this.serverPasswordInput.Name = "serverPasswordInput"; + this.serverPasswordInput.Size = new System.Drawing.Size(360, 20); + this.serverPasswordInput.TabIndex = 306; + // // MainWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -400,6 +422,8 @@ namespace SoFii private System.Windows.Forms.CheckBox gfxFullscreen; private System.Windows.Forms.Label gfxResolutionLabel; private System.Windows.Forms.ComboBox gfxResolutionSelect; + private System.Windows.Forms.Label serverPasswordLabel; + private System.Windows.Forms.TextBox serverPasswordInput; } } diff --git a/SoFii/MainWindow.cs b/SoFii/MainWindow.cs index 2adf65e..76e7441 100644 --- a/SoFii/MainWindow.cs +++ b/SoFii/MainWindow.cs @@ -26,12 +26,15 @@ namespace SoFii { versionLabel.Text = $"SoFii v{Program.GetSemVerString()}"; serverAddressInput.Text = Settings.ServerAddress; + serverPasswordInput.Text = Settings.ServerPassword; if(Settings.UseDefaultServer) { serverAddressInput.Enabled = false; + serverPasswordInput.Enabled = false; serverUseCustom.Checked = false; LoadDefaultServer(); } else { serverAddressInput.Enabled = true; + serverPasswordInput.Enabled = true; serverUseCustom.Checked = true; } @@ -216,8 +219,13 @@ namespace SoFii { } string serverAddr = Settings.ServerAddress; - if(!Settings.UseDefaultServer && !serverAddressInput.Text.Equals(serverAddr)) - Settings.ServerAddress = serverAddr = serverAddressInput.Text; + string serverPass = Settings.ServerPassword; + if(!Settings.UseDefaultServer) { + if(!serverAddressInput.Text.Equals(serverAddr)) + Settings.ServerAddress = serverAddr = serverAddressInput.Text; + if(!serverPasswordInput.Text.Equals(serverPass)) + Settings.ServerPassword = serverPass = serverPasswordInput.Text; + } try { Enabled = false; @@ -236,6 +244,8 @@ namespace SoFii { if(!string.IsNullOrEmpty(playerName)) args.AppendFormat(@"+seta name ""{0}"" ", playerName); + if(!string.IsNullOrEmpty(serverPass)) + args.AppendFormat(@"+password ""{0}""", serverPass); if(!string.IsNullOrEmpty(serverAddr)) args.AppendFormat(@"+connect ""{0}"" +seta server1 ""{0}""", serverAddr); @@ -260,12 +270,15 @@ namespace SoFii { serverAddressInput.Enabled = false; serverAddressInput.Text = "Loading..."; + serverPasswordInput.Enabled = false; + serverPasswordInput.Text = "Loading..."; new Thread(() => { void reportError(string message, string caption = "Error while fetching default server") { InvokeAction(() => { MessageBox.Show(this, message, $"SoFii :: {caption}"); serverAddressInput.Text = string.Empty; + serverPasswordInput.Text = string.Empty; serverResetButton.Text = "Retry"; }); }; @@ -280,6 +293,7 @@ namespace SoFii { string addr = string.Empty; string port = string.Empty; + string pass = string.Empty; string ver = string.Empty; StringBuilder messageBuilder = new StringBuilder(); @@ -299,6 +313,8 @@ namespace SoFii { addr = textPart.Substring(5); else if(textPart.StartsWith("port=") && string.IsNullOrEmpty(port)) port = textPart.Substring(5); + else if(textPart.StartsWith("pass=") && string.IsNullOrEmpty(pass)) + pass = textPart.Substring(5); else if(textPart.StartsWith("ver=") && string.IsNullOrEmpty(ver)) ver = textPart.Substring(4); } @@ -323,6 +339,9 @@ namespace SoFii { Settings.ServerAddress = fullAddr; serverAddressInput.Text = fullAddr; + Settings.ServerPassword = pass; + serverPasswordInput.Text = pass; + if(!string.IsNullOrEmpty(ver) && int.TryParse(ver, out int version) && Program.GetSemVerInt() < version && Settings.IgnoreNewVersion < version) { DialogResult result = MessageBox.Show( @@ -349,6 +368,7 @@ namespace SoFii { } finally { InvokeAction(() => { serverAddressInput.Enabled = serverAddressInputEnabled; + serverPasswordInput.Enabled = serverAddressInputEnabled; serverResetButton.Enabled = true; }); } @@ -358,6 +378,7 @@ namespace SoFii { private void serverResetButton_Click(object sender, EventArgs e) { Settings.UseDefaultServer = true; serverAddressInput.Enabled = false; + serverPasswordInput.Enabled = false; serverUseCustom.Checked = false; LoadDefaultServer(); } @@ -382,6 +403,7 @@ namespace SoFii { Settings.UseDefaultServer = useDefault; serverAddressInput.Enabled = useCustom; + serverPasswordInput.Enabled = useCustom; if(useDefault) LoadDefaultServer(); @@ -402,13 +424,11 @@ namespace SoFii { Brush brush = new SolidBrush(colour); Font font = SystemFonts.DefaultFont; - float offset = 0; StringBuilder sb = new StringBuilder(); + StringBuilder sbDone = new StringBuilder(); gfx.Clear(SystemColors.ControlLightLight); - float spaceWidth = gfx.MeasureString("_", font).Width; - void drawBuffer() { if(sb.Length < 1) return; @@ -416,8 +436,21 @@ namespace SoFii { string str = sb.ToString(); sb.Length = 0; - gfx.DrawString(str, font, brush, offset, 0); - offset += gfx.MeasureString(str.Replace(' ', '_'), font).Width - spaceWidth; + gfx.DrawString( + str, + font, + brush, + gfx.MeasureString( + sbDone.ToString(), + font, + playerNamePreview.Width, + StringFormat.GenericDefault + ).Width, + 0, + StringFormat.GenericDefault + ); + + sbDone.Append(str); }; foreach(char chr in userName) { diff --git a/SoFii/Properties/AssemblyInfo.cs b/SoFii/Properties/AssemblyInfo.cs index 337164c..7105ed2 100644 --- a/SoFii/Properties/AssemblyInfo.cs +++ b/SoFii/Properties/AssemblyInfo.cs @@ -1,10 +1,6 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. [assembly: AssemblyTitle("SoFii")] [assembly: AssemblyDescription("Soldier of Fortune 2 Flashii assistant")] [assembly: AssemblyConfiguration("")] @@ -13,24 +9,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyCopyright("flash.moe 2023")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("6026586c-8730-428a-8e61-e75568ff7185")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0")] [assembly: AssemblyFileVersion("1.0.0")] diff --git a/SoFii/Settings.cs b/SoFii/Settings.cs index e15266e..801730a 100644 --- a/SoFii/Settings.cs +++ b/SoFii/Settings.cs @@ -10,6 +10,7 @@ namespace SoFii { public const string GAME_PATH = "GamePath"; public const string USE_DEFAULT_SERVER = "UseDefaultServer"; public const string SERVER_ADDRESS = "ServerAddress"; + public const string SERVER_PASSWORD = "ServerPassword"; public const string CUSTOM_DNS_SERVERS = "CustomDNSServers"; public const string PLAYER_NAME = "PlayerName"; public const string GFX_FULLSCREEN = "GfxFullscreen"; @@ -36,6 +37,11 @@ namespace SoFii { set => Set(SERVER_ADDRESS, value); } + public static string ServerPassword { + get => Get(SERVER_PASSWORD, string.Empty); + set => Set(SERVER_PASSWORD, value); + } + public static string[] CustomDNSServers { get => Get(CUSTOM_DNS_SERVERS, string.Empty).Split(' '); set {