19#ifndef LOBBY_PROTOCOL_HPP
20#define LOBBY_PROTOCOL_HPP
23#include "utils/stk_process.hpp"
52 LE_CONNECTION_REQUESTED = 1,
53 LE_CONNECTION_REFUSED,
54 LE_CONNECTION_ACCEPTED,
57 LE_UPDATE_PLAYER_LIST,
59 LE_PLAYER_DISCONNECTED,
60 LE_CLIENT_LOADED_WORLD,
86 enum RejectReason : uint8_t
90 RR_INCORRECT_PASSWORD = 2,
91 RR_INCOMPATIBLE_DATA = 3,
92 RR_TOO_MANY_PLAYERS = 4,
96 enum BackLobbyReason : uint8_t
99 BLR_NO_GAME_FOR_LIVE_JOIN = 1,
100 BLR_NO_PLACE_FOR_LIVE_JOIN = 2,
101 BLR_ONE_PLAYER_IN_RANKED_MATCH = 3,
102 BLR_SERVER_ONWER_QUITED_THE_GAME = 4,
103 BLR_SPECTATING_NEXT_GAME = 5
107 const ProcessType m_process_type;
118 std::thread m_start_game_thread;
120 static std::weak_ptr<LobbyProtocol> m_lobby[PT_COUNT];
144 void configRemoteKart(
145 const std::vector<std::shared_ptr<NetworkPlayerProfile> >& players,
146 int local_player_size)
const;
148 void joinStartGameThread()
150 if (m_start_game_thread.joinable())
151 m_start_game_thread.join();
155 int live_join_util_ticks)
const;
157 void exitGameState();
161 template<
typename Singleton,
typename... Types>
162 static std::shared_ptr<Singleton>
create(Types ...args)
164 ProcessType pt = STKProcess::getType();
165 assert(m_lobby[pt].expired());
166 auto ret = std::make_shared<Singleton>(args...);
168 return std::dynamic_pointer_cast<Singleton>(ret);
173 template<
class T>
static std::shared_ptr<T>
get()
175 ProcessType pt = STKProcess::getType();
176 if (std::shared_ptr<LobbyProtocol> lp = m_lobby[pt].lock())
178 std::shared_ptr<T> new_type = std::dynamic_pointer_cast<T>(lp);
187 template<
class T>
static std::shared_ptr<T>
getByType(ProcessType pt)
189 if (std::shared_ptr<LobbyProtocol> lp = m_lobby[pt].lock())
191 std::shared_ptr<T> new_type = std::dynamic_pointer_cast<T>(lp);
202 virtual void setup() = 0;
204 virtual void finishedLoadingWorld() = 0;
206 virtual bool allPlayersReady()
const = 0;
207 virtual bool isRacing()
const = 0;
231 std::pair<uint32_t, uint32_t> getGameStartedProgress()
const
237 void setGameStartedProgress(
const std::pair<uint32_t, uint32_t>& p)
243 void resetGameStartedProgress()
249 bool hasLiveJoiningRecently()
const;
251 void storePlayingTrack(
const std::string& track_ident)
257 std::string getPlayingTrackIdent()
const
263 Track* getPlayingTrack()
const;
Used to store the needed data about the players that join a game. This class stores all the possible ...
Definition: game_setup.hpp:43
Base class for both client and server lobby. The lobbies are started when a server opens a game,...
Definition: lobby_protocol.hpp:47
float getRemainingVotingTime()
Returns the remaining voting time in seconds.
Definition: lobby_protocol.cpp:193
void startVotingPeriod(float max_time)
Starts the voting period time with the specified maximum time.
Definition: lobby_protocol.cpp:185
virtual void update(int ticks)=0
Called by the protocol listener, synchronously with the main loop.
std::map< uint32_t, PeerVote > m_peers_votes
Vote from each peer.
Definition: lobby_protocol.hpp:110
bool isVotingOver()
Returns if the voting period is over.
Definition: lobby_protocol.cpp:204
std::atomic< uint32_t > m_estimated_remaining_time
Estimated current started game remaining time, uint32_t max if not available.
Definition: lobby_protocol.hpp:124
static std::shared_ptr< T > get()
Returns the singleton client or server lobby protocol.
Definition: lobby_protocol.hpp:173
int m_last_live_join_util_ticks
Save the last live join ticks, for physical objects to update current transformation in server,...
Definition: lobby_protocol.hpp:132
int getNumberOfVotes() const
Returns the number of votes received so far.
Definition: lobby_protocol.hpp:219
GameSetup * getGameSetup() const
Returns the game setup data structure.
Definition: lobby_protocol.hpp:216
virtual void loadWorld()
Starts the sychronization protocol and the RaceEventManager.
Definition: lobby_protocol.cpp:74
static std::shared_ptr< Singleton > create(Types ...args)
Creates either a client or server lobby protocol as a singleton.
Definition: lobby_protocol.hpp:162
std::string m_current_track
Store current playing track in name.
Definition: lobby_protocol.hpp:138
std::atomic< uint64_t > m_end_voting_period
Timer user for voting periods in both lobbies.
Definition: lobby_protocol.hpp:113
static std::shared_ptr< T > getByType(ProcessType pt)
Returns specific singleton client or server lobby protocol.
Definition: lobby_protocol.hpp:187
float getMaxVotingTime()
Returns the maximum floating time in seconds.
Definition: lobby_protocol.hpp:213
virtual void setup()=0
A previous GameSetup is deleted and a new one is created.
Definition: lobby_protocol.cpp:170
GameSetup * m_game_setup
Stores data about the online game to play.
Definition: lobby_protocol.hpp:141
uint64_t m_max_voting_time
The maximum voting time.
Definition: lobby_protocol.hpp:116
const PeerVote * getVote(uint32_t host_id) const
Returns the voting data for one host.
Definition: lobby_protocol.cpp:223
std::mutex m_current_track_mutex
Mutex to protect m_current_track.
Definition: lobby_protocol.hpp:135
void addVote(uint32_t host_id, const PeerVote &vote)
Adds a vote.
Definition: lobby_protocol.cpp:214
const std::map< uint32_t, PeerVote > & getAllVotes() const
Returns all voting data.
Definition: lobby_protocol.hpp:228
std::atomic< uint32_t > m_estimated_progress
Estimated current started game progress in 0-100%, uint32_t max if not available.
Definition: lobby_protocol.hpp:128
Contains the profile of a player.
Definition: network_player_profile.hpp:42
A simple structure to store a vote from a client: track name, number of laps and reverse or not.
Definition: peer_vote.hpp:30
Abstract class used to define the global protocol functions.
Definition: protocol.hpp:92
Definition: remote_kart_info.hpp:51
Definition: singleton.hpp:87
Definition: track.hpp:114
Generic protocols declarations.