From e8436720edf1c012cef7ece1a70d1edd9bd2ed35 Mon Sep 17 00:00:00 2001 From: MichaelTheShifter Date: Sun, 26 Jun 2016 07:04:41 -0400 Subject: [PATCH] Make the Network Browser stop matchmaking when closed or a match was made. --- .../Apps/NetworkBrowser.Designer.cs | 157 +++++++++--------- .../Apps/NetworkBrowser.cs | 8 + .../Online/Hacking/Matchmaker.cs | 1 + 3 files changed, 88 insertions(+), 78 deletions(-) diff --git a/source/WindowsFormsApplication1/Apps/NetworkBrowser.Designer.cs b/source/WindowsFormsApplication1/Apps/NetworkBrowser.Designer.cs index 2b79b6d..72ffaa4 100644 --- a/source/WindowsFormsApplication1/Apps/NetworkBrowser.Designer.cs +++ b/source/WindowsFormsApplication1/Apps/NetworkBrowser.Designer.cs @@ -31,6 +31,12 @@ private void InitializeComponent() this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NetworkBrowser)); this.panel1 = new System.Windows.Forms.Panel(); + this.pnlonline = new System.Windows.Forms.Panel(); + this.btnjoinlobby = new System.Windows.Forms.Button(); + this.lbonlineservers = new System.Windows.Forms.ListBox(); + this.lbonlinedesc = new System.Windows.Forms.Label(); + this.lbonlineheader = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.btnscreen = new System.Windows.Forms.Button(); this.pnlmynet = new System.Windows.Forms.Panel(); @@ -47,16 +53,10 @@ private void InitializeComponent() this.lbnetdesc = new System.Windows.Forms.Label(); this.lbtitle = new System.Windows.Forms.Label(); this.tmrcalctotal = new System.Windows.Forms.Timer(this.components); - this.button1 = new System.Windows.Forms.Button(); - this.pnlonline = new System.Windows.Forms.Panel(); - this.lbonlinedesc = new System.Windows.Forms.Label(); - this.lbonlineheader = new System.Windows.Forms.Label(); - this.lbonlineservers = new System.Windows.Forms.ListBox(); - this.btnjoinlobby = new System.Windows.Forms.Button(); this.panel1.SuspendLayout(); + this.pnlonline.SuspendLayout(); this.pnlmynet.SuspendLayout(); this.panel2.SuspendLayout(); - this.pnlonline.SuspendLayout(); this.SuspendLayout(); // // panel1 @@ -78,6 +78,75 @@ private void InitializeComponent() this.panel1.Size = new System.Drawing.Size(725, 495); this.panel1.TabIndex = 0; // + // pnlonline + // + this.pnlonline.Controls.Add(this.btnjoinlobby); + this.pnlonline.Controls.Add(this.lbonlineservers); + this.pnlonline.Controls.Add(this.lbonlinedesc); + this.pnlonline.Controls.Add(this.lbonlineheader); + this.pnlonline.Location = new System.Drawing.Point(12, 12); + this.pnlonline.Name = "pnlonline"; + this.pnlonline.Size = new System.Drawing.Size(404, 447); + this.pnlonline.TabIndex = 10; + // + // btnjoinlobby + // + this.btnjoinlobby.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnjoinlobby.Enabled = false; + this.btnjoinlobby.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnjoinlobby.Location = new System.Drawing.Point(306, 415); + this.btnjoinlobby.Name = "btnjoinlobby"; + this.btnjoinlobby.Size = new System.Drawing.Size(84, 23); + this.btnjoinlobby.TabIndex = 8; + this.btnjoinlobby.Text = "Join Lobby"; + this.btnjoinlobby.UseVisualStyleBackColor = true; + this.btnjoinlobby.Click += new System.EventHandler(this.btnjoinlobby_Click); + // + // lbonlineservers + // + this.lbonlineservers.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbonlineservers.BackColor = System.Drawing.Color.Black; + this.lbonlineservers.ForeColor = System.Drawing.Color.White; + this.lbonlineservers.FormattingEnabled = true; + this.lbonlineservers.Location = new System.Drawing.Point(1, 72); + this.lbonlineservers.Name = "lbonlineservers"; + this.lbonlineservers.Size = new System.Drawing.Size(389, 329); + this.lbonlineservers.TabIndex = 4; + this.lbonlineservers.SelectedIndexChanged += new System.EventHandler(this.lbonlineservers_SelectedIndexChanged); + // + // lbonlinedesc + // + this.lbonlinedesc.Location = new System.Drawing.Point(4, 37); + this.lbonlinedesc.Name = "lbonlinedesc"; + this.lbonlinedesc.Size = new System.Drawing.Size(386, 364); + this.lbonlinedesc.TabIndex = 3; + this.lbonlinedesc.Text = "You can battle other Shifters over the Internet by joining a lobby and waiting fo" + + "r a match to be made. Please select a server from the list below."; + // + // lbonlineheader + // + this.lbonlineheader.AutoSize = true; + this.lbonlineheader.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); + this.lbonlineheader.Location = new System.Drawing.Point(3, 5); + this.lbonlineheader.Name = "lbonlineheader"; + this.lbonlineheader.Size = new System.Drawing.Size(106, 20); + this.lbonlineheader.TabIndex = 2; + this.lbonlineheader.Text = "Online battles"; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button1.Location = new System.Drawing.Point(549, 465); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(83, 23); + this.button1.TabIndex = 9; + this.button1.Text = "Battle online!"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // // label3 // this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -258,75 +327,6 @@ private void InitializeComponent() this.tmrcalctotal.Enabled = true; this.tmrcalctotal.Tick += new System.EventHandler(this.tmrcalctotal_Tick); // - // button1 - // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.button1.Location = new System.Drawing.Point(549, 465); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(83, 23); - this.button1.TabIndex = 9; - this.button1.Text = "Battle online!"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // pnlonline - // - this.pnlonline.Controls.Add(this.btnjoinlobby); - this.pnlonline.Controls.Add(this.lbonlineservers); - this.pnlonline.Controls.Add(this.lbonlinedesc); - this.pnlonline.Controls.Add(this.lbonlineheader); - this.pnlonline.Location = new System.Drawing.Point(12, 12); - this.pnlonline.Name = "pnlonline"; - this.pnlonline.Size = new System.Drawing.Size(404, 447); - this.pnlonline.TabIndex = 10; - // - // lbonlinedesc - // - this.lbonlinedesc.Location = new System.Drawing.Point(4, 37); - this.lbonlinedesc.Name = "lbonlinedesc"; - this.lbonlinedesc.Size = new System.Drawing.Size(386, 364); - this.lbonlinedesc.TabIndex = 3; - this.lbonlinedesc.Text = "You can battle other Shifters over the Internet by joining a lobby and waiting fo" + - "r a match to be made. Please select a server from the list below."; - // - // lbonlineheader - // - this.lbonlineheader.AutoSize = true; - this.lbonlineheader.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); - this.lbonlineheader.Location = new System.Drawing.Point(3, 5); - this.lbonlineheader.Name = "lbonlineheader"; - this.lbonlineheader.Size = new System.Drawing.Size(106, 20); - this.lbonlineheader.TabIndex = 2; - this.lbonlineheader.Text = "Online battles"; - // - // lbonlineservers - // - this.lbonlineservers.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.lbonlineservers.BackColor = System.Drawing.Color.Black; - this.lbonlineservers.ForeColor = System.Drawing.Color.White; - this.lbonlineservers.FormattingEnabled = true; - this.lbonlineservers.Location = new System.Drawing.Point(1, 72); - this.lbonlineservers.Name = "lbonlineservers"; - this.lbonlineservers.Size = new System.Drawing.Size(389, 329); - this.lbonlineservers.TabIndex = 4; - this.lbonlineservers.SelectedIndexChanged += new System.EventHandler(this.lbonlineservers_SelectedIndexChanged); - // - // btnjoinlobby - // - this.btnjoinlobby.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnjoinlobby.Enabled = false; - this.btnjoinlobby.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnjoinlobby.Location = new System.Drawing.Point(306, 415); - this.btnjoinlobby.Name = "btnjoinlobby"; - this.btnjoinlobby.Size = new System.Drawing.Size(84, 23); - this.btnjoinlobby.TabIndex = 8; - this.btnjoinlobby.Text = "Join Lobby"; - this.btnjoinlobby.UseVisualStyleBackColor = true; - this.btnjoinlobby.Click += new System.EventHandler(this.btnjoinlobby_Click); - // // NetworkBrowser // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -337,15 +337,16 @@ private void InitializeComponent() this.ForeColor = System.Drawing.Color.Black; this.Name = "NetworkBrowser"; this.Text = "NetworkBrowser"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.stop_matchmake); this.Load += new System.EventHandler(this.NetworkBrowser_Load); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); + this.pnlonline.ResumeLayout(false); + this.pnlonline.PerformLayout(); this.pnlmynet.ResumeLayout(false); this.pnlmynet.PerformLayout(); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); - this.pnlonline.ResumeLayout(false); - this.pnlonline.PerformLayout(); this.ResumeLayout(false); } diff --git a/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs b/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs index e99e9a6..5223793 100644 --- a/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs +++ b/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs @@ -378,5 +378,13 @@ private void btnjoinlobby_Click(object sender, EventArgs e) Package_Grabber.SendMessage(selected_server.IPAddress, "join_lobby", API.CurrentSave.MyOnlineNetwork); Online.Hacking.Matchmaker.Matchmake(selected_server); } + + private void stop_matchmake(object sender, FormClosingEventArgs e) + { + if(selected_server != null) + { + Package_Grabber.SendMessage(selected_server.IPAddress, $"leave_lobby", API.CurrentSave.MyOnlineNetwork); + } + } } } diff --git a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs index 93aa8d9..aa673e4 100644 --- a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs +++ b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs @@ -74,6 +74,7 @@ public static void Matchmake(ServerInfo si) MakerTimer.Stop(); SelectedNetworkListener = new NetListener(si, SelectedNetwork); SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork); + Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby", API.CurrentSave.MyOnlineNetwork); } }; }