group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
LobbyManager.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "network/Server.hpp"
8
9#include <chrono>
10#include <unordered_map>
11
17{
18public:
20 bool init(Server& serverPtr);
21
25 bool addPlayer(ClientId id, const char* displayName);
26
29 bool removePlayer(ClientId id);
30
33 bool setPlayerReadyStatus(ClientId id, bool ready);
34
40 bool hostStartMatch(ClientId sender);
41
43 [[nodiscard]] bool isHost(ClientId id) const { return id == hostId; }
44
46 void resetReadyStatuses();
47
49 [[nodiscard]] std::vector<ClientId> playerIds() const;
50
51private:
52 Server* server = nullptr;
53 std::vector<LobbyPlayer> players;
54 std::unordered_map<ClientId, std::chrono::steady_clock::time_point>
57
60
63};
Shared lobby data types exchanged between server and clients.
TCP game server that accepts clients and dispatches incoming packets.
Manages authoritative lobby state and broadcasts updates to connected clients.
Definition LobbyManager.hpp:17
void resetReadyStatuses()
Clear all ready flags and broadcast Unready events; resends full lobby state to every client.
Definition LobbyManager.cpp:147
std::unordered_map< ClientId, std::chrono::steady_clock::time_point > joinTimes
Join timestamps, used for host re-election.
Definition LobbyManager.hpp:55
void sendLobbyStateToAllPlayers()
Send a full LobbyState snapshot to every player in the roster.
Definition LobbyManager.cpp:160
bool isHost(ClientId id) const
True if id is the current lobby host.
Definition LobbyManager.hpp:43
ClientId assignNewHost()
Elect the longest-standing player as host and broadcast PlayerNewHost.
Definition LobbyManager.cpp:65
bool init(Server &serverPtr)
Bind the server reference used for all broadcasts.
Definition LobbyManager.cpp:13
bool hostStartMatch(ClientId sender)
Validate a host-initiated match start request.
Definition LobbyManager.cpp:114
bool setPlayerReadyStatus(ClientId id, bool ready)
Update a player's ready flag and broadcast the corresponding Ready/Unready event.
Definition LobbyManager.cpp:92
std::vector< ClientId > playerIds() const
Return current lobby player IDs.
Definition LobbyManager.cpp:167
ClientId hostId
ID of the current host; -1 if lobby is empty.
Definition LobbyManager.hpp:56
bool removePlayer(ClientId id)
Unregister a disconnected player, broadcast PlayerLeft, and reassign host if needed.
Definition LobbyManager.cpp:46
bool addPlayer(ClientId id, const char *displayName)
Register a newly connected player and broadcast a PlayerJoined event.
Definition LobbyManager.cpp:19
std::vector< LobbyPlayer > players
Current player roster.
Definition LobbyManager.hpp:53
TCP stream socket — receives client packets and echoes them back.
Definition Server.hpp:42
Definition LagCompMath.hpp:10
Associates an entity with a connected network client.
Definition ClientId.hpp:10