Skip to content

Commit

Permalink
Make sure Reforged is responsive before sending CountDownEnd.
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxu committed Nov 4, 2024
1 parent 1234f52 commit 45a0f34
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion binaries/flo-cli/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>, ob: Option<i32>, node_id: Option<i32>) -> Result<i32> {
if players.is_empty() && ob.is_none() {
Expand Down
36 changes: 33 additions & 3 deletions crates/client/src/lan/game/lobby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 45a0f34

Please sign in to comment.