Browse Source

Fix server trying to match people with disconnected people

master
Stephen 1 month ago
parent
commit
f3159f2904
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      src/main.rs

+ 14
- 3
src/main.rs View File

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


Loading…
Cancel
Save