Skip to content

Commit

Permalink
Fix double controller disconnect messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxu committed Dec 9, 2023
1 parent 485e06a commit 58c8171
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions crates/client/src/controller/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ impl ControllerStream {
))
.await?;

let mut disconnect_handled = false;

loop {
tokio::select! {
next_send = frame_receiver.recv() => {
Expand Down Expand Up @@ -190,6 +192,10 @@ impl ControllerStream {
tracing::error!("handle frame: {}", e);
}
}

if frame.type_id == PacketTypeId::LobbyDisconnect {
disconnect_handled = true;
}
},
Err(e) => {
tracing::debug!("exiting: recv: {}", e);
Expand All @@ -200,15 +206,17 @@ impl ControllerStream {
}
}

parent
.notify(SendWs::new(
id,
OutgoingMessage::Disconnect(messages::Disconnect {
reason: messages::DisconnectReason::Unknown,
message: "Server connection closed".to_string(),
}),
))
.await?;
if !disconnect_handled {
parent
.notify(SendWs::new(
id,
OutgoingMessage::Disconnect(messages::Disconnect {
reason: messages::DisconnectReason::Unknown,
message: "Server connection closed".to_string(),
}),
))
.await?;
}

parent
.notify(ControllerEventData::Disconnected.wrap(id))
Expand Down

0 comments on commit 58c8171

Please sign in to comment.