From fdaf10660e8373e46f4554c6cc82152fe5eedf46 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Mon, 29 Apr 2024 01:39:29 +0200 Subject: [PATCH] handle stop connection cmd --- crates/projection-irc/src/lib.rs | 17 ++++++++++++----- crates/projection-xmpp/src/lib.rs | 27 +++++++++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/crates/projection-irc/src/lib.rs b/crates/projection-irc/src/lib.rs index a320c5d..2a310a1 100644 --- a/crates/projection-irc/src/lib.rs +++ b/crates/projection-irc/src/lib.rs @@ -507,11 +507,18 @@ async fn handle_registered_socket<'a>( buffer.clear(); }, update = connection.receiver.recv() => { - if let Some(update) = update { - handle_update(&config, &user, &player_id, writer, &rooms, update).await?; - } else { - log::warn!("Player is terminated, must terminate the connection"); - break; + match update { + Some(ConnectionMessage::Update(update)) => { + handle_update(&config, &user, &player_id, writer, &rooms, update).await?; + } + Some(ConnectionMessage::Stop(_)) => { + tracing::debug!("Connection is being terminated"); + break; + } + None => { + log::warn!("Player is terminated, must terminate the connection"); + break; + } } } } diff --git a/crates/projection-xmpp/src/lib.rs b/crates/projection-xmpp/src/lib.rs index fe56481..04826bc 100644 --- a/crates/projection-xmpp/src/lib.rs +++ b/crates/projection-xmpp/src/lib.rs @@ -23,7 +23,7 @@ use tokio_rustls::rustls::{Certificate, PrivateKey}; use tokio_rustls::TlsAcceptor; 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::repo::Storage; use lavina_core::room::RoomRegistry; @@ -395,16 +395,23 @@ async fn socket_final( true }, update = conn.user_handle.receiver.recv() => { - if let Some(update) = update { - conn.handle_update(&mut events, update).await?; - for i in &events { - xml_writer.write_event_async(i).await?; + match update { + Some(ConnectionMessage::Update(update)) => { + conn.handle_update(&mut events, update).await?; + for i in &events { + xml_writer.write_event_async(i).await?; + } + events.clear(); + xml_writer.get_mut().flush().await?; + } + Some(ConnectionMessage::Stop(_)) => { + tracing::debug!("Connection is being terminated"); + break; + } + None => { + log::warn!("Player is terminated, must terminate the connection"); + break; } - events.clear(); - xml_writer.get_mut().flush().await?; - } else { - log::warn!("Player is terminated, must terminate the connection"); - break; } false }