diff --git a/TODO.md b/TODO.md index 4cde1f5..4910e4f 100644 --- a/TODO.md +++ b/TODO.md @@ -26,7 +26,7 @@ - [x] Lobby tests - [x] Game end test for actual return from loop - [x] More transport crate tests - - [ ] Signaling is wrong, only kick everyone else on host leave if the lobby is open + - [x] Signaling is wrong, only kick everyone else on host leave if the lobby is open - [x] Organize signalling and seperate out more logic - [x] Signaling tests - [ ] Testing crate for integration testing? diff --git a/manhunt-signaling/src/state.rs b/manhunt-signaling/src/state.rs index 7ff7732..be20336 100644 --- a/manhunt-signaling/src/state.rs +++ b/manhunt-signaling/src/state.rs @@ -223,7 +223,7 @@ impl ServerState { .unwrap_or_default(); if host { - if let Some(mat) = matches.get_mut(&removed_peer.room) { + if let Some(mat) = matches.get_mut(&removed_peer.room).filter(|m| m.open_lobby) { // If we're host, disconnect everyone else mat.open_lobby = false; mat.cancel.cancel(); @@ -461,6 +461,26 @@ mod tests { assert!(!mat.open_lobby); } + #[test] + fn test_host_leave_with_players_but_started() { + let mut state = ServerState::default(); + + let code = "asdfasdfasdfasdf"; + + quick_create(&mut state, code, 1); + quick_join(&mut state, code, 2); + + state.mark_started(&code.to_string()); + + let others = state.remove_peer(peer(1), true); + + assert_eq!(others, Some(vec![peer(2)])); + let matches = state.matches.lock().unwrap(); + let mat = &matches[&code.to_string()]; + assert!(!mat.cancel.is_cancelled()); + assert!(!mat.open_lobby); + } + #[test] fn test_join_no_match() { let mut state = ServerState::default();