17 Lobby::Lobby(std::shared_ptr<RoomManager> roomManager) : _roomManager(roomManager) {
22 std::lock_guard<std::mutex> lock(
_mutex);
25 LOG_WARNING(
"Player ", playerId,
" already in lobby");
36 LOG_INFO(
"✓ Player '", playerName,
"' (", playerId,
") joined lobby (",
_players.size(),
" players)");
41 std::lock_guard<std::mutex> lock(
_mutex);
53 LOG_INFO(
"✓ Player ", playerId,
" left lobby (",
_players.size(),
" players remaining)");
58 std::lock_guard<std::mutex> lock(
_mutex);
62 LOG_WARNING(
"Cannot update name - player ", playerId,
" not in lobby");
66 std::string oldName = it->second.playerName;
67 it->second.playerName = newName;
68 LOG_INFO(
"✓ Player ", playerId,
" name updated: '", oldName,
"' → '", newName,
"'");
73 std::lock_guard<std::mutex> lock(
_mutex);
84 std::lock_guard<std::mutex> lock(
_mutex);
86 std::vector<LobbyPlayer> players;
89 for (
const auto &[
id, player] :
_players) {
90 players.push_back(player);
97 std::lock_guard<std::mutex> lock(
_mutex);
102 std::lock_guard<std::mutex> lock(
_mutex);
106 LOG_WARNING(
"Cannot start matchmaking - player ", playerId,
" not in lobby");
110 if (it->second.inMatchmaking) {
111 LOG_WARNING(
"Player ", playerId,
" already in matchmaking");
116 LOG_ERROR(
"Cannot start matchmaking - room manager not initialized");
120 it->second.inMatchmaking =
true;
123 LOG_INFO(
"✓ Player ", playerId,
" started matchmaking");
128 std::lock_guard<std::mutex> lock(
_mutex);
135 if (!it->second.inMatchmaking) {
143 it->second.inMatchmaking =
false;
144 LOG_INFO(
"✓ Player ", playerId,
" cancelled matchmaking");
149 std::lock_guard<std::mutex> lock(
_mutex);
151 auto playerIt =
_players.find(playerId);
153 LOG_WARNING(
"Cannot join room - player ", playerId,
" not in lobby");
158 LOG_ERROR(
"Cannot join room - room manager not initialized");
164 LOG_WARNING(
"Cannot join room - room '", roomId,
"' not found");
168 if (room->join(playerId)) {
169 LOG_INFO(
"✓ Player ", playerId,
" joined room '", roomId,
"'");
178 std::lock_guard<std::mutex> lock(
_mutex);
180 auto playerIt =
_players.find(hostPlayerId);
182 LOG_WARNING(
"Cannot create room - player ", hostPlayerId,
" not in lobby");
187 LOG_ERROR(
"Cannot create room - room manager not initialized");
192 uint64_t roomNumber =
_nextRoomId.fetch_add(1, std::memory_order_relaxed);
193 std::string roomId =
"custom_" + std::to_string(hostPlayerId) +
"_" + std::to_string(roomNumber);
195 auto room =
_roomManager->createRoom(roomId, roomName, maxPlayers, isPrivate);
197 LOG_ERROR(
"Failed to create custom room");
201 if (room->join(hostPlayerId)) {
202 room->setHost(hostPlayerId);
203 LOG_INFO(
"✓ Player ", hostPlayerId,
" created custom room '", roomName,
"' (", roomId,
")");
212 std::lock_guard<std::mutex> lock(
_mutex);
216 it->second.isReady = ready;
217 LOG_INFO(
"Player ", playerId,
" ready status: ", (ready ?
"ready" :
"not ready"));
bool updatePlayerName(uint32_t playerId, const std::string &newName)
Update a player's display name.
bool startMatchmaking(uint32_t playerId)
Start matchmaking for a player.
bool joinRoom(uint32_t playerId, const std::string &roomId)
Join a specific room by ID.
std::shared_ptr< RoomManager > _roomManager
std::vector< LobbyPlayer > getAllPlayers() const
Get all players in lobby.
bool addPlayer(uint32_t playerId, const std::string &playerName)
Add a player to the lobby.
std::string createCustomRoom(uint32_t hostPlayerId, const std::string &roomName, size_t maxPlayers, bool isPrivate)
Create a custom room.
void setPlayerReady(uint32_t playerId, bool ready)
Set player ready status (for custom rooms)
size_t getPlayerCount() const
Get number of players in lobby.
std::unordered_map< uint32_t, LobbyPlayer > _players
bool cancelMatchmaking(uint32_t playerId)
Cancel matchmaking for a player.
static std::atomic< uint64_t > _nextRoomId
const LobbyPlayer * getPlayer(uint32_t playerId) const
Get player info.
Lobby(std::shared_ptr< RoomManager > roomManager)
Construct a lobby.
bool removePlayer(uint32_t playerId)
Remove a player from the lobby.
Information about a player in the lobby.