ServerHandle

Struct ServerHandle 

Source
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

Source

pub async fn shutdown(&self)

Signal the server to stop accepting connections and disconnect all clients.

Source

pub fn create_room(&self, id: &str) -> Result<()>

Create a room at runtime. Fails if the room already exists.

Source

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.

Source

pub fn room_exists(&self, id: &str) -> bool

Check if a room exists.

Source

pub fn room_count(&self) -> usize

Number of active rooms.

Source

pub fn get_room_ids(&self) -> Vec<String>

List all room IDs.

Source

pub fn get_room_clients(&self, id: &str) -> Option<Vec<Uuid>>

Client IDs in a room. Returns None if the room doesn’t exist.

Source

pub fn room_client_count(&self, id: &str) -> Option<usize>

Number of clients in a room. Returns None if the room doesn’t exist.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn room_has_meta(&self, room_id: &str) -> bool

Check if a room has metadata set.

Source

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.

Source

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.

Source

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.

Source

pub fn client_has_meta(&self, client_id: &Uuid) -> bool

Check if a client has metadata set.

Source

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.

Source

pub fn get_client_addr(&self, client_id: Uuid) -> Option<SocketAddr>

Remote address of a connected client.

Source

pub fn get_client_count(&self) -> usize

Total number of connected clients.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.