fix: trying to remove clients that are only observers

This commit is contained in:
2025-11-19 16:01:46 -05:00
Unverified
parent 14bee5e575
commit 71b422b898

View File

@@ -240,6 +240,8 @@ async fn handle_connection(
)
.await;
// TODO: add to ledger
// Check game end conditions
let (winner, filled) = {
let mut result = (Color::None, false);
@@ -394,6 +396,7 @@ async fn handle_connection(
Ok(match_id) => {
let result = watch(&matches, match_id, addr).await;
if result.is_err() { let _ = send(&tx, "ERROR:INVALID:WATCH"); }
// TODO: send ledger
}
Err(_) => { let _ = send(&tx, "ERROR:INVALID:WATCH"); }
}
@@ -505,6 +508,7 @@ async fn handle_connection(
// Remove and terminate any matches
// TODO: Support reconnecting behaviors
if clients.read().await.get(&addr).is_some() { // We may not be a client disconnecting
if let Some(match_id) = clients.read().await.get(&addr).unwrap().read().await.current_match {
let matches_guard = matches.read().await;
let clients_guard = clients.read().await;
@@ -526,11 +530,12 @@ async fn handle_connection(
matches.write().await.remove(&match_id);
}
let client = clients.write().await.remove(&addr).unwrap();
let username = client.read().await.username.clone();
observers.write().await.remove(&addr);
usernames.write().await.remove(&username);
} else {
observers.write().await.remove(&addr);
}
let mut admin_guard = admin.write().await;
if let Some(admin_addr) = *admin_guard {