diff --git a/binaries/flo-cli/src/game.rs b/binaries/flo-cli/src/game.rs index cb87f81..05726dd 100644 --- a/binaries/flo-cli/src/game.rs +++ b/binaries/flo-cli/src/game.rs @@ -3,7 +3,7 @@ use crate::Result; use flo_grpc::controller::*; use flo_grpc::game::*; -const MAP: &str = r#"maps\Northern_Isles-WH_EternalStrife_Jan2024.w3x"#; +const MAP: &str = r#"maps\(2)bootybay.w3m"#; pub async fn create_game(players: Vec, ob: Option, node_id: Option) -> Result { if players.is_empty() && ob.is_none() { diff --git a/crates/client/src/lan/game/lobby.rs b/crates/client/src/lan/game/lobby.rs index 61cfb46..0747bcc 100644 --- a/crates/client/src/lan/game/lobby.rs +++ b/crates/client/src/lan/game/lobby.rs @@ -147,13 +147,42 @@ impl<'a> LobbyHandler<'a> { return Ok(()); } self.starting = true; - self.stream.send(Packet::simple(self.info.slot_info.slot_info.clone() as flo_w3gs::protocol::slot::SlotInfo)?).await?; + self + .stream + .send(Packet::simple( + self.info.slot_info.slot_info.clone() as flo_w3gs::protocol::slot::SlotInfo + )?) + .await?; self.stream.send(Packet::simple(CountDownStart)?).await?; + + self.ping_and_await_pong().await?; sleep(Duration::from_secs(6)).await; + self.ping_and_await_pong().await?; + self.stream.send(Packet::simple(CountDownEnd)?).await?; Ok(()) } + async fn ping_and_await_pong(&mut self) -> Result<()> { + self + .stream + .send(Packet::simple(PingFromHost::with_payload(0xFFFFFFFF))?) + .await?; + self.stream.flush().await?; + + while let Some(pkt) = self.stream.recv().await? { + if let PongToHost::PACKET_TYPE_ID = pkt.type_id() { + let payload: PongToHost = pkt.decode_simple()?; + if payload.payload() == 0xFFFFFFFF { + break; + } + } else { + return Err(Error::UnexpectedW3GSPacket(pkt)); + } + } + Ok(()) + } + async fn handle_packet( &mut self, state: &mut JoinPacketRecvState, @@ -188,8 +217,9 @@ impl<'a> LobbyHandler<'a> { slot_info.slot_info.random_seed ); - replies.push(Packet::simple(slot_info.slot_info.clone() as flo_w3gs::protocol::slot::SlotInfo)?); - + replies.push(Packet::simple( + slot_info.slot_info.clone() as flo_w3gs::protocol::slot::SlotInfo + )?); let mut player_info_packets = Vec::with_capacity(num_players); let mut player_skin_packets = Vec::with_capacity(num_players);