From f3159f29044407556e3567c1957e18a88a571777 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 11 Dec 2020 21:35:45 -0400 Subject: [PATCH] Fix server trying to match people with disconnected people --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e2b45ba..a144454 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,8 +102,12 @@ impl Shared { { let client = self.clients.get_mut(addr).unwrap(); client.partner = None; - client.send_status("Waiting for another person...".to_owned()).unwrap(); + if client.send_status("Waiting for another person...".to_owned()).is_err() { + // we aren't valid + return; + } } + match self.single { Some(x) => { if x == *addr { return; } // don't match with ourselves @@ -113,13 +117,20 @@ impl Shared { { let client = self.clients.get_mut(addr).unwrap(); client.partner = Some(x); - client.send_success(format!("You are now connected to {}.", their_username)).unwrap(); + if client.send_success(format!("You are now connected to {}.", their_username)).is_err() { + // we aren't valid + return; + } } { let partner = self.clients.get_mut(&x).unwrap(); partner.partner = Some(*addr); - partner.send_success(format!("You are now connected to {}.", our_username)).unwrap(); + if partner.send_success(format!("You are now connected to {}.", our_username)).is_err() { + // they aren't valid + self.single = Some(addr.to_owned()); + return; + } } self.single = None;