Fix crash with phantom clients while matchmaking

This commit is contained in:
MichaelTheShifter 2016-06-26 07:46:56 -04:00
parent 2963b1bff2
commit a14470ce12
2 changed files with 41 additions and 1 deletions

View file

@ -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 = "<null>";
lbnetdesc.Text = @"<no description>
- 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)

View file

@ -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();