diff --git a/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs b/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs index 1890744..4662cb8 100644 --- a/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs +++ b/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs @@ -395,13 +395,16 @@ private void btnjoinlobby_Click(object sender, EventArgs e) t.Tick += (o, a) => { SetupSidePane(Online.Hacking.Matchmaker.Players[sindex]); - if(sindex < Online.Hacking.Matchmaker.Players.Count - 1) + if (Matchmaker.Players.Count > 1) { - sindex = 0; - } - else - { - sindex += 1; + if (sindex < Online.Hacking.Matchmaker.Players.Count - 1) + { + sindex = 0; + } + else + { + sindex += 1; + } } }; t.Start(); diff --git a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs index fca22ac..733d060 100644 --- a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs +++ b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs @@ -65,18 +65,31 @@ public static void Matchmake(ServerInfo si) } }; Package_Grabber.SendMessage(si.IPAddress, "get_matchmaking"); + int index = 0; MakerTimer.Tick += (o, e) => { - int index = rnd.Next(0, Players.Count - 1); - if (Players[index] != API.CurrentSave.MyOnlineNetwork && Players[index].Name != null) + try { - SelectedNetwork = Players[index]; - MakerTimer.Stop(); - SelectedNetworkListener = new NetListener(si, SelectedNetwork); - SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork); - Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby", API.CurrentSave.MyOnlineNetwork); + if (Players[index] != API.CurrentSave.MyOnlineNetwork && Players[index].Name != null) + { + SelectedNetwork = Players[index]; + MakerTimer.Stop(); + SelectedNetworkListener = new NetListener(si, SelectedNetwork); + SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork); + Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby", API.CurrentSave.MyOnlineNetwork); + } + else + { + index += 1; + } + } + catch (Exception ex) + { + invoke(() => { API.CreateInfoboxSession("Cannot make a match.", "Network Browser had trouble making a match with another network. Error: " + ex.Message, infobox.InfoboxMode.Info); }); } }; + MakerTimer.Interval = 50; + MakerTimer.Start(); } @@ -186,6 +199,7 @@ public NetTransmitter(ServerInfo si, Network enemy) EnemyIdent = enemy.Name + ";" + enemy.Description; serverInfo = si; var h = new HackUI(this, Matchmaker.SelectedNetworkListener); + h.Show(); //HackUI will handle everything else to do with our network. }