diff --git a/crates/client/src/lan/game/game.rs b/crates/client/src/lan/game/game.rs index f9f22f7..4bdf04e 100644 --- a/crates/client/src/lan/game/game.rs +++ b/crates/client/src/lan/game/game.rs @@ -157,31 +157,6 @@ impl<'a> GameHandler<'a> { self.handle_game_packet(pkt).await?; } else { tracing::info!("game stream closed"); - if self.save_replay { - let game_info = flo_types::observer::GameInfo::from((&*self.info.game, self.game_version_string.clone())); - let packet_copy = self.saved_packets.clone(); - let mut user_replay_path = self.user_replay_path.clone(); - tokio::spawn(async move { - let now = chrono::Utc::now(); - let now_timestamp_str = format!("w3c-{}.w3g", now.format("%Y%m%d%H%M%S")); - user_replay_path.push_str(&now_timestamp_str); - let the_file = match std::fs::File::create(&user_replay_path) { - Ok(file) => Some(file), - Err(err) => { - tracing::error!("Could not open file: {}", err); - None - //return; - } - }; - if let Some(the_file) = the_file { - match generate_replay_from_packets(game_info, packet_copy, true, the_file).await { - Ok(_) => {}, - Err(err) => { tracing::error!("Could not generate replay because: {}", err); } - }; - } - Ok::<(), Error>(()) - }); - } return Ok(GameResult::Disconnected) } } @@ -210,6 +185,37 @@ impl<'a> GameHandler<'a> { } } + pub fn start_save_replay(&self) { + if self.save_replay { + let game_info = + flo_types::observer::GameInfo::from((&*self.info.game, self.game_version_string.clone())); + let packet_copy = self.saved_packets.clone(); + let mut user_replay_path = self.user_replay_path.clone(); + tokio::task::spawn(async move { + let now = chrono::Utc::now(); + let now_timestamp_str = format!("w3c-{}.w3g", now.format("%Y%m%d%H%M%S")); + user_replay_path.push_str(&now_timestamp_str); + let the_file = match std::fs::File::create(&user_replay_path) { + Ok(file) => Some(file), + Err(err) => { + tracing::error!("Could not open file: {}", err); + None + //return; + } + }; + if let Some(the_file) = the_file { + match generate_replay_from_packets(game_info, packet_copy, true, the_file).await { + Ok(_) => {} + Err(err) => { + tracing::error!("Could not generate replay because: {}", err); + } + }; + } + Ok::<(), Error>(()) + }); + } + } + #[inline] async fn handle_incoming_w3gs(&mut self, pkt: Packet) -> Result<()> { match pkt.type_id() { diff --git a/crates/client/src/lan/game/proxy.rs b/crates/client/src/lan/game/proxy.rs index b09ca01..18c81a8 100644 --- a/crates/client/src/lan/game/proxy.rs +++ b/crates/client/src/lan/game/proxy.rs @@ -304,7 +304,9 @@ impl State { guard.replace(GameEndReason::Unknown); } } + game_handler.start_save_replay(); stream.flush().await.ok(); + Ok(()) }