pub struct ServerHandle { /* private fields */ }Expand description
Handle to a running server.
Provides runtime control: shutdown, room management and state queries Rooms can be created and deleted at any time, new clients will see the updated room list, and existing clients in deleted rooms get errors on their next broadcast or join attempt.
Implementations§
Source§impl ServerHandle
impl ServerHandle
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Signal the server to stop accepting connections and disconnect all clients.
Sourcepub fn create_room(&self, id: &str) -> Result<()>
pub fn create_room(&self, id: &str) -> Result<()>
Create a room at runtime. Fails if the room already exists.
Sourcepub fn delete_room(&self, id: &str) -> bool
pub fn delete_room(&self, id: &str) -> bool
Delete a room at runtime. Returns true if the room existed.
Soft delete: connected clients are not kicked, but their next
broadcast or join will fail with a SyncError::RoomNotFound.
Sourcepub fn room_exists(&self, id: &str) -> bool
pub fn room_exists(&self, id: &str) -> bool
Check if a room exists.
Sourcepub fn room_count(&self) -> usize
pub fn room_count(&self) -> usize
Number of active rooms.
Sourcepub fn get_room_ids(&self) -> Vec<String>
pub fn get_room_ids(&self) -> Vec<String>
List all room IDs.
Sourcepub fn get_room_clients(&self, id: &str) -> Option<Vec<Uuid>>
pub fn get_room_clients(&self, id: &str) -> Option<Vec<Uuid>>
Client IDs in a room. Returns None if the room doesn’t exist.
Sourcepub fn room_client_count(&self, id: &str) -> Option<usize>
pub fn room_client_count(&self, id: &str) -> Option<usize>
Number of clients in a room. Returns None if the room doesn’t exist.
Sourcepub fn get_client_channel_len(
&self,
room_id: &str,
client_id: &Uuid,
) -> Option<usize>
pub fn get_client_channel_len( &self, room_id: &str, client_id: &Uuid, ) -> Option<usize>
Get the write channel queue length for a specific client in a room.
Returns None if the room doesn’t exist or the client is not in it.
Higher values indicate the client’s writer task is falling behind.
Sourcepub fn get_room_channel_lens(&self, room_id: &str) -> Option<Vec<(Uuid, usize)>>
pub fn get_room_channel_lens(&self, room_id: &str) -> Option<Vec<(Uuid, usize)>>
Get all clients’ write channel queue lengths in a room.
Returns None if the room doesn’t exist.
Each entry is (uuid, channel_len). Useful for monitoring backpressure.
Sourcepub fn set_room_meta<T: Any + Send + Sync + 'static>(
&self,
room_id: &str,
value: T,
) -> bool
pub fn set_room_meta<T: Any + Send + Sync + 'static>( &self, room_id: &str, value: T, ) -> bool
Store typed metadata on a room. Replaces any previous metadata.
Returns false if the room doesn’t exist.
Sourcepub fn with_room_meta<T: Any + Send + Sync + 'static, R>(
&self,
room_id: &str,
f: impl FnOnce(&T) -> R,
) -> Option<R>
pub fn with_room_meta<T: Any + Send + Sync + 'static, R>( &self, room_id: &str, f: impl FnOnce(&T) -> R, ) -> Option<R>
Read room metadata via a callback.
The callback receives &T if metadata is set and the type matches.
Returns None if the room doesn’t exist or has no metadata of type T.
This avoids needing Clone on your metadata type.
Sourcepub fn take_room_meta<T: Any + Send + Sync + 'static>(
&self,
room_id: &str,
) -> Option<T>
pub fn take_room_meta<T: Any + Send + Sync + 'static>( &self, room_id: &str, ) -> Option<T>
Remove and return room metadata, downcasted to T.
Returns None if the room doesn’t exist or has no metadata of type T.
Sourcepub fn room_has_meta(&self, room_id: &str) -> bool
pub fn room_has_meta(&self, room_id: &str) -> bool
Check if a room has metadata set.
Sourcepub fn set_client_meta<T: Any + Send + Sync + 'static>(
&self,
client_id: &Uuid,
value: T,
) -> bool
pub fn set_client_meta<T: Any + Send + Sync + 'static>( &self, client_id: &Uuid, value: T, ) -> bool
Store typed metadata on a connected client. Replaces any previous metadata.
Returns false if the client doesn’t exist.
Sourcepub fn with_client_meta<T: Any + Send + Sync + 'static, R>(
&self,
client_id: &Uuid,
f: impl FnOnce(&T) -> R,
) -> Option<R>
pub fn with_client_meta<T: Any + Send + Sync + 'static, R>( &self, client_id: &Uuid, f: impl FnOnce(&T) -> R, ) -> Option<R>
Read client metadata via a callback.
The callback receives &T if metadata is set and the type matches.
Returns None if the client doesn’t exist or has no metadata of type T.
Sourcepub fn take_client_meta<T: Any + Send + Sync + 'static>(
&self,
client_id: &Uuid,
) -> Option<T>
pub fn take_client_meta<T: Any + Send + Sync + 'static>( &self, client_id: &Uuid, ) -> Option<T>
Remove and return client metadata, downcasted to T.
Returns None if the client doesn’t exist or has no metadata of type T.
Sourcepub fn client_has_meta(&self, client_id: &Uuid) -> bool
pub fn client_has_meta(&self, client_id: &Uuid) -> bool
Check if a client has metadata set.
Sourcepub fn get_client_room(&self, client_id: Uuid) -> Option<String>
pub fn get_client_room(&self, client_id: Uuid) -> Option<String>
Room a client is currently in. Returns None if not in a room or not connected.
Sourcepub fn get_client_addr(&self, client_id: Uuid) -> Option<SocketAddr>
pub fn get_client_addr(&self, client_id: Uuid) -> Option<SocketAddr>
Remote address of a connected client.
Sourcepub fn get_client_count(&self) -> usize
pub fn get_client_count(&self) -> usize
Total number of connected clients.
Sourcepub fn kick_client(&self, client_id: &Uuid) -> bool
pub fn kick_client(&self, client_id: &Uuid) -> bool
Kick a client from their current room. Broadcasts PlayerLeft to other clients and calls the on_leave handler. The client connection will be closed by the server.