From a14470ce12c09a87665521387bee2f982cd5a6d0 Mon Sep 17 00:00:00 2001 From: MichaelTheShifter Date: Sun, 26 Jun 2016 07:46:56 -0400 Subject: [PATCH] Fix crash with phantom clients while matchmaking --- .../Apps/NetworkBrowser.cs | 40 +++++++++++++++++++ .../Online/Hacking/Matchmaker.cs | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs b/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs index 92c87cb..1890744 100644 --- a/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs +++ b/source/WindowsFormsApplication1/Apps/NetworkBrowser.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using ShiftOS.Online.Hacking; namespace ShiftOS { @@ -388,6 +389,45 @@ private void btnjoinlobby_Click(object sender, EventArgs e) API.CurrentSave.MyOnlineNetwork.Codepoints = API.Codepoints; Package_Grabber.SendMessage(selected_server.IPAddress, "join_lobby", API.CurrentSave.MyOnlineNetwork); Online.Hacking.Matchmaker.Matchmake(selected_server); + var t = new System.Windows.Forms.Timer(); + t.Interval = 5000; + int sindex = 0; + t.Tick += (o, a) => + { + SetupSidePane(Online.Hacking.Matchmaker.Players[sindex]); + if(sindex < Online.Hacking.Matchmaker.Players.Count - 1) + { + sindex = 0; + } + else + { + sindex += 1; + } + }; + t.Start(); + } + + private void SetupSidePane(Network network) + { + try + { + lbtitle.Text = network.Name; + lbnetdesc.Text = $@"{network.Description} + + - {network.Codepoints} codepoints. + - {network.Wins} wins, {network.Losses} losses."; + } + catch + { + lbtitle.Text = ""; + lbnetdesc.Text = @" + + - unknown codepoints. + - unknown wins, unknown losses. + + +If you see this happen, it's a phantom client. The server won't pair you with it."; + } } private void stop_matchmake(object sender, FormClosingEventArgs e) diff --git a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs index aa673e4..fca22ac 100644 --- a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs +++ b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs @@ -68,7 +68,7 @@ public static void Matchmake(ServerInfo si) MakerTimer.Tick += (o, e) => { int index = rnd.Next(0, Players.Count - 1); - if (Players[index] != API.CurrentSave.MyOnlineNetwork) + if (Players[index] != API.CurrentSave.MyOnlineNetwork && Players[index].Name != null) { SelectedNetwork = Players[index]; MakerTimer.Stop();