SuperTuxKart
Loading...
Searching...
No Matches
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).
 
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 ,
  BLR_SERVER_ONWER_QUITED_THE_GAME = 4 , BLR_SPECTATING_NEXT_GAME = 5
}
 

Public Member Functions

virtual void setup ()=0
 A previous GameSetup is deleted and a new one is created.
 
virtual void update (int ticks)=0
 Called by the protocol listener, synchronously with the main loop.
 
virtual void finishedLoadingWorld ()=0
 
virtual void loadWorld ()
 Starts the sychronization protocol and the RaceEventManager.
 
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.
 
float getRemainingVotingTime ()
 Returns the remaining voting time in seconds.
 
bool isVotingOver ()
 Returns if the voting period is over.
 
float getMaxVotingTime ()
 Returns the maximum floating time in seconds.
 
GameSetupgetGameSetup () const
 Returns the game setup data structure.
 
int getNumberOfVotes () const
 Returns the number of votes received so far.
 
void addVote (uint32_t host_id, const PeerVote &vote)
 Adds a vote.
 
const PeerVotegetVote (uint32_t host_id) const
 Returns the voting data for one host.
 
void resetVotingTime ()
 
const std::map< uint32_t, PeerVote > & getAllVotes () const
 Returns all voting data.
 
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.
 
virtual ~Protocol ()
 Destructor.
 
virtual void setup ()=0
 Called when the protocol is going to start.
 
virtual void update (int ticks)=0
 Called by the protocol listener, synchronously with the main loop.
 
virtual void asynchronousUpdate ()=0
 Called by the protocol listener as often as possible.
 
NetworkStringgetNetworkString (size_t capacity=16) const
 functions to check incoming data easily
 
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.
 
void sendMessageToPeers (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in game, encrypt the message if needed.
 
void sendMessageToPeersInServer (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in server, encrypt the message if needed.
 
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.
 
virtual bool notifyEventAsynchronous (Event *event)
 Notify a protocol matching the Event type of that event.
 
ProtocolType getProtocolType () const
 Method to get a protocol's type.
 
void setHandleConnections (bool b)
 Sets if this protocol should receive connection events.
 
void setHandleDisconnections (bool b)
 Sets if this protocol should receive disconnection events.
 
virtual bool handleConnects () const
 Return true if this protocol should be informed about connects.
 
virtual bool handleDisconnects () const
 Return true if this protocol should be informed about disconnects.
 

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.
 
template<class T >
static std::shared_ptr< T > get ()
 Returns the singleton client or server lobby protocol.
 
template<class T >
static std::shared_ptr< T > getByType (ProcessType pt)
 Returns specific singleton client or server lobby protocol.
 

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
 
void exitGameState ()
 

Protected Attributes

const ProcessType m_process_type
 
std::map< uint32_t, PeerVotem_peers_votes
 Vote from each peer.
 
std::atomic< uint64_t > m_end_voting_period
 Timer user for voting periods in both lobbies.
 
uint64_t m_max_voting_time
 The maximum voting time.
 
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.
 
std::atomic< uint32_t > m_estimated_progress
 Estimated current started game progress in 0-100%, uint32_t max if not available.
 
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.
 
std::mutex m_current_track_mutex
 Mutex to protect m_current_track.
 
std::string m_current_track
 Store current playing track in name.
 
GameSetupm_game_setup
 Stores data about the online game to play.
 
- Protected Attributes inherited from Protocol
ProtocolType m_type
 The type of the protocol.
 
bool m_handle_connections
 True if this protocol should receive connection events.
 
bool m_handle_disconnections
 TRue if this protocol should recceiver disconnection events.
 

Static Protected Attributes

static std::weak_ptr< LobbyProtocolm_lobby [PT_COUNT]
 

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 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.

◆ finishedLoadingWorld()

virtual void LobbyProtocol::finishedLoadingWorld ( )
pure virtual

Implemented in ClientLobby, and ServerLobby.

◆ 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).

◆ 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 ClientLobby, and ServerLobby.

◆ 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 ClientLobby, and ServerLobby.

Member Data Documentation

◆ 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: