mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-29 10:18:47 -06:00
disconnect on exit
This commit is contained in:
parent
6b55688dbd
commit
bda8e7b94c
|
@ -128,6 +128,12 @@ impl<S, R> Client<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_nonblocking(&mut self, is_nonblocking: bool) -> Result<()> {
|
||||||
|
self.socket.set_nonblocking(is_nonblocking)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_status(&self) -> ClientStatus {
|
pub fn get_status(&self) -> ClientStatus {
|
||||||
self.status
|
self.status
|
||||||
|
|
|
@ -75,7 +75,7 @@ use delta_time::{DeltaTime, init_delta_time};
|
||||||
use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now};
|
use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now};
|
||||||
use control_flow::{exit_on_esc, insert_control_flow_unique, SetControlFlow};
|
use control_flow::{exit_on_esc, insert_control_flow_unique, SetControlFlow};
|
||||||
use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state};
|
use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state};
|
||||||
use networking::{update_networking, is_multiplayer};
|
use networking::{update_networking, is_multiplayer, disconnect_on_exit};
|
||||||
use init::initialize_from_args;
|
use init::initialize_from_args;
|
||||||
use gui::{render_gui, init_gui, update_gui};
|
use gui::{render_gui, init_gui, update_gui};
|
||||||
use loading_screen::update_loading_screen;
|
use loading_screen::update_loading_screen;
|
||||||
|
@ -104,7 +104,7 @@ fn update() -> Workload {
|
||||||
update_window_size,
|
update_window_size,
|
||||||
update_cursor_lock_state,
|
update_cursor_lock_state,
|
||||||
process_inputs,
|
process_inputs,
|
||||||
exit_on_esc,
|
|
||||||
(
|
(
|
||||||
update_networking
|
update_networking
|
||||||
).into_workload().run_if(is_multiplayer),
|
).into_workload().run_if(is_multiplayer),
|
||||||
|
@ -124,6 +124,8 @@ fn update() -> Workload {
|
||||||
compute_cameras,
|
compute_cameras,
|
||||||
update_gui,
|
update_gui,
|
||||||
update_state,
|
update_state,
|
||||||
|
exit_on_esc,
|
||||||
|
disconnect_on_exit,
|
||||||
).into_workload()
|
).into_workload()
|
||||||
}
|
}
|
||||||
fn render() -> Workload {
|
fn render() -> Workload {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, WorkloadModificator, EntitiesView, EntitiesViewMut, Component, ViewMut, SystemModificator};
|
use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator};
|
||||||
|
use glium::glutin::event_loop::ControlFlow;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use kubi_udp::client::{Client, ClientConfig, ClientEvent};
|
use kubi_udp::client::{Client, ClientConfig, ClientEvent};
|
||||||
use kubi_shared::networking::{
|
use kubi_shared::networking::{
|
||||||
|
@ -6,7 +7,7 @@ use kubi_shared::networking::{
|
||||||
state::ClientJoinState
|
state::ClientJoinState
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::events::EventComponent;
|
use crate::{events::EventComponent, control_flow::SetControlFlow};
|
||||||
|
|
||||||
#[derive(Unique, Clone, Copy, PartialEq, Eq)]
|
#[derive(Unique, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum GameType {
|
pub enum GameType {
|
||||||
|
@ -73,6 +74,20 @@ pub fn update_networking() -> Workload {
|
||||||
).into_workload()
|
).into_workload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn disconnect_on_exit(
|
||||||
|
control_flow: UniqueView<SetControlFlow>,
|
||||||
|
mut client: UniqueViewMut<UdpClient>,
|
||||||
|
) {
|
||||||
|
if let Some(ControlFlow::ExitWithCode(_)) = control_flow.0 {
|
||||||
|
client.0.set_nonblocking(false).expect("Failed to switch socket to blocking mode");
|
||||||
|
if let Err(error) = client.0.disconnect() {
|
||||||
|
log::error!("failed to disconnect: {}", error);
|
||||||
|
} else {
|
||||||
|
log::info!("Client disconnected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_multiplayer(
|
pub fn is_multiplayer(
|
||||||
game_type: UniqueView<GameType>
|
game_type: UniqueView<GameType>
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue