From faf54dc3ae4aac6ddaadea13c8c610305d6bf710 Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 9 Sep 2019 16:46:26 +1000 Subject: [PATCH] game finished find round --- server/src/instance.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/instance.rs b/server/src/instance.rs index 57bc00aa..d6a76c7a 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -384,14 +384,14 @@ impl Instance { fn game_finished(&mut self, game: &Game) -> Result<&mut Instance, Error> { { let current_round = self.rounds - .last_mut() - .expect("instance does not have any rounds"); + .iter_mut() + .filter(|r| r.game_id.is_some()) + .find(|r| r.game_id.unwrap() == game.id); - if current_round.game_id.unwrap() != game.id { - return Err(err_msg("instance does not have a round for this game")); - } - - current_round.finished = true; + match current_round { + Some(c) => c.finished = true, + None => return Err(err_msg("instance does not have a round for this game")), + }; } // if you don't win, you lose