handle disconnect

This commit is contained in:
griffi-gh 2023-03-14 01:36:34 +01:00
parent 5d8f253c3c
commit 7251dacedc

View file

@ -134,6 +134,19 @@ fn check_server_hello_response(
} }
} }
fn handle_disconnect(
network_events: View<NetworkEvent>,
mut join_state: UniqueViewMut<ClientJoinState>
) {
for event in network_events.iter() {
if matches!(event.0, ClientEvent::Disconnect) {
log::warn!("Disconnected from server");
*join_state = ClientJoinState::Disconnected;
return;
}
}
}
pub fn update_networking() -> Workload { pub fn update_networking() -> Workload {
( (
connect_client.run_if_missing_unique::<UdpClient>(), connect_client.run_if_missing_unique::<UdpClient>(),
@ -143,8 +156,9 @@ pub fn update_networking() -> Workload {
say_hello, say_hello,
).into_sequential_workload().run_if(if_just_connected), ).into_sequential_workload().run_if(if_just_connected),
( (
check_server_hello_response check_server_hello_response,
).run_if(is_join_state::<{ClientJoinState::Connected as u8}>), handle_disconnect,
).into_sequential_workload().run_if(is_join_state::<{ClientJoinState::Connected as u8}>),
( (
recv_block_place_events recv_block_place_events
).run_if(is_join_state::<{ClientJoinState::Joined as u8}>).run_if(is_ingame_or_loading), ).run_if(is_join_state::<{ClientJoinState::Joined as u8}>).run_if(is_ingame_or_loading),