forked from lavina/lavina
1
0
Fork 0

handle stop connection cmd

This commit is contained in:
Nikita Vilunov 2024-04-29 01:39:29 +02:00
parent 9625120940
commit fdaf10660e
2 changed files with 29 additions and 15 deletions

View File

@ -507,15 +507,22 @@ async fn handle_registered_socket<'a>(
buffer.clear(); buffer.clear();
}, },
update = connection.receiver.recv() => { update = connection.receiver.recv() => {
if let Some(update) = update { match update {
Some(ConnectionMessage::Update(update)) => {
handle_update(&config, &user, &player_id, writer, &rooms, update).await?; handle_update(&config, &user, &player_id, writer, &rooms, update).await?;
} else { }
Some(ConnectionMessage::Stop(_)) => {
tracing::debug!("Connection is being terminated");
break;
}
None => {
log::warn!("Player is terminated, must terminate the connection"); log::warn!("Player is terminated, must terminate the connection");
break; break;
} }
} }
} }
} }
}
ServerMessage { ServerMessage {
tags: vec![], tags: vec![],
sender: Some(config.server_name.clone()), sender: Some(config.server_name.clone()),

View File

@ -23,7 +23,7 @@ use tokio_rustls::rustls::{Certificate, PrivateKey};
use tokio_rustls::TlsAcceptor; use tokio_rustls::TlsAcceptor;
use lavina_core::auth::{Authenticator, Verdict}; use lavina_core::auth::{Authenticator, Verdict};
use lavina_core::player::{PlayerConnection, PlayerId, PlayerRegistry}; use lavina_core::player::{ConnectionMessage, PlayerConnection, PlayerId, PlayerRegistry};
use lavina_core::prelude::*; use lavina_core::prelude::*;
use lavina_core::repo::Storage; use lavina_core::repo::Storage;
use lavina_core::room::RoomRegistry; use lavina_core::room::RoomRegistry;
@ -395,17 +395,24 @@ async fn socket_final(
true true
}, },
update = conn.user_handle.receiver.recv() => { update = conn.user_handle.receiver.recv() => {
if let Some(update) = update { match update {
Some(ConnectionMessage::Update(update)) => {
conn.handle_update(&mut events, update).await?; conn.handle_update(&mut events, update).await?;
for i in &events { for i in &events {
xml_writer.write_event_async(i).await?; xml_writer.write_event_async(i).await?;
} }
events.clear(); events.clear();
xml_writer.get_mut().flush().await?; xml_writer.get_mut().flush().await?;
} else { }
Some(ConnectionMessage::Stop(_)) => {
tracing::debug!("Connection is being terminated");
break;
}
None => {
log::warn!("Player is terminated, must terminate the connection"); log::warn!("Player is terminated, must terminate the connection");
break; break;
} }
}
false false
} }