Manages authoritative lobby state and broadcasts updates to connected clients.
More...
#include <LobbyManager.hpp>
|
| 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.
|
|
| Server * | server = nullptr |
| | Authoritative server; not owned.
|
| std::vector< LobbyPlayer > | players |
| | 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.
|
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.
◆ 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.
◆ 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.
◆ resetReadyStatuses()
| void LobbyManager::resetReadyStatuses |
( |
| ) |
|
Clear all ready flags and broadcast Unready events; resends full lobby state to every client.
◆ sendLobbyStateToAllPlayers()
| void LobbyManager::sendLobbyStateToAllPlayers |
( |
| ) |
|
|
private |
Send a full LobbyState snapshot to every player in the roster.
◆ 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.
◆ hostId
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
◆ server
| Server* LobbyManager::server = nullptr |
|
private |
Authoritative server; not owned.
The documentation for this class was generated from the following files: