mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Janky fix of the logout timeout problem
This commit is contained in:
@ -222,7 +222,7 @@ impl Client {
|
|||||||
/// Send disconnect message to the server
|
/// Send disconnect message to the server
|
||||||
pub fn request_logout(&mut self) {
|
pub fn request_logout(&mut self) {
|
||||||
self.postbox.send_message(ClientMsg::Disconnect);
|
self.postbox.send_message(ClientMsg::Disconnect);
|
||||||
self.client_state = ClientState::Pending;
|
self.client_state = ClientState::Disconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request a state transition to `ClientState::Registered` from an ingame
|
/// Request a state transition to `ClientState::Registered` from an ingame
|
||||||
@ -722,6 +722,7 @@ impl Client {
|
|||||||
},
|
},
|
||||||
ServerMsg::Disconnect => {
|
ServerMsg::Disconnect => {
|
||||||
frontend_events.push(Event::Disconnect);
|
frontend_events.push(Event::Disconnect);
|
||||||
|
self.client_state = ClientState::Disconnected;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ pub enum ClientState {
|
|||||||
Registered,
|
Registered,
|
||||||
Spectator,
|
Spectator,
|
||||||
Character,
|
Character,
|
||||||
|
Disconnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const MAX_BYTES_CHAT_MSG: usize = 256;
|
pub const MAX_BYTES_CHAT_MSG: usize = 256;
|
||||||
|
@ -111,6 +111,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
server_emitter.emit(ServerEvent::ExitIngame { entity });
|
server_emitter.emit(ServerEvent::ExitIngame { entity });
|
||||||
},
|
},
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
// Request spectator state
|
// Request spectator state
|
||||||
ClientMsg::Spectate => match client.client_state {
|
ClientMsg::Spectate => match client.client_state {
|
||||||
@ -121,6 +122,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
client.allow_state(ClientState::Spectator)
|
client.allow_state(ClientState::Spectator)
|
||||||
},
|
},
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
// Request registered state (login)
|
// Request registered state (login)
|
||||||
ClientMsg::Register {
|
ClientMsg::Register {
|
||||||
@ -200,6 +202,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
},
|
},
|
||||||
ClientState::Character => client.error_state(RequestStateError::Already),
|
ClientState::Character => client.error_state(RequestStateError::Already),
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
ClientMsg::ControllerInputs(inputs) => match client.client_state {
|
ClientMsg::ControllerInputs(inputs) => match client.client_state {
|
||||||
ClientState::Connected
|
ClientState::Connected
|
||||||
@ -213,6 +216,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
ClientMsg::ControlEvent(event) => match client.client_state {
|
ClientMsg::ControlEvent(event) => match client.client_state {
|
||||||
ClientState::Connected
|
ClientState::Connected
|
||||||
@ -226,6 +230,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
ClientMsg::ChatMsg { message } => match client.client_state {
|
ClientMsg::ChatMsg { message } => match client.client_state {
|
||||||
ClientState::Connected => client.error_state(RequestStateError::Impossible),
|
ClientState::Connected => client.error_state(RequestStateError::Impossible),
|
||||||
@ -240,6 +245,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
ClientMsg::PlayerPhysics { pos, vel, ori } => match client.client_state {
|
ClientMsg::PlayerPhysics { pos, vel, ori } => match client.client_state {
|
||||||
ClientState::Character => {
|
ClientState::Character => {
|
||||||
@ -280,6 +286,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ClientState::Pending => {},
|
ClientState::Pending => {},
|
||||||
|
ClientState::Disconnected => unreachable!(),
|
||||||
},
|
},
|
||||||
// Always possible.
|
// Always possible.
|
||||||
ClientMsg::Ping => client.postbox.send_message(ServerMsg::Pong),
|
ClientMsg::Ping => client.postbox.send_message(ServerMsg::Pong),
|
||||||
|
@ -33,6 +33,14 @@ pub struct SessionState {
|
|||||||
selected_block: Block,
|
selected_block: Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The action to perform after a tick
|
||||||
|
enum TickAction {
|
||||||
|
// Continue executing
|
||||||
|
Continue,
|
||||||
|
// Disconnected (i.e. go to main menu)
|
||||||
|
Disconnect,
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents an active game session (i.e., the one being played).
|
/// Represents an active game session (i.e., the one being played).
|
||||||
impl SessionState {
|
impl SessionState {
|
||||||
/// Create a new `SessionState`.
|
/// Create a new `SessionState`.
|
||||||
@ -65,7 +73,7 @@ impl SessionState {
|
|||||||
|
|
||||||
impl SessionState {
|
impl SessionState {
|
||||||
/// Tick the session (and the client attached to it).
|
/// Tick the session (and the client attached to it).
|
||||||
fn tick(&mut self, dt: Duration) -> Result<(), Error> {
|
fn tick(&mut self, dt: Duration) -> Result<TickAction, Error> {
|
||||||
self.inputs.tick(dt);
|
self.inputs.tick(dt);
|
||||||
for event in self.client.borrow_mut().tick(
|
for event in self.client.borrow_mut().tick(
|
||||||
self.inputs.clone(),
|
self.inputs.clone(),
|
||||||
@ -79,7 +87,10 @@ impl SessionState {
|
|||||||
} => {
|
} => {
|
||||||
self.hud.new_message(event);
|
self.hud.new_message(event);
|
||||||
},
|
},
|
||||||
client::Event::Disconnect => {}, // TODO
|
client::Event::Disconnect => {
|
||||||
|
log::warn!("disconnect");
|
||||||
|
return Ok(TickAction::Disconnect);
|
||||||
|
},
|
||||||
client::Event::DisconnectionNotification(time) => {
|
client::Event::DisconnectionNotification(time) => {
|
||||||
let message = match time {
|
let message = match time {
|
||||||
0 => String::from("Goodbye!"),
|
0 => String::from("Goodbye!"),
|
||||||
@ -94,7 +105,7 @@ impl SessionState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(TickAction::Continue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clean up the session (and the client attached to it) after a tick.
|
/// Clean up the session (and the client attached to it) after a tick.
|
||||||
@ -390,12 +401,16 @@ impl PlayState for SessionState {
|
|||||||
|| !global_state.singleplayer.as_ref().unwrap().is_paused()
|
|| !global_state.singleplayer.as_ref().unwrap().is_paused()
|
||||||
{
|
{
|
||||||
// Perform an in-game tick.
|
// Perform an in-game tick.
|
||||||
if let Err(err) = self.tick(clock.get_avg_delta()) {
|
match self.tick(clock.get_avg_delta()) {
|
||||||
global_state.info_message =
|
Ok(TickAction::Continue) => {}, // Do nothing
|
||||||
Some(localized_strings.get("common.connection_lost").to_owned());
|
Ok(TickAction::Disconnect) => return PlayStateResult::Pop, // Go to main menu
|
||||||
error!("[session] Failed to tick the scene: {:?}", err);
|
Err(err) => {
|
||||||
|
global_state.info_message =
|
||||||
|
Some(localized_strings.get("common.connection_lost").to_owned());
|
||||||
|
error!("[session] Failed to tick the scene: {:?}", err);
|
||||||
|
|
||||||
return PlayStateResult::Pop;
|
return PlayStateResult::Pop;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user