SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ClientLobby Class Reference
Inheritance diagram for ClientLobby:
Inheritance graph
[legend]

Public Member Functions

 ClientLobby (std::shared_ptr< Server > s)
 The protocol that manages starting a race with the server.
 
void doneWithResults ()
 Called from the gui when a client clicked on 'continue' on the race result screen.
 
bool receivedServerResult ()
 
void startingRaceNow ()
 
const std::set< std::string > & getAvailableKarts () const
 
const std::set< std::string > & getAvailableTracks () const
 
virtual bool notifyEvent (Event *event) OVERRIDE
 Notify a protocol matching the Event type of that event.
 
virtual bool notifyEventAsynchronous (Event *event) OVERRIDE
 Notify a protocol matching the Event type of that event.
 
virtual void finishedLoadingWorld () OVERRIDE
 Callback when the world is loaded.
 
virtual void setup () OVERRIDE
 A previous GameSetup is deleted and a new one is created.
 
virtual void update (int ticks) OVERRIDE
 Called by the protocol listener, synchronously with the main loop.
 
virtual void asynchronousUpdate () OVERRIDE
 Called by the protocol listener as often as possible.
 
virtual bool allPlayersReady () const OVERRIDE
 
bool waitingForServerRespond () const
 
bool isLobbyReady () const
 
bool isWaitingForGame () const
 
bool isServerAutoGameTime () const
 
virtual bool isRacing () const OVERRIDE
 
void requestKartInfo (uint8_t kart_id)
 
void setSpectator (bool val)
 
bool isSpectator () const
 
void startLiveJoinKartSelection ()
 
void sendChat (irr::core::stringw text, KartTeam team)
 
const std::vector< LobbyPlayer > & getLobbyPlayers () const
 
bool isServerLiveJoinable () const
 
void changeSpectateTarget (PlayerAction action, int value, Input::InputType type) const
 
void addSpectateHelperMessage () const
 
bool serverEnabledChat () const
 
bool serverEnabledTrackVoting () const
 
bool serverEnabledReportPlayer () const
 
const std::vector< float > & getRankingChanges () const
 
void handleClientCommand (const std::string &cmd)
 
ClientState getCurrentState () const
 
std::shared_ptr< ServergetJoinedServer () const
 
void updateAssetsToServer ()
 
- Public Member Functions inherited from LobbyProtocol
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

static bool startedDownloadAddonsPack ()
 
static void downloadAddonsPack (std::shared_ptr< Online::HTTPRequest > r)
 
static void destroyBackgroundDownload ()
 
- Static Public Member Functions inherited from LobbyProtocol
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.
 

Private Types

enum  ClientState : unsigned int {
  NONE , LINKED , REQUESTING_CONNECTION , CONNECTED ,
  SELECTING_ASSETS , RACING , RACE_FINISHED , DONE ,
  EXITING
}
 

Private Member Functions

void disconnectedPlayer (Event *event)
 Called when a new player is disconnected.
 
void connectionAccepted (Event *event)
 Callback function on connection acceptation.
 
void connectionRefused (Event *event)
 Callback function on connection refusal.
 
void startGame (Event *event)
 Called when the server broadcasts to start the race to all clients.
 
void startSelection (Event *event)
 Called when the kart selection starts.
 
void raceFinished (Event *event)
 Called when all karts have finished the race.
 
void backToLobby (Event *event)
 Called when the server informs the clients to exit the race result screen.
 
void receivePlayerVote (Event *event)
 
void updatePlayerList (Event *event)
 
void handleChat (Event *event)
 
void handleServerInfo (Event *event)
 
void reportSuccess (Event *event)
 
void handleBadTeam ()
 
void handleBadConnection ()
 
void becomingServerOwner ()
 
void addAllPlayers (Event *event)
 
void finalizeConnectionRequest (NetworkString *header, BareNetworkString *rest, bool encrypt)
 
void liveJoinAcknowledged (Event *event)
 
void handleKartInfo (Event *event)
 
void finishLiveJoin ()
 
std::vector< std::shared_ptr< NetworkPlayerProfile > > decodePlayers (const BareNetworkString &data, std::shared_ptr< STKPeer > peer=nullptr, bool *is_spectator=NULL) const
 
void getPlayersAddonKartType (const BareNetworkString &data, std::vector< std::shared_ptr< NetworkPlayerProfile > > &players) const
 
void getKartsTracksNetworkString (BareNetworkString *ns)
 
void doInstallAddonsPack ()
 Called when the asynchronous download of the addon finished.
 

Private Attributes

std::shared_ptr< Serverm_server
 
bool m_waiting_for_game
 
bool m_server_auto_game_time
 
bool m_received_server_result
 
bool m_auto_started
 
bool m_first_connect
 
bool m_spectator
 
