SuperTuxKart
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
LobbyProtocol Class Referenceabstract

Base class for both client and server lobby. The lobbies are started when a server opens a game, or when a client joins a game. It is used to exchange data about the race settings, like kart selection. More...

#include <lobby_protocol.hpp>

Inheritance diagram for LobbyProtocol:
Inheritance graph
[legend]

Public Types

enum  : uint8_t {
  LE_CONNECTION_REQUESTED = 1, LE_CONNECTION_REFUSED, LE_CONNECTION_ACCEPTED, LE_SERVER_INFO,
  LE_REQUEST_BEGIN, LE_UPDATE_PLAYER_LIST, LE_KART_SELECTION, LE_PLAYER_DISCONNECTED,
  LE_CLIENT_LOADED_WORLD, LE_LOAD_WORLD, LE_START_RACE, LE_START_SELECTION,
  LE_RACE_FINISHED, LE_RACE_FINISHED_ACK, LE_BACK_LOBBY, LE_VOTE,
  LE_CHAT, LE_SERVER_OWNERSHIP, LE_KICK_HOST, LE_CHANGE_TEAM,
  LE_BAD_TEAM, LE_BAD_CONNECTION, LE_CONFIG_SERVER, LE_CHANGE_HANDICAP,
  LE_LIVE_JOIN, LE_LIVE_JOIN_ACK, LE_KART_INFO, LE_CLIENT_BACK_LOBBY,
  LE_REPORT_PLAYER, LE_ASSETS_UPDATE, LE_COMMAND
}
 Lists all lobby events (LE). More...
 
enum  RejectReason : uint8_t {
  RR_BUSY = 0, RR_BANNED = 1, RR_INCORRECT_PASSWORD = 2, RR_INCOMPATIBLE_DATA = 3,
  RR_TOO_MANY_PLAYERS = 4, RR_INVALID_PLAYER = 5
}
 
enum  BackLobbyReason : uint8_t { BLR_NONE = 0, BLR_NO_GAME_FOR_LIVE_JOIN = 1, BLR_NO_PLACE_FOR_LIVE_JOIN = 2, BLR_ONE_PLAYER_IN_RANKED_MATCH = 3 }
 

Public Member Functions

virtual void setup ()=0
 A previous GameSetup is deleted and a new one is created. More...
 
virtual void update (int ticks)=0
 Called by the protocol listener, synchronously with the main loop. More...
 
virtual void finishedLoadingWorld ()=0
 
virtual void loadWorld ()
 Starts the sychronization protocol and the RaceEventManager. More...
 
virtual bool allPlayersReady () const =0
 
virtual bool isRacing () const =0
 
void startVotingPeriod (float max_time)
 Starts the voting period time with the specified maximum time. More...
 
float getRemainingVotingTime ()
 Returns the remaining voting time in seconds. More...
 
bool isVotingOver ()
 Returns if the voting period is over. More...
 
float getMaxVotingTime ()
 Returns the maximum floating time in seconds. More...
 
GameSetupgetGameSetup () const
 Returns the game setup data structure. More...
 
int getNumberOfVotes () const
 Returns the number of votes received so far. More...
 
void addVote (uint32_t host_id, const PeerVote &vote)
 Adds a vote. More...
 
const PeerVotegetVote (uint32_t host_id) const
 Returns the voting data for one host. More...
 
void resetVotingTime ()
 
const std::map< uint32_t, PeerVote > & getAllVotes () const
 Returns all voting data. More...
 
std::pair< uint32_t, uint32_t > getGameStartedProgress () const
 
void setGameStartedProgress (const std::pair< uint32_t, uint32_t > &p)
 
void resetGameStartedProgress ()
 
bool hasLiveJoiningRecently () const
 
void storePlayingTrack (const std::string &track_ident)
 
std::string getPlayingTrackIdent () const
 
TrackgetPlayingTrack () const
 
