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
impl ServerState
pub fn new(configs: BTreeMap<u64, ConfigSet>) -> Arc<SyncedServerState>
fn new_internal( configs: BTreeMap<u64, ConfigSet>, spawn_task: bool, ) -> Arc<SyncedServerState>
Sourcepub fn add_lobby(
&mut self,
conf: ConfigSet,
shared_server_state: Arc<SyncedServerState>,
spawn_task: bool,
)
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).