Skip to content

Commit

Permalink
Multiplayer: Solve NAT for game servers (#619)
Browse files Browse the repository at this point in the history
Previously, the initial Joined message was never received when the client was behind a NAT. That resulted in the multiplayer being indefinitely stuck in the Connected state.
  • Loading branch information
Indy2222 authored Jul 9, 2023
1 parent 005d062 commit bc8e9f8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/multiplayer/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn open_or_join(
fn process_from_server(
mut ports: ResMut<Ports>,
mut events: EventReader<FromMainServerEvent>,
mut outputs: EventWriter<ToGameServerEvent<true>>,
mut fatals: EventWriter<FatalErrorEvent>,
) {
for event in events.iter() {
Expand All @@ -83,6 +84,8 @@ fn process_from_server(
FromServer::GameOpened { port } => match ports.init_game_port(*port) {
Ok(_) => {
info!("Game on port {} opened.", *port);
// Send something to open NAT.
outputs.send(ToGame::Ping(u32::MAX).into());
}
Err(err) => {
fatals.send(FatalErrorEvent::new(format!("Invalid GameOpened: {err:?}")));
Expand Down

0 comments on commit bc8e9f8

Please sign in to comment.