mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
dropping participant on client disconnect clients
This commit is contained in:
parent
8fb445b0e8
commit
9ae1d8474f
@ -42,7 +42,7 @@ use std::{
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use tracing::{debug, error, warn};
|
||||
use tracing::{debug, error, trace, warn};
|
||||
use uvth::{ThreadPool, ThreadPoolBuilder};
|
||||
use vek::*;
|
||||
|
||||
@ -312,10 +312,11 @@ impl Client {
|
||||
|
||||
/// Send disconnect message to the server
|
||||
pub fn request_logout(&mut self) {
|
||||
debug!("Requesting logout from server");
|
||||
if let Err(e) = self.singleton_stream.send(ClientMsg::Disconnect) {
|
||||
error!(
|
||||
?e,
|
||||
"couldn't send disconnect package to server, did server close already?"
|
||||
"Couldn't send disconnect package to server, did server close already?"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1191,11 +1192,12 @@ impl Client {
|
||||
|
||||
impl Drop for Client {
|
||||
fn drop(&mut self) {
|
||||
trace!("Dropping client");
|
||||
if let Err(e) = self.singleton_stream.send(ClientMsg::Disconnect) {
|
||||
warn!(
|
||||
"error during drop of client, couldn't send disconnect package, is the connection \
|
||||
already closed? : {}",
|
||||
e
|
||||
?e,
|
||||
"Error during drop of client, couldn't send disconnect package, is the connection \
|
||||
already closed?",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
use common::msg::{ClientState, RequestStateError, ServerMsg};
|
||||
use hashbrown::HashSet;
|
||||
use network::Stream;
|
||||
use network::{Participant, Stream};
|
||||
use specs::{Component, FlaggedStorage};
|
||||
use specs_idvs::IdvStorage;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use vek::*;
|
||||
|
||||
pub struct Client {
|
||||
pub client_state: ClientState,
|
||||
pub participant: Mutex<Option<Arc<Participant>>>,
|
||||
pub singleton_stream: Stream,
|
||||
pub last_ping: f64,
|
||||
pub login_msg_sent: bool,
|
||||
|
@ -8,8 +8,9 @@ use common::{
|
||||
msg::{ClientState, PlayerListUpdate, ServerMsg},
|
||||
sync::{Uid, UidAllocator},
|
||||
};
|
||||
use futures_executor::block_on;
|
||||
use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt};
|
||||
use tracing::error;
|
||||
use tracing::{debug, error, trace};
|
||||
|
||||
pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) {
|
||||
let state = server.state_mut();
|
||||
@ -46,6 +47,17 @@ pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) {
|
||||
}
|
||||
|
||||
pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event {
|
||||
if let Some(client) = server.state().read_storage::<Client>().get(entity) {
|
||||
trace!("closing participant of client");
|
||||
let participant = client.participant.lock().unwrap().take().unwrap();
|
||||
if let Err(e) = block_on(server.network.disconnect(participant)) {
|
||||
debug!(
|
||||
?e,
|
||||
"Error when disconnecting client, maybe the pipe already broke"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
let state = server.state_mut();
|
||||
|
||||
// Tell other clients to remove from player list
|
||||
|
@ -601,6 +601,7 @@ impl Server {
|
||||
|
||||
let mut client = Client {
|
||||
client_state: ClientState::Connected,
|
||||
participant: std::sync::Mutex::new(Some(participant)),
|
||||
singleton_stream,
|
||||
last_ping: self.state.get_time(),
|
||||
login_msg_sent: false,
|
||||
|
Loading…
Reference in New Issue
Block a user