Fixes to name builder and password in DNS.

This commit is contained in:
flash 2023-12-21 03:39:58 +01:00
parent 9dcfad3038
commit e8d6c7fa42
4 changed files with 71 additions and 29 deletions

View file

@ -55,6 +55,8 @@ namespace SoFii
this.playerNameInput = new System.Windows.Forms.TextBox(); this.playerNameInput = new System.Windows.Forms.TextBox();
this.versionLabel = new System.Windows.Forms.Label(); this.versionLabel = new System.Windows.Forms.Label();
this.mainOpenFileDiag = new System.Windows.Forms.OpenFileDialog(); 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.serverBox.SuspendLayout();
this.gameBox.SuspendLayout(); this.gameBox.SuspendLayout();
this.mainTabs.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) this.serverBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | 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.serverUseCustom);
this.serverBox.Controls.Add(this.serverAddressLabel); this.serverBox.Controls.Add(this.serverAddressLabel);
this.serverBox.Controls.Add(this.serverAddressInput); this.serverBox.Controls.Add(this.serverAddressInput);
this.serverBox.Controls.Add(this.serverResetButton); this.serverBox.Controls.Add(this.serverResetButton);
this.serverBox.Location = new System.Drawing.Point(6, 65); this.serverBox.Location = new System.Drawing.Point(6, 65);
this.serverBox.Name = "serverBox"; 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.TabIndex = 300;
this.serverBox.TabStop = false; this.serverBox.TabStop = false;
this.serverBox.Text = "Server"; this.serverBox.Text = "Server";
@ -342,6 +346,24 @@ namespace SoFii
this.mainOpenFileDiag.Filter = "SoF2 Multiplayer Executable|SoF2MP.exe"; this.mainOpenFileDiag.Filter = "SoF2 Multiplayer Executable|SoF2MP.exe";
this.mainOpenFileDiag.RestoreDirectory = true; 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 // MainWindow
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -400,6 +422,8 @@ namespace SoFii
private System.Windows.Forms.CheckBox gfxFullscreen; private System.Windows.Forms.CheckBox gfxFullscreen;
private System.Windows.Forms.Label gfxResolutionLabel; private System.Windows.Forms.Label gfxResolutionLabel;
private System.Windows.Forms.ComboBox gfxResolutionSelect; private System.Windows.Forms.ComboBox gfxResolutionSelect;
private System.Windows.Forms.Label serverPasswordLabel;
private System.Windows.Forms.TextBox serverPasswordInput;
} }
} }

View file

