Server
 All Data Structures Files Functions Variables
Public Member Functions
communication::Lobby Class Reference

#include <Lobby.hpp>

Public Member Functions

 Lobby (const std::string &name, const std::string &startTime, Communicator &communicator, const Client &client, int id, util::Logging &log, const messages::broadcast::MatchConfig &matchConfig)
 
void addSpectator (const Client &client, int id)
 
auto reAddUser (const Client &client, int id) -> std::optional< int >
 
void onMessage (const messages::Message &message, int id)
 
void onLeave (int id)
 
auto getUserInLobby () const -> int
 
auto isMatchStarted () const -> bool
 
auto getName () const -> std::string
 

Detailed Description

Represents a single lobby and all relevant information

Constructor & Destructor Documentation

communication::Lobby::Lobby ( const std::string &  name,
const std::string &  startTime,
Communicator communicator,
const Client client,
int  id,
util::Logging &  log,
const messages::broadcast::MatchConfig &  matchConfig 
)

CTor: Initialize the Lobby, and add the first client.

Parameters
namethe name of the lobby
startTimethe timestamp of the message that started the lobby
communicatora reference to the communicator to send messages
clientthe first client in the lobby
idthe id of the client as send by the MessageHandler
logthe log in which to write
matchConfigthe matchConfig for the lobby

Member Function Documentation

void communication::Lobby::addSpectator ( const Client client,
int  id 
)

Add another spectator to the lobby, this player is always a spectator at first.

Parameters
clientthe client which should get added
idthe id of the player as send by the MessageHandler
auto communication::Lobby::getName ( ) const -> std::string

Get the name of the lobby

Returns
the name of the lobby
auto communication::Lobby::getUserInLobby ( ) const -> int

Get the number of users in the lobby

Returns
the number of users in the lobby
auto communication::Lobby::isMatchStarted ( ) const -> bool

Return if currently a game is active

Returns
wheter the game is actively running
void communication::Lobby::onLeave ( int  id)

An event that gets called when a client leaves

Parameters
idthe id of the player
Returns
true if the lobby is empty after the player left and thus if the lobby should be closed
void communication::Lobby::onMessage ( const messages::Message &  message,
int  id 
)

Function that gets called on a new message (except JoinRequest which are handled in the Communicator)

auto communication::Lobby::reAddUser ( const Client client,
int  id 
) -> std::optional< int >

Checks if a user with the same name and password is already in the lobby

Parameters
clientthe new client
idthe id of the new client
Returns
the old id if this is a rejoin

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