From 31ec30c2efe61e861ffd521644b5f7590c5884b4 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 24 Apr 2024 20:46:44 +0200 Subject: [PATCH] player shutdown cmds --- crates/lavina-core/src/player.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/lavina-core/src/player.rs b/crates/lavina-core/src/player.rs index 2f5edb4..b205cd1 100644 --- a/crates/lavina-core/src/player.rs +++ b/crates/lavina-core/src/player.rs @@ -54,7 +54,7 @@ pub struct ConnectionId(pub AnonKey); /// The connection is used to send commands to the player actor and to receive updates that might be sent to the client. pub struct PlayerConnection { pub connection_id: ConnectionId, - pub receiver: Receiver, + pub receiver: Receiver, player_handle: PlayerHandle, } impl PlayerConnection { @@ -152,7 +152,7 @@ impl PlayerHandle { enum ActorCommand { /// Establish a new connection. AddConnection { - sender: Sender, + sender: Sender, promise: Promise, }, /// Terminate an existing connection. @@ -329,7 +329,7 @@ struct PlayerRegistryInner { struct Player { player_id: PlayerId, storage_id: u32, - connections: AnonTable>, + connections: AnonTable>, my_rooms: HashMap, banned_from: HashSet, rx: Receiver, @@ -413,7 +413,7 @@ impl Player { _ => {} } for (_, connection) in &self.connections { - let _ = connection.send(update.clone()).await; + let _ = connection.send(ConnectionMessage::Update(update.clone())).await; } } @@ -557,7 +557,17 @@ impl Player { if ConnectionId(a) == except { continue; } - let _ = b.send(update.clone()).await; + let _ = b.send(ConnectionMessage::Update(update.clone())).await; } } } + +pub enum ConnectionMessage { + Update(Updates), + Stop(StopReason), +} + +pub enum StopReason { + ServerShutdown, + InternalError, +}