pub struct SharedLobbyState(Arc<Mutex<LobbyState>>, LobbyId);Expand description
A shared, lockable reference to lobby state, shared between the lobby’s task and the server’s task.
Tuple Fields§
§0: Arc<Mutex<LobbyState>>§1: LobbyIdImplementations§
Sourcepub async fn fight(&self) -> LockedLobbyState<'_>
pub async fn fight(&self) -> LockedLobbyState<'_>
Broadcasts a GAMESTATE, and does nothing beyond that, since the fight phase requires no user/client interaction.
Sourcepub async fn lightsaber_purchase(&self) -> LockedLobbyState<'_>
pub async fn lightsaber_purchase(&self) -> LockedLobbyState<'_>
Sends the LIGHTSABER_OPTIONS message to all players,
then waits for up to timeout for the players to respond.
If they have not responded after timeout, a random
choice is made on their behalf.
It is guaranteed that, after this function completes,
- every living player has a
lightsaber_choicevalue ofOk(_). - the lightsaber options which were sent to clients are the last entry in
hist_lightsaber_options.
To ensure no race condition can break these conditions, the function returns a held lock to the lobby state with all the above guarantees upheld.
Sourcepub async fn placements(&self) -> LockedLobbyState<'_>
pub async fn placements(&self) -> LockedLobbyState<'_>
Waits for up to timeout for the players to respond.
If they have not responded after timeout, the previous
placement is kept without making any changes.
It is guaranteed that, after this function completes,
- every alive player has a
placementvalue ofOk(_), where_is a valid placement consisting of placed and banked units.
To ensure no race condition can break these conditions, the function returns a held lock to the lobby state with all the above guarantees upheld.
Sourcepub async fn wait_for_game_start(&self)
pub async fn wait_for_game_start(&self)
Waits for the game to be started if it has not started yet. If the game has been started already, returns immediately.
Sourcepub async fn start_game_after_timeout(&self, extend_timer: bool)
pub async fn start_game_after_timeout(&self, extend_timer: bool)
Waits for up to timeout (taken from the lobby’s config) for the game to be started.
If it has not started by then, it is started by force.
If a timer is already running and extend_timer is false, the game will start
when the previous timer ends.
If a timer is already running and extend_timer is true, the previous timer will
be ignored once it finishes, and a new timer is started.
This means that this function can take longer than timeout, if it is called a second
time with extend_timer being true.
Sourcepub async fn unit_purchase(&self, current_round: u64) -> LockedLobbyState<'_>
pub async fn unit_purchase(&self, current_round: u64) -> LockedLobbyState<'_>
Sends the UNIT_OPTIONS message to all players,
then waits for up to timeout for the players to respond.
If they have not responded after timeout, a random
choice is made on their behalf.
It is guaranteed that, after this function completes,
- every alive player has a
unit_choicevalue ofOk(_), where_is one of the 3 unit types inhist_unit_options.last(). - the unit options which were sent to clients are the last entry in
hist_unit_options.
To ensure no race condition can break these conditions, the function returns a held lock to the lobby state with all the above guarantees upheld.
pub fn new(lobby_state: LobbyState) -> Self
pub async fn lock(&self) -> LockedLobbyState<'_>
pub fn id(&self) -> LobbyId
pub async fn remove_lobby_from_server(&self)
Trait Implementations§
Source§fn clone(&self) -> SharedLobbyState
fn clone(&self) -> SharedLobbyState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more