Struct SharedLobbyState

Source
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: LobbyId

Implementations§

Source§

impl SharedLobbyState

Source

pub async fn fight(&self) -> LockedLobbyState<'_>

Broadcasts a GAMESTATE, and does nothing beyond that, since the fight phase requires no user/client interaction.

Source§

impl SharedLobbyState

Source

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_choice value of Ok(_).
  • 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.

Source§

impl SharedLobbyState

Source

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 placement value of Ok(_), 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.

Source§

impl SharedLobbyState

Source

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.

Source

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.

Source§

impl SharedLobbyState

Source

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_choice value of Ok(_), where _ is one of the 3 unit types in hist_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.

Source§

impl SharedLobbyState

Source

pub fn new(lobby_state: LobbyState) -> Self

Source

pub async fn lock(&self) -> LockedLobbyState<'_>

Source

pub fn id(&self) -> LobbyId

Source

pub async fn remove_lobby_from_server(&self)

Trait Implementations§

Source§

impl Clone for SharedLobbyState

Source§

fn clone(&self) -> SharedLobbyState

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SharedLobbyState

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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