Struct ServerState

Source
pub struct ServerState {
    lobbies: HashMap<LobbyId, SharedLobbyState>,
    player_ids: HashMap<PlayerId, Result<LobbyId, Instant>>,
    reconnect_tokens: HashMap<ReconnectToken, Result<(LobbyId, PlayerId), Instant>>,
}

Fields§

§lobbies: HashMap<LobbyId, SharedLobbyState>§player_ids: HashMap<PlayerId, Result<LobbyId, Instant>>

Player IDs are globally unique, and each id represents a player in a lobby. When the lobby is closed, the id remains reserved for some time in case a client attempts to reconnect. In this state, the value is Err(time). Once now > time, i.e. time is in the past, a cleanup operation may free the reconnect token to prevent this map from growing infinitely large.

§reconnect_tokens: HashMap<ReconnectToken, Result<(LobbyId, PlayerId), Instant>>

Reconnect tokens are globally unique, and each token represents a player in a lobby. When the lobby is closed, the token remains reserved for some time in case a client attempts to reconnect. In this state, the value is Err(time). Once now > time, i.e. time is in the past, a cleanup operation may free the reconnect token to prevent this map from growing infinitely large. This is the same logic as in player_ids.

Implementations§

Source§

impl ServerState

Source

pub fn new(configs: BTreeMap<u64, ConfigSet>) -> Arc<SyncedServerState>

Source

fn new_internal( configs: BTreeMap<u64, ConfigSet>, spawn_task: bool, ) -> Arc<SyncedServerState>

Source

pub fn add_lobby( &mut self, conf: ConfigSet, shared_server_state: Arc<SyncedServerState>, spawn_task: bool, )

Creates a new lobby from a ConfigSet. Also starts the lobby task (see crate::lobby::game::run).

Source

pub async fn remove_lobby(&mut self, id: LobbyId)

Source

pub fn lobbies(&self) -> impl Iterator<Item = (&LobbyId, &SharedLobbyState)>

Source

pub fn lobby(&self, id: &LobbyId) -> Option<SharedLobbyState>

Source

pub fn gen_random_player_id_and_reconnect_token( &mut self, lobby_id: LobbyId, ) -> (PlayerId, ReconnectToken)

Source§

impl ServerState

Source

pub async fn cleanup(&mut self)

Trait Implementations§

Source§

impl Debug for ServerState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V