bool m_server_live_joinable
 
bool m_server_send_live_load_world
 
bool m_server_enabled_chat
 
bool m_server_enabled_track_voting
 
bool m_server_enabled_report_player
 
uint64_t m_auto_back_to_lobby_time
 
uint64_t m_start_live_game_time
 
std::atomic< ClientState > m_state
 The state of the finite state machine.
 
std::set< std::string > m_available_karts
 
std::set< std::string > m_available_tracks
 
std::map< PeerDisconnectInfo, irr::core::stringw > m_disconnected_msg
 
std::vector< LobbyPlayerm_lobby_players
 
std::vector< float > m_ranking_changes
 
irr::core::stringw m_total_players
 

Static Private Attributes

static std::thread m_background_download
 
static std::shared_ptr< Online::HTTPRequestm_download_request
 

Additional Inherited Members

- Public Types inherited from LobbyProtocol
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
}
 
- Protected Member Functions inherited from LobbyProtocol
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 inherited from LobbyProtocol
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 inherited from LobbyProtocol
static std::weak_ptr< LobbyProtocolm_lobby [PT_COUNT]
 

Constructor & Destructor Documentation

◆ ClientLobby()

ClientLobby::ClientLobby ( std::shared_ptr< Server s)

The protocol that manages starting a race with the server.

It uses a finite state machine:

dot_inline_dotgraph_1.png

Note that some states are actually managed outside of the client lobby. For example to select race details after selecting a kart is managed by the GUI engine.

Member Function Documentation

◆ allPlayersReady()

virtual bool ClientLobby::allPlayersReady ( ) const
inlinevirtual

Implements LobbyProtocol.

◆ asynchronousUpdate()

virtual void ClientLobby::asynchronousUpdate ( )
inlinevirtual

Called by the protocol listener as often as possible.

Must be re-defined.

Implements Protocol.

◆ backToLobby()

void ClientLobby::backToLobby ( Event event)
private

Called when the server informs the clients to exit the race result screen.

It exits the race, and goes back to the lobby.

◆ connectionAccepted()

void ClientLobby::connectionAccepted ( Event event)
private

Callback function on connection acceptation.

Called when the server accepts the connection.

Parameters
event: Event providing the information.

◆ connectionRefused()

void ClientLobby::connectionRefused ( Event event)
private

Callback function on connection refusal.

Called when the server refuses the connection.

Parameters
event: Event providing the information.

Format of the data :

Byte 0

Size | 1 |

Data | refusal code |

◆ disconnectedPlayer()

void ClientLobby::disconnectedPlayer ( Event event)
private

Called when a new player is disconnected.

Parameters
event: Event providing the information.

Format of the data :

Byte 0

Size | 1 |

Data | player id *|

◆ doneWithResults()

void ClientLobby::doneWithResults ( )

Called from the gui when a client clicked on 'continue' on the race result screen.

It notifies the server that this client has exited the screen and is back at the lobby.

◆ finishedLoadingWorld()

void ClientLobby::finishedLoadingWorld ( )
virtual

Callback when the world is loaded.

The client will inform the server that the players on this host are ready to start the race. It is called by the RaceManager after the world is loaded.

Implements LobbyProtocol.

◆ isRacing()

virtual bool ClientLobby::isRacing ( ) const
inlinevirtual

Implements LobbyProtocol.

◆ notifyEvent()

bool ClientLobby::notifyEvent ( Event event)
virtual

Notify a protocol matching the Event type of that event.

Parameters
event: Pointer to the event.
Returns
True if the event has been treated, false otherwise.

Reimplemented from Protocol.

◆ notifyEventAsynchronous()

bool ClientLobby::notifyEventAsynchronous ( Event event)
virtual

Notify a protocol matching the Event type of that event.

This update is done asynchronously :

Parameters
event: Pointer to the event.
Returns
True if the event has been treated, false otherwise

Reimplemented from Protocol.

◆ raceFinished()

void ClientLobby::raceFinished ( Event event)
private

Called when all karts have finished the race.

Parameters
event: Event providing the information.

Format of the data :

Byte 0 1

Size | 1 | 1 | |

Data | Kart 1 ID | kart id 2 | ... |

◆ setup()

void ClientLobby::setup ( )
virtual

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

Returns
Newly create GameSetup object.

Implements LobbyProtocol.

◆ startGame()

void ClientLobby::startGame ( Event event)
private

Called when the server broadcasts to start the race to all clients.

Parameters
event: Event providing the time the client should start game.

◆ startSelection()

void ClientLobby::startSelection ( Event event)
private

Called when the kart selection starts.

Parameters
event: Event providing the information (no additional information in this case).

◆ update()

void ClientLobby::update ( int  ticks)
virtual

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

Must be re-defined.

Implements LobbyProtocol.


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