- Public Member Functions inherited from Protocol
 Protocol (ProtocolType type)
 Constructor Sets the basic protocol parameters, as the callback object and the protocol type. More...
 
virtual ~Protocol ()
 Destructor.
 
virtual void asynchronousUpdate ()=0
 Called by the protocol listener as often as possible. More...
 
NetworkStringgetNetworkString (size_t capacity=16) const
 functions to check incoming data easily More...
 
bool checkDataSize (Event *event, unsigned int minimum_size)
 Checks if the message has at least the specified size, and if not prints a warning message including the message content. More...
 
void sendMessageToPeers (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in game, encrypt the message if needed. More...
 
void sendMessageToPeersInServer (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in server, encrypt the message if needed. More...
 
void sendToServer (NetworkString *message, bool reliable=true)
 Sends a message from a client to the server.
 
virtual void requestStart ()
 Starts a request in the protocol manager to start this protocol.
 
virtual void requestTerminate ()
 Submits a request to the ProtocolManager to terminate this protocol.
 
virtual bool notifyEvent (Event *event)
 Notify a protocol matching the Event type of that event. More...
 
virtual bool notifyEventAsynchronous (Event *event)
 Notify a protocol matching the Event type of that event. More...
 
ProtocolType getProtocolType () const
 Method to get a protocol's type. More...
 
void setHandleConnections (bool b)
 Sets if this protocol should receive connection events. More...
 
void setHandleDisconnections (bool b)
 Sets if this protocol should receive disconnection events. More...
 
virtual bool handleConnects () const
 Return true if this protocol should be informed about connects. More...
 
virtual bool handleDisconnects () const
 Return true if this protocol should be informed about disconnects. More...
 

Static Public Member Functions

template<typename Singleton , typename... Types>
static std::shared_ptr< Singletoncreate (Types ...args)
 Creates either a client or server lobby protocol as a singleton. More...
 
template<class T >
static std::shared_ptr< T > get ()
 Returns the singleton client or server lobby protocol. More...
 

Protected Member Functions

void configRemoteKart (const std::vector< std::shared_ptr< NetworkPlayerProfile > > &players, int local_player_size) const
 
void joinStartGameThread ()
 
void addLiveJoiningKart (int kart_id, const RemoteKartInfo &rki, int live_join_util_ticks) const
 

Protected Attributes

std::map< uint32_t, PeerVotem_peers_votes
 Vote from each peer. More...
 
std::atomic< uint64_t > m_end_voting_period
 Timer user for voting periods in both lobbies. More...
 
uint64_t m_max_voting_time
 The maximum voting time. More...
 
std::thread m_start_game_thread
 
std::atomic< uint32_t > m_estimated_remaining_time
 Estimated current started game remaining time, uint32_t max if not available. More...
 
std::atomic< uint32_t > m_estimated_progress
 Estimated current started game progress in 0-100%, uint32_t max if not available. More...
 
int m_last_live_join_util_ticks
 Save the last live join ticks, for physical objects to update current transformation in server, and reset smooth network body in client. More...
 
std::mutex m_current_track_mutex
 Mutex to protect m_current_track. More...
 
std::string m_current_track
 Store current playing track in name. More...
 
GameSetupm_game_setup
 Stores data about the online game to play. More...
 
- Protected Attributes inherited from Protocol
ProtocolType m_type
 The type of the protocol. More...
 
bool m_handle_connections
 True if this protocol should receive connection events. More...
 
bool m_handle_disconnections
 TRue if this protocol should recceiver disconnection events. More...
 

Static Protected Attributes

static std::weak_ptr< LobbyProtocolm_lobby
 

Detailed Description

Base class for both client and server lobby. The lobbies are started when a server opens a game, or when a client joins a game. It is used to exchange data about the race settings, like kart selection.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : uint8_t

Lists all lobby events (LE).

Member Function Documentation

◆ addVote()

void LobbyProtocol::addVote ( uint32_t  host_id,
const PeerVote vote 
)

Adds a vote.

Parameters
host_idHost id of this vote.
voteThe vote to add.

◆ create()

template<typename Singleton , typename... Types>
static std::shared_ptr<Singleton> LobbyProtocol::create ( Types ...  args)
inlinestatic

Creates either a client or server lobby protocol as a singleton.

◆ get()

template<class T >
static std::shared_ptr<T> LobbyProtocol::get ( )
inlinestatic

Returns the singleton client or server lobby protocol.

◆ getAllVotes()

const std::map<uint32_t, PeerVote>& LobbyProtocol::getAllVotes ( ) const
inline

Returns all voting data.

◆ getGameSetup()

GameSetup* LobbyProtocol::getGameSetup ( ) const
inline

Returns the game setup data structure.

◆ getMaxVotingTime()

float LobbyProtocol::getMaxVotingTime ( )
inline

Returns the maximum floating time in seconds.

◆ getNumberOfVotes()

int LobbyProtocol::getNumberOfVotes ( ) const
inline

Returns the number of votes received so far.

◆ getRemainingVotingTime()

float LobbyProtocol::getRemainingVotingTime ( )

Returns the remaining voting time in seconds.

◆ getVote()

const PeerVote * LobbyProtocol::getVote ( uint32_t  host_id) const

Returns the voting data for one host.

Returns NULL if the vote from the given host id has not yet arrived (or if it is an invalid host id).

◆ isVotingOver()

bool LobbyProtocol::isVotingOver ( )

Returns if the voting period is over.

◆ loadWorld()

void LobbyProtocol::loadWorld ( )
virtual

Starts the sychronization protocol and the RaceEventManager.

It then sets the player structures up, creates the active player, and loads the world. This is called on the client when the server informs them that the world can be loaded (LE_LOAD_WORLD) and on the server in state LOAD_WORLD (i.e. just after informing all clients).

◆ setup()

void LobbyProtocol::setup ( )
pure virtual

A previous GameSetup is deleted and a new one is created.

Returns
Newly create GameSetup object.

Implements Protocol.

Implemented in ServerLobby, and ClientLobby.

◆ startVotingPeriod()

void LobbyProtocol::startVotingPeriod ( float  max_time)

Starts the voting period time with the specified maximum time.

Parameters
max_timeMaximum voting time in seconds

◆ update()

virtual void LobbyProtocol::update ( int  ticks)
pure virtual

Called by the protocol listener, synchronously with the main loop.

Must be re-defined.

Implements Protocol.

Implemented in ServerLobby, and ClientLobby.

Member Data Documentation

◆ m_current_track

std::string LobbyProtocol::m_current_track
protected

Store current playing track in name.

◆ m_current_track_mutex

std::mutex LobbyProtocol::m_current_track_mutex
mutableprotected

Mutex to protect m_current_track.

◆ m_end_voting_period

std::atomic<uint64_t> LobbyProtocol::m_end_voting_period
protected

Timer user for voting periods in both lobbies.

◆ m_estimated_progress

std::atomic<uint32_t> LobbyProtocol::m_estimated_progress
protected

Estimated current started game progress in 0-100%, uint32_t max if not available.

◆ m_estimated_remaining_time

std::atomic<uint32_t> LobbyProtocol::m_estimated_remaining_time
protected

Estimated current started game remaining time, uint32_t max if not available.

◆ m_game_setup

GameSetup* LobbyProtocol::m_game_setup
protected

Stores data about the online game to play.

◆ m_last_live_join_util_ticks

int LobbyProtocol::m_last_live_join_util_ticks
protected

Save the last live join ticks, for physical objects to update current transformation in server, and reset smooth network body in client.

◆ m_max_voting_time

uint64_t LobbyProtocol::m_max_voting_time
protected

The maximum voting time.

◆ m_peers_votes

std::map<uint32_t, PeerVote> LobbyProtocol::m_peers_votes
protected

Vote from each peer.

The host id is used as a key. Note that host ids can be non-consecutive, so we cannot use std::vector.


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