Add network-layer multiplayer disconnect handling

This commit is contained in:
NG (Graham) committed 2026-01-07 21:09:38 -05:00
1 parent 1d0831d307
commit ac9e2a9fcd
10 files changed
+64 -18

No files matched your search

+4 -2
View File
@@ -1,14 +1,16 @@
pub struct LnlEventHandler {
event_handlers: std::collections::HashMap<i16, Box<dyn super::EventCodeHandler>>,
motion_handler: Box<dyn super::RobotMotionHandler>,
disconnect_handler: Box<dyn super::DisconnectHandler>,
user_provider: std::sync::Arc<oj_rc_core::persist::user::UserImpl>
}
impl LnlEventHandler {
pub fn new<M: super::RobotMotionHandler + 'static>(user_provider: std::sync::Arc<oj_rc_core::persist::user::UserImpl>, motion_handler: M) -> Self {
pub fn new<M: super::RobotMotionHandler + 'static, D: super::DisconnectHandler + 'static>(user_provider: std::sync::Arc<oj_rc_core::persist::user::UserImpl>, motion_handler: M, disconnect_handler: D) -> Self {
Self {
event_handlers: std::collections::HashMap::new(),
motion_handler: Box::new(motion_handler),
disconnect_handler: Box::new(disconnect_handler),
user_provider,
}
}
@@ -75,12 +77,12 @@ impl literustlib_server::EventHandler for LnlEventHandler {
}
async fn on_disconnect(&self, peer: &std::sync::Arc<literustlib_server::Connection<Self::PacketData>>, user: &Self::UserData) {
self.disconnect_handler.handle(peer, user).await;
if let Some(user_info) = user.user().await {
log::info!("Disconnect from user {} ({})", user_info.user_id(), peer.id());
} else {
log::debug!("Disconnect from connection {}", peer.id());
}
}
}