Majorly improve 'server port utilities' dialog window

It uses server's port instead of having to type in a port, it shows a more useful description message, and it uses https:// instead of http:// for external links
This commit is contained in:
UnknownShadow200 2019-07-11 10:23:44 +10:00
parent 2e7c82105c
commit 50b4b0db47
5 changed files with 112 additions and 152 deletions

View File

@ -25,143 +25,120 @@ namespace MCGalaxy.Gui.Popups {
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.linkManually = new System.Windows.Forms.LinkLabel();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.gbUpnp = new System.Windows.Forms.GroupBox();
this.btnDelete = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.linkHelpForward = new System.Windows.Forms.LinkLabel();
this.txtPortForward = new System.Windows.Forms.TextBox();
this.lblForward = new System.Windows.Forms.Label();
this.lblResult = new System.Windows.Forms.Label();
this.btnForward = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip( this.components );
this.groupBox2.SuspendLayout();
this.lblInfo = new System.Windows.Forms.Label();
this.linkHelpForward = new System.Windows.Forms.LinkLabel();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.gbUpnp.SuspendLayout();
this.SuspendLayout();
//
// groupBox2
//
this.groupBox2.Controls.Add( this.btnDelete );
this.groupBox2.Controls.Add( this.label3 );
this.groupBox2.Controls.Add( this.txtPortForward );
this.groupBox2.Controls.Add( this.lblForward );
this.groupBox2.Controls.Add( this.btnForward );
this.groupBox2.Controls.Add( this.label2 );
this.groupBox2.Location = new System.Drawing.Point( 12, 42 );
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size( 274, 150 );
this.groupBox2.TabIndex = 7;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Port Forward";
//
// linkManually
//
this.linkManually.AutoSize = true;
this.linkManually.Location = new System.Drawing.Point( 12, 10 );
this.linkManually.Location = new System.Drawing.Point(12, 10);
this.linkManually.Name = "linkManually";
this.linkManually.Size = new System.Drawing.Size( 83, 13 );
this.linkManually.Size = new System.Drawing.Size(86, 13);
this.linkManually.TabIndex = 4;
this.linkManually.TabStop = true;
this.linkManually.Text = "Check port open";
this.linkManually.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler( this.linkManually_LinkClicked );
this.linkManually.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkManually_LinkClicked);
//
// gbUpnp
//
this.gbUpnp.Controls.Add(this.btnDelete);
this.gbUpnp.Controls.Add(this.lblResult);
this.gbUpnp.Controls.Add(this.btnForward);
this.gbUpnp.Controls.Add(this.lblInfo);
this.gbUpnp.Location = new System.Drawing.Point(11, 42);
this.gbUpnp.Name = "gbUpnp";
this.gbUpnp.Size = new System.Drawing.Size(274, 115);
this.gbUpnp.TabIndex = 7;
this.gbUpnp.TabStop = false;
this.gbUpnp.Text = "Auto port forward";
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(156, 66);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(93, 23);
this.btnDelete.TabIndex = 12;
this.btnDelete.Text = "Delete forward";
this.btnDelete.UseVisualStyleBackColor = true;
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// lblResult
//
this.lblResult.AutoSize = true;
this.lblResult.ForeColor = System.Drawing.SystemColors.ButtonShadow;
this.lblResult.Location = new System.Drawing.Point(22, 91);
this.lblResult.Name = "lblResult";
this.lblResult.Size = new System.Drawing.Size(0, 13);
this.lblResult.TabIndex = 8;
//
// btnForward
//
this.btnForward.Location = new System.Drawing.Point(22, 66);
this.btnForward.Name = "btnForward";
this.btnForward.Size = new System.Drawing.Size(86, 23);
this.btnForward.TabIndex = 9;
this.btnForward.Text = "Forward 25565";
this.toolTip1.SetToolTip(this.btnForward, "This does not work for everyone, keep trying or manually port forward.\r\n");
this.btnForward.UseVisualStyleBackColor = true;
this.btnForward.Click += new System.EventHandler(this.btnForward_Click);
//
// lblInfo
//
this.lblInfo.AutoSize = true;
this.lblInfo.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblInfo.Location = new System.Drawing.Point(22, 16);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(239, 36);
this.lblInfo.TabIndex = 0;
this.lblInfo.Text = "This uses UPnP, which not all routers support.\r\nIf this doesn\'t work, you will ha" +
"ve to\r\n manually port forward in your router.";
this.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// linkHelpForward
//
this.linkHelpForward.AutoSize = true;
this.linkHelpForward.Location = new System.Drawing.Point( 222, 10 );
this.linkHelpForward.Location = new System.Drawing.Point(172, 10);
this.linkHelpForward.Name = "linkHelpForward";
this.linkHelpForward.Size = new System.Drawing.Size( 64, 13 );
this.linkHelpForward.Size = new System.Drawing.Size(114, 13);
this.linkHelpForward.TabIndex = 11;
this.linkHelpForward.TabStop = true;
this.linkHelpForward.Text = "Need Help?";
this.linkHelpForward.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler( this.linkHelpForward_LinkClicked );
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point( 156, 110 );
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size( 93, 23 );
this.btnDelete.TabIndex = 12;
this.btnDelete.Text = "Delete Forward";
this.btnDelete.UseVisualStyleBackColor = true;
this.btnDelete.Click += new System.EventHandler( this.btnDelete_Click );
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point( 22, 69 );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size( 29, 13 );
this.label3.TabIndex = 6;
this.label3.Text = "Port:";
//
// txtPortForward
//
this.txtPortForward.Location = new System.Drawing.Point( 57, 66 );
this.txtPortForward.MaxLength = 5;
this.txtPortForward.Name = "txtPortForward";
this.txtPortForward.Size = new System.Drawing.Size( 192, 20 );
this.txtPortForward.TabIndex = 7;
//
// lblForward
//
this.lblForward.AutoSize = true;
this.lblForward.ForeColor = System.Drawing.SystemColors.ButtonShadow;
this.lblForward.Location = new System.Drawing.Point( 22, 91 );
this.lblForward.Name = "lblForward";
this.lblForward.Size = new System.Drawing.Size( 0, 13 );
this.lblForward.TabIndex = 8;
//
// btnForward
//
this.btnForward.Location = new System.Drawing.Point( 30, 110 );
this.btnForward.Name = "btnForward";
this.btnForward.Size = new System.Drawing.Size( 75, 23 );
this.btnForward.TabIndex = 9;
this.btnForward.Text = "Forward";
this.toolTip1.SetToolTip( this.btnForward, "This method does not work for everyone, keep trying or manually forward.\r\n" );
this.btnForward.UseVisualStyleBackColor = true;
this.btnForward.Click += new System.EventHandler( this.btnForward_Click );
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font( "Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( (byte) ( 0 ) ) );
this.label2.Location = new System.Drawing.Point( 29, 16 );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size( 220, 36 );
this.label2.TabIndex = 0;
this.label2.Text = "Warning! This method uses UPnP \r\nwhich does have known security issues. \r\nUse " +
"at your own risk.";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.linkHelpForward.Text = "Need help forwarding?";
this.linkHelpForward.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkHelpForward_LinkClicked);
//
// PortTools
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size( 296, 204 );
this.Controls.Add( this.groupBox2 );
this.Controls.Add( this.linkManually );
this.Controls.Add( this.linkHelpForward );
this.ClientSize = new System.Drawing.Size(296, 168);
this.Controls.Add(this.gbUpnp);
this.Controls.Add(this.linkManually);
this.Controls.Add(this.linkHelpForward);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "PortTools";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Port Tools";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler( this.PortChecker_FormClosing );
this.groupBox2.ResumeLayout( false );
this.groupBox2.PerformLayout();
this.ResumeLayout( false );
this.Text = "Port forward tools";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.PortChecker_FormClosing);
this.gbUpnp.ResumeLayout(false);
this.gbUpnp.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.LinkLabel linkManually;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox gbUpnp;
private System.Windows.Forms.LinkLabel linkHelpForward;
private System.Windows.Forms.TextBox txtPortForward;
private System.Windows.Forms.Label lblForward;
private System.Windows.Forms.Label lblResult;
private System.Windows.Forms.Button btnForward;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label lblInfo;
private System.Windows.Forms.Button btnDelete;
private System.Windows.Forms.ToolTip toolTip1;
}

