fix: prevent disconnected users from being added to tournamnets
This commit is contained in:
@@ -21,6 +21,8 @@ async def gameloop(socket):
|
||||
match message[0]:
|
||||
case "CONNECT":
|
||||
await socket.send("READY")
|
||||
case "RECONNECT":
|
||||
await socket.send("READY")
|
||||
|
||||
case "GAME":
|
||||
if message[1] == "START":
|
||||
|
||||
@@ -308,7 +308,9 @@ async fn handle_connection(
|
||||
if let Some(username) = sd.usernames.read().await.get(&addr).cloned() {
|
||||
let tournament_guard = sd.tournament.read().await;
|
||||
let client = sd.clients.read().await.get(&username).cloned().unwrap();
|
||||
let client = client.write().await;
|
||||
let mut client = client.write().await;
|
||||
client.ready = false;
|
||||
|
||||
if client.current_match.is_some() {
|
||||
let current_match = sd.matches.read().await.get(&client.current_match.unwrap()).cloned().unwrap();
|
||||
let current_match = current_match.read().await;
|
||||
|
||||
@@ -170,8 +170,6 @@ impl Server {
|
||||
client.addr = addr;
|
||||
client.connection = tx.clone();
|
||||
|
||||
let _ = send(&tx, "RECONNECT:ACK");
|
||||
|
||||
if let Some(current_match_id) = client.current_match {
|
||||
let matches_guard = self.matches.read().await;
|
||||
let the_match = matches_guard.get(¤t_match_id).unwrap().read().await;
|
||||
@@ -189,6 +187,15 @@ impl Server {
|
||||
// Clear they're state just in case, even if it's not terminated
|
||||
let _ = send(&tx, "GAME:TERMINATED");
|
||||
}
|
||||
|
||||
let tournament = self.tournament.read().await.as_ref().cloned();
|
||||
if let Some(tourney) = tournament {
|
||||
let tourney = tourney.read().await;
|
||||
if !tourney.contains_player(requested_username) {
|
||||
let _ = send(&tx, "RECONNECT:ACK");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return Err(anyhow::anyhow!(format!(
|
||||
"ERROR:INVALID:RECONNECT:{}",
|
||||
@@ -269,7 +276,8 @@ impl Server {
|
||||
let username = username.unwrap();
|
||||
|
||||
if clients_guard.get(&username).unwrap().read().await.ready {
|
||||
return Err(anyhow::anyhow!("ERROR:INVALID:READY"));
|
||||
let _ = send(&tx, "READY:ACK");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut client = clients_guard.get(&username).unwrap().write().await;
|
||||
|
||||
Reference in New Issue
Block a user