SuperTuxKart
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
ServerLobby Class Reference
Inheritance diagram for ServerLobby:
Inheritance graph
[legend]

Classes

struct  KeyData
 

Public Types

enum  ServerState : unsigned int {
  SET_PUBLIC_ADDRESS , REGISTER_SELF_ADDRESS , WAITING_FOR_START_GAME , SELECTING ,
  LOAD_WORLD , WAIT_FOR_WORLD_LOADED , WAIT_FOR_RACE_STARTED , RACING ,
  WAIT_FOR_RACE_STOPPED , RESULT_DISPLAY , ERROR_LEAVE , EXITING
}
 
- 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
}
 

Public Member Functions

 ServerLobby ()
 This is the central game setup protocol running in the server. More...
 
virtual ~ServerLobby ()
 Destructor.
 
virtual bool notifyEventAsynchronous (Event *event) OVERRIDE
 Notify a protocol matching the Event type of that event. More...
 
virtual bool notifyEvent (Event *event) OVERRIDE
 Notify a protocol matching the Event type of that event. More...
 
virtual void setup () OVERRIDE
 A previous GameSetup is deleted and a new one is created. More...
 
virtual void update (int ticks) OVERRIDE
 Simple finite state machine. More...
 
virtual void asynchronousUpdate () OVERRIDE
 Find out the public IP server or poll STK server asynchronously.
 
void updatePlayerList (bool update_when_reset_server=false)
 Called when any players change their setting (team for example), or connection / disconnection, it will use the game_started parameter to determine if this should be send to all peers in server or just in game. More...
 
void startSelection (const Event *event=NULL)
 Instructs all clients to start the kart selection. More...
 
void checkIncomingConnectionRequests ()
 Query the STK server for connection requests. More...
 
void finishedLoadingWorld () OVERRIDE
 Called from the RaceManager of the server when the world is loaded. More...
 
ServerState getCurrentState () const
 
void updateBanList ()
 
bool waitingForPlayers () const
 
virtual bool allPlayersReady () const OVERRIDE
 
virtual bool isRacing () const OVERRIDE
 
bool allowJoinedPlayersWaiting () const
 
void setSaveServerConfig (bool val)
 
float getStartupBoostOrPenaltyForKart (uint32_t ping, unsigned kart_id)
 
int getDifficulty () const
 
int getGameMode () const
 
int getLobbyPlayers () const
 
void saveInitialItems (std::shared_ptr< NetworkItemManager > nim)
 
void saveIPBanTable (const SocketAddress &addr)
 
void listBanTable ()
 
void initServerStatsTable ()
 
bool isAIProfile (const std::shared_ptr< NetworkPlayerProfile > &npp) const
 
uint32_t getServerIdOnline () const
 
uint32_t getClientServerHostId () const
 
void setClientServerHostId (uint32_t id)
 
bool playerReportsTableExists () const
 
GameSetupgetGameSetup ()
 
ProcessType getProcessType ()
 
- Public Member Functions inherited from LobbyProtocol
virtual void loadWorld ()
 Starts the sychronization protocol and the RaceEventManager. More...
 
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.
 
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. 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.
 
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.
 
bool checkDataSize (Event *event, unsigned int minimum_size)
 functions to check incoming data easily 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.
 
ProtocolType getProtocolType () const
 Method to get a protocol's type. More...
 
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.
 

Public Attributes

std::weak_ptr< STKPeerm_server_owner
 Hold the next connected peer for server owner if current one expired (disconnected).
 
std::pair< std::set< std::string >, std::set< std::string > > m_official_kts
 Official karts and tracks available in server.
 
std::pair< std::set< std::string >, std::set< std::string > > m_addon_kts
 Addon karts and tracks available in server.
 
std::set< std::string > m_addon_arenas
 Addon arenas available in server.
 
std::set< std::string > m_addon_soccers
 Addon soccers available in server.
 
std::map< std::weak_ptr< STKPeer >, std::set< irr::core::stringw >, std::owner_less< std::weak_ptr< STKPeer > > > m_peers_muted_players
 

Static Public Attributes

static int m_fixed_laps = -1
 

Private Types