@ -26,12 +26,15 @@ namespace SoFii {
versionLabel.Text = $"SoFii v{Program.GetSemVerString()}"; versionLabel.Text = $"SoFii v{Program.GetSemVerString()}";
serverAddressInput.Text = Settings.ServerAddress; serverAddressInput.Text = Settings.ServerAddress;
serverPasswordInput.Text = Settings.ServerPassword;
if(Settings.UseDefaultServer) { if(Settings.UseDefaultServer) {
serverAddressInput.Enabled = false; serverAddressInput.Enabled = false;
serverPasswordInput.Enabled = false;
serverUseCustom.Checked = false; serverUseCustom.Checked = false;
LoadDefaultServer(); LoadDefaultServer();
} else { } else {
serverAddressInput.Enabled = true; serverAddressInput.Enabled = true;
serverPasswordInput.Enabled = true;
serverUseCustom.Checked = true; serverUseCustom.Checked = true;
} }
@ -216,8 +219,13 @@ namespace SoFii {
} }
string serverAddr = Settings.ServerAddress; string serverAddr = Settings.ServerAddress;
if(!Settings.UseDefaultServer && !serverAddressInput.Text.Equals(serverAddr)) string serverPass = Settings.ServerPassword;
Settings.ServerAddress = serverAddr = serverAddressInput.Text; if(!Settings.UseDefaultServer) {
if(!serverAddressInput.Text.Equals(serverAddr))
Settings.ServerAddress = serverAddr = serverAddressInput.Text;
if(!serverPasswordInput.Text.Equals(serverPass))
Settings.ServerPassword = serverPass = serverPasswordInput.Text;
}
try { try {
Enabled = false; Enabled = false;
@ -236,6 +244,8 @@ namespace SoFii {
if(!string.IsNullOrEmpty(playerName)) if(!string.IsNullOrEmpty(playerName))
args.AppendFormat(@"+seta name ""{0}"" ", playerName); args.AppendFormat(@"+seta name ""{0}"" ", playerName);
if(!string.IsNullOrEmpty(serverPass))
args.AppendFormat(@"+password ""{0}""", serverPass);
if(!string.IsNullOrEmpty(serverAddr)) if(!string.IsNullOrEmpty(serverAddr))
args.AppendFormat(@"+connect ""{0}"" +seta server1 ""{0}""", serverAddr); args.AppendFormat(@"+connect ""{0}"" +seta server1 ""{0}""", serverAddr);
@ -260,12 +270,15 @@ namespace SoFii {
serverAddressInput.Enabled = false; serverAddressInput.Enabled = false;
serverAddressInput.Text = "Loading..."; serverAddressInput.Text = "Loading...";
serverPasswordInput.Enabled = false;
serverPasswordInput.Text = "Loading...";
new Thread(() => { new Thread(() => {
void reportError(string message, string caption = "Error while fetching default server") { void reportError(string message, string caption = "Error while fetching default server") {
InvokeAction(() => { InvokeAction(() => {
MessageBox.Show(this, message, $"SoFii :: {caption}"); MessageBox.Show(this, message, $"SoFii :: {caption}");
serverAddressInput.Text = string.Empty; serverAddressInput.Text = string.Empty;
serverPasswordInput.Text = string.Empty;
serverResetButton.Text = "Retry"; serverResetButton.Text = "Retry";
}); });
}; };
@ -280,6 +293,7 @@ namespace SoFii {
string addr = string.Empty; string addr = string.Empty;
string port = string.Empty; string port = string.Empty;
string pass = string.Empty;
string ver = string.Empty; string ver = string.Empty;
StringBuilder messageBuilder = new StringBuilder(); StringBuilder messageBuilder = new StringBuilder();
@ -299,6 +313,8 @@ namespace SoFii {
addr = textPart.Substring(5); addr = textPart.Substring(5);
else if(textPart.StartsWith("port=") && string.IsNullOrEmpty(port)) else if(textPart.StartsWith("port=") && string.IsNullOrEmpty(port))
port = textPart.Substring(5); port = textPart.Substring(5);
else if(textPart.StartsWith("pass=") && string.IsNullOrEmpty(pass))
pass = textPart.Substring(5);
else if(textPart.StartsWith("ver=") && string.IsNullOrEmpty(ver)) else if(textPart.StartsWith("ver=") && string.IsNullOrEmpty(ver))
ver = textPart.Substring(4); ver = textPart.Substring(4);
} }
@ -323,6 +339,9 @@ namespace SoFii {
Settings.ServerAddress = fullAddr; Settings.ServerAddress = fullAddr;
serverAddressInput.Text = fullAddr; serverAddressInput.Text = fullAddr;
Settings.ServerPassword = pass;
serverPasswordInput.Text = pass;
if(!string.IsNullOrEmpty(ver) && int.TryParse(ver, out int version) if(!string.IsNullOrEmpty(ver) && int.TryParse(ver, out int version)
&& Program.GetSemVerInt() < version && Settings.IgnoreNewVersion < version) { && Program.GetSemVerInt() < version && Settings.IgnoreNewVersion < version) {
DialogResult result = MessageBox.Show( DialogResult result = MessageBox.Show(
@ -349,6 +368,7 @@ namespace SoFii {
} finally { } finally {
InvokeAction(() => { InvokeAction(() => {
serverAddressInput.Enabled = serverAddressInputEnabled; serverAddressInput.Enabled = serverAddressInputEnabled;
serverPasswordInput.Enabled = serverAddressInputEnabled;
serverResetButton.Enabled = true; serverResetButton.Enabled = true;
}); });
} }
@ -358,6 +378,7 @@ namespace SoFii {
private void serverResetButton_Click(object sender, EventArgs e) { private void serverResetButton_Click(object sender, EventArgs e) {
Settings.UseDefaultServer = true; Settings.UseDefaultServer = true;
serverAddressInput.Enabled = false; serverAddressInput.Enabled = false;
serverPasswordInput.Enabled = false;
serverUseCustom.Checked = false; serverUseCustom.Checked = false;
LoadDefaultServer(); LoadDefaultServer();
} }
@ -382,6 +403,7 @@ namespace SoFii {
Settings.UseDefaultServer = useDefault; Settings.UseDefaultServer = useDefault;
serverAddressInput.Enabled = useCustom; serverAddressInput.Enabled = useCustom;
serverPasswordInput.Enabled = useCustom;
if(useDefault) if(useDefault)
LoadDefaultServer(); LoadDefaultServer();
@ -402,13 +424,11 @@ namespace SoFii {
Brush brush = new SolidBrush(colour); Brush brush = new SolidBrush(colour);
Font font = SystemFonts.DefaultFont; Font font = SystemFonts.DefaultFont;
float offset = 0;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
StringBuilder sbDone = new StringBuilder();
gfx.Clear(SystemColors.ControlLightLight); gfx.Clear(SystemColors.ControlLightLight);
float spaceWidth = gfx.MeasureString("_", font).Width;
void drawBuffer() { void drawBuffer() {
if(sb.Length < 1) if(sb.Length < 1)
return; return;
@ -416,8 +436,21 @@ namespace SoFii {
string str = sb.ToString(); string str = sb.ToString();
sb.Length = 0; sb.Length = 0;
gfx.DrawString(str, font, brush, offset, 0); gfx.DrawString(
offset += gfx.MeasureString(str.Replace(' ', '_'), font).Width - spaceWidth; str,
font,
brush,
gfx.MeasureString(
sbDone.ToString(),
font,
playerNamePreview.Width,
StringFormat.GenericDefault
).Width,
0,
StringFormat.GenericDefault
);
sbDone.Append(str);
}; };
foreach(char chr in userName) { foreach(char chr in userName) {

View file

@ -1,10 +1,6 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; 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: AssemblyTitle("SoFii")]
[assembly: AssemblyDescription("Soldier of Fortune 2 Flashii assistant")] [assembly: AssemblyDescription("Soldier of Fortune 2 Flashii assistant")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
@ -13,24 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("flash.moe 2023")] [assembly: AssemblyCopyright("flash.moe 2023")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [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)] [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")] [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: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")] [assembly: AssemblyFileVersion("1.0.0")]

View file

@ -10,6 +10,7 @@ namespace SoFii {
public const string GAME_PATH = "GamePath"; public const string GAME_PATH = "GamePath";
public const string USE_DEFAULT_SERVER = "UseDefaultServer"; public const string USE_DEFAULT_SERVER = "UseDefaultServer";
public const string SERVER_ADDRESS = "ServerAddress"; public const string SERVER_ADDRESS = "ServerAddress";
public const string SERVER_PASSWORD = "ServerPassword";
public const string CUSTOM_DNS_SERVERS = "CustomDNSServers"; public const string CUSTOM_DNS_SERVERS = "CustomDNSServers";
public const string PLAYER_NAME = "PlayerName"; public const string PLAYER_NAME = "PlayerName";
public const string GFX_FULLSCREEN = "GfxFullscreen"; public const string GFX_FULLSCREEN = "GfxFullscreen";
@ -36,6 +37,11 @@ namespace SoFii {
set => Set(SERVER_ADDRESS, value); set => Set(SERVER_ADDRESS, value);
} }
public static string ServerPassword {
get => Get(SERVER_PASSWORD, string.Empty);
set => Set(SERVER_PASSWORD, value);
}
public static string[] CustomDNSServers { public static string[] CustomDNSServers {
get => Get(CUSTOM_DNS_SERVERS, string.Empty).Split(' '); get => Get(CUSTOM_DNS_SERVERS, string.Empty).Split(' ');
set { set {