R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
server::Lobby Class Reference

Main lobby where players connect before joining rooms. More...

#include <Lobby.hpp>

Collaboration diagram for server::Lobby:
Collaboration graph

Public Member Functions

 Lobby (std::shared_ptr< RoomManager > roomManager)
 Construct a lobby.
 
 ~Lobby ()=default
 
bool addPlayer (uint32_t playerId, const std::string &playerName)
 Add a player to the lobby.
 
bool removePlayer (uint32_t playerId)
 Remove a player from the lobby.
 
bool updatePlayerName (uint32_t playerId, const std::string &newName)
 Update a player's display name.
 
const LobbyPlayergetPlayer (uint32_t playerId) const
 Get player info.
 
std::vector< LobbyPlayergetAllPlayers () const
 Get all players in lobby.
 
size_t getPlayerCount () const
 Get number of players in lobby.
 
bool startMatchmaking (uint32_t playerId)
 Start matchmaking for a player.
 
bool cancelMatchmaking (uint32_t playerId)
 Cancel matchmaking for a player.
 
bool joinRoom (uint32_t playerId, const std::string &roomId)
 Join a specific room by ID.
 
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)
 
std::shared_ptr< RoomManagergetRoomManager () const
 Get room manager.
 

Private Attributes

std::unordered_map< uint32_t, LobbyPlayer_players
 
std::shared_ptr< RoomManager_roomManager
 
std::mutex _mutex
 

Static Private Attributes

static std::atomic< uint64_t > _nextRoomId {1}
 

Detailed Description

Main lobby where players connect before joining rooms.

Features:

  • Player registration/deregistration
  • Room discovery (list available rooms)
  • Matchmaking integration
  • Ready system for manual rooms

Definition at line 43 of file Lobby.hpp.

Constructor & Destructor Documentation

◆ Lobby()

server::Lobby::Lobby ( std::shared_ptr< RoomManager roomManager)
explicit

Construct a lobby.

Parameters
roomManagerShared pointer to room manager

Definition at line 17 of file Lobby.cpp.

References LOG_INFO.

◆ ~Lobby()

server::Lobby::~Lobby ( )
default

Member Function Documentation

◆ addPlayer()

bool server::Lobby::addPlayer ( uint32_t  playerId,
const std::string &  playerName 
)

Add a player to the lobby.

Parameters
playerIdPlayer ID
playerNamePlayer display name
Returns
true if player was added

Definition at line 21 of file Lobby.cpp.

References _mutex, _players, server::LobbyPlayer::inMatchmaking, server::LobbyPlayer::isReady, LOG_INFO, LOG_WARNING, server::LobbyPlayer::playerId, and server::LobbyPlayer::playerName.

◆ cancelMatchmaking()

bool server::Lobby::cancelMatchmaking ( uint32_t  playerId)

Cancel matchmaking for a player.

Parameters
playerIdPlayer ID
Returns
true if matchmaking cancelled

Definition at line 127 of file Lobby.cpp.

References _mutex, _players, _roomManager, and LOG_INFO.

◆ createCustomRoom()

std::string server::Lobby::createCustomRoom ( uint32_t  hostPlayerId,
const std::string &  roomName,
size_t  maxPlayers,
bool  isPrivate 
)

Create a custom room.

Parameters
hostPlayerIdHost player ID
roomNameRoom display name
maxPlayersMaximum players
isPrivateWhether room is private
Returns
Room ID if created, empty string otherwise

Definition at line 176 of file Lobby.cpp.

References _mutex, _nextRoomId, _players, _roomManager, LOG_ERROR, LOG_INFO, and LOG_WARNING.

◆ getAllPlayers()

std::vector< LobbyPlayer > server::Lobby::getAllPlayers ( ) const

Get all players in lobby.

Returns
Vector of lobby players

Definition at line 83 of file Lobby.cpp.

References _mutex, and _players.

◆ getPlayer()

const LobbyPlayer * server::Lobby::getPlayer ( uint32_t  playerId) const

Get player info.

Parameters
playerIdPlayer ID
Returns
Pointer to LobbyPlayer (nullptr if not found)

Definition at line 72 of file Lobby.cpp.

References _mutex, and _players.

◆ getPlayerCount()

size_t server::Lobby::getPlayerCount ( ) const

Get number of players in lobby.

Returns
Player count

Definition at line 96 of file Lobby.cpp.

References _mutex, and _players.

◆ getRoomManager()

std::shared_ptr< RoomManager > server::Lobby::getRoomManager ( ) const
inline

Get room manager.

Returns
Shared pointer to room manager

Definition at line 138 of file Lobby.hpp.

References _roomManager.

◆ joinRoom()

bool server::Lobby::joinRoom ( uint32_t  playerId,
const std::string &  roomId 
)

Join a specific room by ID.

Parameters
playerIdPlayer ID
roomIdRoom identifier
Returns
true if player joined room

Definition at line 148 of file Lobby.cpp.

References _mutex, _players, _roomManager, LOG_ERROR, LOG_INFO, and LOG_WARNING.

◆ removePlayer()

bool server::Lobby::removePlayer ( uint32_t  playerId)

Remove a player from the lobby.

Parameters
playerIdPlayer ID
Returns
true if player was removed

Definition at line 40 of file Lobby.cpp.

References _mutex, _players, _roomManager, and LOG_INFO.

◆ setPlayerReady()

void server::Lobby::setPlayerReady ( uint32_t  playerId,
bool  ready 
)

Set player ready status (for custom rooms)

Parameters
playerIdPlayer ID
readyReady status

Definition at line 211 of file Lobby.cpp.

References _mutex, _players, and LOG_INFO.

◆ startMatchmaking()

bool server::Lobby::startMatchmaking ( uint32_t  playerId)

Start matchmaking for a player.

Parameters
playerIdPlayer ID
Returns
true if matchmaking started

Definition at line 101 of file Lobby.cpp.

References _mutex, _players, _roomManager, LOG_ERROR, LOG_INFO, and LOG_WARNING.

◆ updatePlayerName()

bool server::Lobby::updatePlayerName ( uint32_t  playerId,
const std::string &  newName 
)

Update a player's display name.

Parameters
playerIdPlayer ID
newNameNew display name
Returns
true if player name was updated

Definition at line 57 of file Lobby.cpp.

References _mutex, _players, LOG_INFO, and LOG_WARNING.

Member Data Documentation

◆ _mutex

std::mutex server::Lobby::_mutex
mutableprivate

◆ _nextRoomId

std::atomic< uint64_t > server::Lobby::_nextRoomId {1}
staticprivate

Definition at line 146 of file Lobby.hpp.

Referenced by createCustomRoom().

◆ _players

std::unordered_map<uint32_t, LobbyPlayer> server::Lobby::_players
private

◆ _roomManager

std::shared_ptr<RoomManager> server::Lobby::_roomManager
private

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