enum  ResetState : unsigned int { RS_NONE , RS_WAITING , RS_ASYNC_RESET }
 

Private Member Functions

void clientDisconnected (Event *event)
 Called when a client disconnects. More...
 
void connectionRequested (Event *event)
 
void kartSelectionRequested (Event *event)
 Called when a player asks to select karts. More...
 
void handlePlayerVote (Event *event)
 Called when a player votes for track(s), it will auto correct client data if it sends some invalid data. More...
 
void playerFinishedResult (Event *event)
 Called when a client clicks on 'ok' on the race result screen. More...
 
void registerServer (bool first_time)
 Register this server (i.e. More...
 
void finishedLoadingWorldClient (Event *event)
 Called when a client notifies the server that it has loaded the world. More...
 
void finishedLoadingLiveJoinClient (Event *event)
 Finally put the kart in the world and inform client the current world status, (including current confirmed item state, kart scores...)
 
void kickHost (Event *event)
 
void changeTeam (Event *event)
 
void handleChat (Event *event)
 
void unregisterServer (bool now, std::weak_ptr< ServerLobby > sl=std::weak_ptr< ServerLobby >())
 Unregister this server (i.e. More...
 
void updateServerOwner ()
 
void handleServerConfiguration (Event *event)
 Called when the server owner request to change game mode or difficulty. More...
 
void updateTracksForMode ()
 Called whenever server is reset or game mode is changed.
 
bool checkPeersReady (bool ignore_ai_peer) const
 
void resetPeersReady ()
 
void addPeerConnection (const std::string &addr_str)
 
void removeExpiredPeerConnection ()
 
void replaceKeys (std::map< uint32_t, KeyData > &new_keys)
 
void handlePendingConnection ()
 
void handleUnencryptedConnection (std::shared_ptr< STKPeer > peer, BareNetworkString &data, uint32_t online_id, const irr::core::stringw &online_name, bool is_pending_connection, std::string country_code="")
 
bool decryptConnectionRequest (std::shared_ptr< STKPeer > peer, BareNetworkString &data, const std::string &key, const std::string &iv, uint32_t online_id, const irr::core::stringw &online_name, const std::string &country_code)
 
bool handleAllVotes (PeerVote *winner, uint32_t *winner_peer_id)
 Select the track to be used based on all votes being received. More...
 
template<typename T >
void findMajorityValue (const std::map< T, unsigned > &choices, unsigned cur_players, T *best_choice, float *rate)
 
void getRankingForPlayer (std::shared_ptr< NetworkPlayerProfile > p)
 
void submitRankingsToAddons ()
 
void computeNewRankings ()
 Compute the new player's rankings used in ranked servers.
 
void checkRaceFinished ()
 Checks if the race is finished, and if so informs the clients and switches to state RESULT_DISPLAY, during which the race result gui is shown and all clients can click on 'continue'.
 
void getHitCaptureLimit ()
 
void configPeersStartTime ()
 This function is called when all clients have loaded the world and are therefore ready to start the race. More...
 
void resetServer ()
 
void addWaitingPlayersToGame ()
 
void changeHandicap (Event *event)
 Called when a player want to change his handicap. More...
 
void handlePlayerDisconnection () const
 Update and see if any player disconnects, if so eliminate the kart in world, so this function must be called in main thread.
 
void addLiveJoinPlaceholder (std::vector< std::shared_ptr< NetworkPlayerProfile > > &players) const
 Add reserved players for live join later if required.
 
NetworkStringgetLoadWorldMessage (std::vector< std::shared_ptr< NetworkPlayerProfile > > &players, bool live_join) const
 
void encodePlayers (BareNetworkString *bns, std::vector< std::shared_ptr< NetworkPlayerProfile > > &players) const
 
std::vector< std::shared_ptr< NetworkPlayerProfile > > getLivePlayers () const
 Get a list of current ingame players for live join or spectate.
 
void setPlayerKarts (const NetworkString &ns, STKPeer *peer) const
 
bool handleAssets (const NetworkString &ns, STKPeer *peer)
 
void liveJoinRequest (Event *event)
 This message is like kartSelectionRequested, but it will send the peer load world message if he can join the current started game.
 
void rejectLiveJoin (STKPeer *peer, BackLobbyReason blr)
 STKPeer peer will be reset back to the lobby with reason BackLobbyReason blr
 
bool canLiveJoinNow () const
 Returns true if server can be live joined or spectating.
 
bool worldIsActive () const
 Returns true if world is active for clients to live join, spectate or going back to lobby live.
 
int getReservedId (std::shared_ptr< NetworkPlayerProfile > &p, unsigned local_id) const
 Decide where to put the live join player depends on his team and game mode.
 
void handleKartInfo (Event *event)
 Tell the client RemoteKartInfo of a player when some player joining live.
 
void clientInGameWantsToBackLobby (Event *event)
 Client if currently in-game (including spectator) wants to go back to lobby.
 
void clientSelectingAssetsWantsToBackLobby (Event *event)
 Client if currently select assets wants to go back to lobby.
 
std::set< std::shared_ptr< STKPeer > > getSpectatorsByLimit ()
 
void kickPlayerWithReason (STKPeer *peer, const char *reason) const
 
void testBannedForIP (STKPeer *peer) const
 
void testBannedForIPv6 (STKPeer *peer) const
 
void testBannedForOnlineId (STKPeer *peer, uint32_t online_id) const
 
void writePlayerReport (Event *event)
 
bool supportsAI ()
 
void updateAddons ()
 

Private Attributes

std::atomic< ServerState > m_state
 
std::atomic< ResetState > m_rs_state
 
std::weak_ptr< STKPeerm_ai_peer
 AI peer which holds the list of reserved AI for dedicated server.
 
std::vector< std::shared_ptr< NetworkPlayerProfile > > m_ai_profiles
 AI profiles for all-in-one graphical client server, this will be a fixed count thorough the live time of server, which its value is configured in NetworkConfig.
 
std::atomic< uint32_t > m_server_owner_id
 
std::pair< std::set< std::string >, std::set< std::string > > m_available_kts
 Available karts and tracks for all clients, this will be initialized with data in server first.
 
std::atomic_bool m_server_has_loaded_world
 Keeps track of the server state.
 
bool m_registered_for_once_only
 
bool m_save_server_config
 
std::map< std::weak_ptr< STKPeer >, bool, std::owner_less< std::weak_ptr< STKPeer > > > m_peers_ready
 Counts how many peers have finished loading the world.
 
std::weak_ptr< Online::Requestm_server_registering
 
std::atomic< int64_t > m_timeout
 Timeout counter for various state.
 
std::mutex m_keys_mutex
 
std::map< uint32_t, KeyDatam_keys
 
std::map< std::weak_ptr< STKPeer >, std::pair< uint32_t, BareNetworkString >, std::owner_less< std::weak_ptr< STKPeer > > > m_pending_connection
 
std::map< std::string, uint64_t > m_pending_peer_connection
 
std::shared_ptr< Rankingm_ranking
 
NetworkStringm_result_ns
 
BareNetworkStringm_items_complete_state
 
std::atomic< uint32_t > m_server_id_online
 
std::atomic< uint32_t > m_client_server_host_id
 
std::atomic< int > m_difficulty
 
std::atomic< int > m_game_mode
 
std::atomic< int > m_lobby_players
 
std::atomic< int > m_current_ai_count
 
std::atomic< uint64_t > m_last_success_poll_time
 
uint64_t m_last_unsuccess_poll_time
 
uint64_t m_server_started_at
 
uint64_t m_server_delay
 
PeerVotem_default_vote
 
int m_battle_hit_capture_limit
 
float m_battle_time_limit
 
unsigned m_item_seed
 
uint32_t m_winner_peer_id
 
uint64_t m_client_starting_time
 
unsigned m_ai_count
 

Additional Inherited Members

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

◆ ServerLobby()

ServerLobby::ServerLobby ( )

This is the central game setup protocol running in the server.

It is mostly a finite state machine. Note that all nodes in ellipses and light grey background are actual states; nodes in boxes and white background are functions triggered from a state or triggering potentially a state change.

dot_inline_dotgraph_2.png

It starts with detecting the public ip address and port of this host (GetPublicAddress).

Member Function Documentation

◆ changeHandicap()

void ServerLobby::changeHandicap ( Event event)
private

Called when a player want to change his handicap.

Parameters
event: Event providing the information.

Format of the data :

Byte 0 1

Size | 1 | 1 |

Data | local player id | new handicap |

◆ checkIncomingConnectionRequests()

void ServerLobby::checkIncomingConnectionRequests ( )

Query the STK server for connection requests.

For each connection request start a ConnectToPeer protocol.

◆ clientDisconnected()

void ServerLobby::clientDisconnected ( Event event)
private

Called when a client disconnects.

Parameters
eventThe disconnect event.

◆ configPeersStartTime()

void ServerLobby::configPeersStartTime ( )
private

This function is called when all clients have loaded the world and are therefore ready to start the race.

It determine the start time in network timer for client and server based on pings and then switches state to WAIT_FOR_RACE_STARTED.

◆ finishedLoadingWorld()

void ServerLobby::finishedLoadingWorld ( )
virtual

Called from the RaceManager of the server when the world is loaded.

Marks the server to be ready to start the race.

Implements LobbyProtocol.

◆ finishedLoadingWorldClient()

void ServerLobby::finishedLoadingWorldClient ( Event event)
private

Called when a client notifies the server that it has loaded the world.

When all clients and the server are ready, the race can be started.

◆ handleAllVotes()

bool ServerLobby::handleAllVotes ( PeerVote winner_vote,
uint32_t *  winner_peer_id 
)
private

Select the track to be used based on all votes being received.

Parameters
winner_voteThe PeerVote that was picked.
winner_peer_idThe host id of winner (unchanged if no vote).
Returns
True if race can go on, otherwise wait.

◆ handlePlayerVote()

void ServerLobby::handlePlayerVote ( Event event)
private

Called when a player votes for track(s), it will auto correct client data if it sends some invalid data.

Parameters
event: Event providing the information.

◆ handleServerConfiguration()

void ServerLobby::handleServerConfiguration ( Event event)
private

Called when the server owner request to change game mode or difficulty.

Parameters
event: Event providing the information.

Format of the data :

Byte 0 1 2

Size | 1 | 1 | 1 |

Data | difficulty | game mode | soccer goal target |

◆ kartSelectionRequested()

void ServerLobby::kartSelectionRequested ( Event event)
private

Called when a player asks to select karts.

Parameters
event: Event providing the information.

◆ notifyEvent()

bool ServerLobby::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 ServerLobby::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.

◆ playerFinishedResult()

void ServerLobby::playerFinishedResult ( Event event)
private

Called when a client clicks on 'ok' on the race result screen.

If all players have clicked on 'ok', go back to the lobby.

◆ registerServer()

void ServerLobby::registerServer ( bool  first_time)
private

Register this server (i.e.

its public address) with the STK server so that clients can find it. It blocks till a response from the stk server is received (this function is executed from the ProtocolManager thread). The information about this client is added to the table 'server'.

◆ setup()

void ServerLobby::setup ( )
virtual

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

Returns
Newly create GameSetup object.

Implements LobbyProtocol.

◆ startSelection()

void ServerLobby::startSelection ( const Event event = NULL)

Instructs all clients to start the kart selection.

If event is NULL, the command comes from the owner less server.

◆ unregisterServer()

void ServerLobby::unregisterServer ( bool  now,
std::weak_ptr< ServerLobby sl = std::weak_ptr<ServerLobby>() 
)
private

Unregister this server (i.e.

its public address) with the STK server, currently when karts enter kart selection screen it will be done or quit stk.

◆ update()

void ServerLobby::update ( int  ticks)
virtual

Simple finite state machine.

Once this is known, register the server and its address with the stk server so that client can find it.

Implements LobbyProtocol.

◆ updatePlayerList()

void ServerLobby::updatePlayerList ( bool  update_when_reset_server = false)

Called when any players change their setting (team for example), or connection / disconnection, it will use the game_started parameter to determine if this should be send to all peers in server or just in game.

Parameters
update_when_reset_serverIf true, this message will be sent to all peers.

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