From 9ed191d9ae0f16449b9a707cf061b2c678b7d16d Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 10 Feb 2020 13:05:33 +1000 Subject: [PATCH] finish games when finishing idle instances --- core/src/game.rs | 2 +- server/src/warden.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/game.rs b/core/src/game.rs index cbeebe84..2ee6de59 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -804,7 +804,7 @@ impl Game { } } - fn finish(mut self) -> Game { + pub fn finish(mut self) -> Game { self.phase = Phase::Finished; // self.log.push(format!("Game finished.")); diff --git a/server/src/warden.rs b/server/src/warden.rs index 644e78db..33f6d712 100644 --- a/server/src/warden.rs +++ b/server/src/warden.rs @@ -13,6 +13,7 @@ use pg::{ PgPool, games_need_upkeep, + game_get, game_update, game_write, game_delete, @@ -157,6 +158,12 @@ fn fetch_instances(mut tx: Transaction) -> Result { } for mut instance in instances_idle(&mut tx)? { + if let Some(game_id) = instance.current_game_id() { + let mut game = game_get(&mut tx, game_id)?; + game = game.finish(); + game_update(&mut tx, &game)?; + } + instance.finish(); instance_update(&mut tx, instance)?; }