View File

@ -27,61 +27,45 @@ namespace MCGalaxy.Gui.Popups {
public partial class PortTools : Form {
readonly BackgroundWorker worker;
public PortTools() {
int port;
public PortTools(string portStr) {
InitializeComponent();
worker = new BackgroundWorker { WorkerSupportsCancellation = true };
worker.DoWork += mWorkerForwarder_DoWork;
worker.RunWorkerCompleted += mWorkerForwarder_RunWorkerCompleted;
if (!int.TryParse(portStr, out port)) port = 25565;
btnForward.Text = "Forward " + port;
}
private void linkManually_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
try { Process.Start("http://www.canyouseeme.org/"); }
void linkManually_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
try { Process.Start("https://www.canyouseeme.org/"); }
catch { }
}
private void PortChecker_FormClosing(object sender, FormClosingEventArgs e) {
void PortChecker_FormClosing(object sender, FormClosingEventArgs e) {
worker.CancelAsync();
}
private void linkHelpForward_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
try { Process.Start("http://portforward.com"); }
void linkHelpForward_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
try { Process.Start("https://portforward.com"); }
catch { }
}
private void btnForward_Click(object sender, EventArgs e) {
int port = 25565;
if (String.IsNullOrEmpty(txtPortForward.Text.Trim()))
txtPortForward.Text = "25565";
try {
port = int.Parse(txtPortForward.Text);
} catch {
txtPortForward.Text = "25565";
}
void btnForward_Click(object sender, EventArgs e) {
SetUPnPEnabled(false);
worker.RunWorkerAsync(new object[] { port, true });
worker.RunWorkerAsync(true);
}
private void btnDelete_Click(object sender, EventArgs e) {
int port = 25565;
if (String.IsNullOrEmpty(txtPortForward.Text.Trim()))
txtPortForward.Text = "25565";
try {
port = int.Parse(txtPortForward.Text);
} catch {
txtPortForward.Text = "25565";
}
void btnDelete_Click(object sender, EventArgs e) {
SetUPnPEnabled(false);
worker.RunWorkerAsync(new object[] { port, false });
worker.RunWorkerAsync(false);
}
void mWorkerForwarder_DoWork(object sender, DoWorkEventArgs e) {
int tries = 0;
int port = (int)((object[])e.Argument)[0];
bool adding = (bool)((object[])e.Argument)[1];
bool adding = (bool)e.Argument;
retry:
try {
@ -108,28 +92,27 @@ namespace MCGalaxy.Gui.Popups {
int result = (int)e.Result;
switch (result) {
case 0:
lblForward.Text = "Error contacting router.";
lblForward.ForeColor = Color.Red;
lblResult.Text = "Error contacting router.";
lblResult.ForeColor = Color.Red;
return;
case 1:
lblForward.Text = "Port forwarded automatically using UPnP";
lblForward.ForeColor = Color.Green;
lblResult.Text = "Port forwarded automatically using UPnP";
lblResult.ForeColor = Color.Green;
return;
case 2:
lblForward.Text = "Something Weird just happened, try again.";
lblForward.ForeColor = Color.Black;
lblResult.Text = "Something weird just happened, try again.";
lblResult.ForeColor = Color.Black;
return;
case 3:
lblForward.Text = "Deleted Port Forward Rule.";
lblForward.ForeColor = Color.Green;
lblResult.Text = "Deleted port forward rule.";
lblResult.ForeColor = Color.Green;
return;
}
}
void SetUPnPEnabled(bool enabled) {
btnDelete.Enabled = enabled;
btnForward.Enabled = enabled;
txtPortForward.Enabled = enabled;
btnForward.Enabled = enabled;
}
}
}

View File

@ -2637,11 +2637,11 @@ namespace MCGalaxy.Gui
// srv_btnPort
//
this.srv_btnPort.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.srv_btnPort.Location = new System.Drawing.Point(152, 71);
this.srv_btnPort.Location = new System.Drawing.Point(152, 72);
this.srv_btnPort.Name = "srv_btnPort";
this.srv_btnPort.Size = new System.Drawing.Size(110, 23);
this.srv_btnPort.Size = new System.Drawing.Size(95, 23);
this.srv_btnPort.TabIndex = 3;
this.srv_btnPort.Text = "Server Port Utilities";
this.srv_btnPort.Text = "Port forwarding";
this.srv_btnPort.UseVisualStyleBackColor = true;
this.srv_btnPort.Click += new System.EventHandler(this.ChkPort_Click);
//

View File

@ -75,7 +75,7 @@ namespace MCGalaxy.Gui {
}
void ChkPort_Click(object sender, EventArgs e) {
using (PortTools form = new PortTools()) {
using (PortTools form = new PortTools(srv_numPort.Text)) {
form.ShowDialog();
}
}

View File

@ -92,7 +92,7 @@ namespace MCGalaxy.Gui {
}
ushort size;
if (!ushort.TryParse(value, out size) || size > 16384) {
if (!ushort.TryParse(value, out size) || size == 0 || size > 16384) {
Popup.Warning("Map " + propName + " must be an integer between 1 and 16384");
return null;
}