group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
LobbyManager Class Reference

Manages authoritative lobby state and broadcasts updates to connected clients. More...

#include <LobbyManager.hpp>

Collaboration diagram for LobbyManager:
[legend]

Public Member Functions

bool init (Server &serverPtr)
 Bind the server reference used for all broadcasts.
bool addPlayer (ClientId id)
 Register a newly connected player and broadcast a PlayerJoined event.
bool removePlayer (ClientId id)
 Unregister a disconnected player, broadcast PlayerLeft, and reassign host if needed.
bool setPlayerReadyStatus (ClientId id, bool ready)
 Update a player's ready flag and broadcast the corresponding Ready/Unready event.
bool hostStartMatch (ClientId sender)
 Validate a host-initiated match start request.
void resetReadyStatuses ()
 Clear all ready flags and broadcast Unready events; resends full lobby state to every client.

Private Member Functions

ClientId assignNewHost ()
 Elect the longest-standing player as host and broadcast PlayerNewHost.
void sendLobbyStateToAllPlayers ()
 Send a full LobbyState snapshot to every player in the roster.

Private Attributes

Serverserver = nullptr
 Authoritative server; not owned.
std::vector< LobbyPlayerplayers
 Current player roster.
std::unordered_map< ClientId, std::chrono::steady_clock::time_point > joinTimes
 Join timestamps, used for host re-election.
ClientId hostId {-1}
 ID of the current host; -1 if lobby is empty.

Detailed Description

Manages authoritative lobby state and broadcasts updates to connected clients.

Tracks the player roster, host assignment, and ready statuses. All mutating operations broadcast the appropriate LobbyUpdateEvent via the Server.

Member Function Documentation

◆ addPlayer()

bool LobbyManager::addPlayer ( ClientId id)

Register a newly connected player and broadcast a PlayerJoined event.

Returns
False if the player was already present.

◆ assignNewHost()

ClientId LobbyManager::assignNewHost ( )
private

Elect the longest-standing player as host and broadcast PlayerNewHost.

Here is the caller graph for this function:

◆ hostStartMatch()

bool LobbyManager::hostStartMatch ( ClientId sender)

Validate a host-initiated match start request.

Rejects if sender is not the host, any non-host player is unready, or no non-host players are connected.

Returns
True if the match may proceed.

◆ init()

bool LobbyManager::init ( Server & serverPtr)

Bind the server reference used for all broadcasts.

◆ removePlayer()

bool LobbyManager::removePlayer ( ClientId id)

Unregister a disconnected player, broadcast PlayerLeft, and reassign host if needed.

Returns
False if the player was not found.
Here is the call graph for this function:

◆ resetReadyStatuses()

void LobbyManager::resetReadyStatuses ( )

Clear all ready flags and broadcast Unready events; resends full lobby state to every client.

Here is the call graph for this function:

◆ sendLobbyStateToAllPlayers()

void LobbyManager::sendLobbyStateToAllPlayers ( )
private

Send a full LobbyState snapshot to every player in the roster.

Here is the caller graph for this function:

◆ setPlayerReadyStatus()

bool LobbyManager::setPlayerReadyStatus ( ClientId id,
bool ready )

Update a player's ready flag and broadcast the corresponding Ready/Unready event.

Returns
False if the player was not found.

Member Data Documentation

◆ hostId

ClientId LobbyManager::hostId {-1}
private

ID of the current host; -1 if lobby is empty.

◆ joinTimes

std::unordered_map<ClientId, std::chrono::steady_clock::time_point> LobbyManager::joinTimes
private

Join timestamps, used for host re-election.

◆ players

std::vector<LobbyPlayer> LobbyManager::players
private

Current player roster.

◆ server

Server* LobbyManager::server = nullptr
private

Authoritative server; not owned.


The documentation for this class was generated from the following files: