mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add disconnect handling
Former-commit-id: 24a9d535101f28debc0fe5a0600a32c9b744466f
This commit is contained in:
parent
7baecff1f0
commit
701755a8e2
@ -24,10 +24,11 @@ const SERVER_TIMEOUT: f64 = 20.0; // Seconds
|
||||
|
||||
pub enum Event {
|
||||
Chat(String),
|
||||
Disconnect,
|
||||
}
|
||||
|
||||
pub struct Client {
|
||||
client_state: ClientState,
|
||||
client_state: Option<ClientState>,
|
||||
thread_pool: ThreadPool,
|
||||
|
||||
last_ping: f64,
|
||||
@ -45,7 +46,7 @@ impl Client {
|
||||
/// Create a new `Client`.
|
||||
#[allow(dead_code)]
|
||||
pub fn new<A: Into<SocketAddr>>(addr: A, view_distance: u64) -> Result<Self, Error> {
|
||||
let mut client_state = ClientState::Connected;
|
||||
let mut client_state = Some(ClientState::Connected);
|
||||
let mut postbox = PostBox::to(addr)?;
|
||||
|
||||
// Wait for initial sync
|
||||
@ -259,13 +260,17 @@ impl Client {
|
||||
self.pending_chunks.remove(&key);
|
||||
}
|
||||
ServerMsg::StateAnswer(Ok(state)) => {
|
||||
self.client_state = state;
|
||||
self.client_state = Some(state);
|
||||
}
|
||||
ServerMsg::StateAnswer(Err((error, state))) => {
|
||||
self.client_state = state;
|
||||
self.client_state = Some(state);
|
||||
}
|
||||
ServerMsg::ForceState(state) => {
|
||||
self.client_state = state;
|
||||
self.client_state = Some(state);
|
||||
}
|
||||
ServerMsg::Disconnect => {
|
||||
self.client_state = None;
|
||||
frontend_events.push(Event::Disconnect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,5 +40,6 @@ pub enum ServerMsg {
|
||||
key: Vec3<i32>,
|
||||
chunk: Box<TerrainChunk>,
|
||||
},
|
||||
Disconnect,
|
||||
Shutdown,
|
||||
}
|
||||
|
@ -348,10 +348,7 @@ impl Server {
|
||||
|
||||
if disconnect {
|
||||
disconnected_clients.push(entity);
|
||||
client.postbox.send_message(ServerMsg::StateAnswer(Err((
|
||||
RequestStateError::Impossible,
|
||||
ClientState::Connected,
|
||||
))));
|
||||
client.postbox.send_message(ServerMsg::Disconnect);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -68,6 +68,9 @@ impl SessionState {
|
||||
client::Event::Chat(msg) => {
|
||||
self.hud.new_message(msg);
|
||||
}
|
||||
client::Event::Disconnect => {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user