19#ifndef CLIENT_LOBBY_HPP
20#define CLIENT_LOBBY_HPP
22#include "input/input.hpp"
23#include "network/protocols/lobby_protocol.hpp"
24#include "utils/cpp2011.hpp"
34enum KartTeam : int8_t;
47 irr::core::stringw m_user_name;
48 int m_local_player_id;
55 std::string m_country_code;
57 bool isSpectator()
const {
return m_icon_id == 5; }
58 bool isAI()
const {
return m_icon_id == 6; }
72 void receivePlayerVote(
Event* event);
73 void updatePlayerList(
Event* event);
74 void handleChat(
Event* event);
75 void handleServerInfo(
Event* event);
76 void reportSuccess(
Event* event);
78 void handleBadConnection();
79 void becomingServerOwner();
81 std::shared_ptr<Server> m_server;
83 enum ClientState :
unsigned int
87 REQUESTING_CONNECTION,
96 bool m_waiting_for_game;
98 bool m_server_auto_game_time;
100 bool m_received_server_result;
104 bool m_first_connect;
108 bool m_server_live_joinable;
110 bool m_server_send_live_load_world;
112 bool m_server_enabled_chat;
114 bool m_server_enabled_track_voting;
116 bool m_server_enabled_report_player;
118 uint64_t m_auto_back_to_lobby_time;
120 uint64_t m_start_live_game_time;
125 std::set<std::string> m_available_karts;
126 std::set<std::string> m_available_tracks;
128 void addAllPlayers(
Event* event);
132 std::map<PeerDisconnectInfo, irr::core::stringw> m_disconnected_msg;
134 std::vector<LobbyPlayer> m_lobby_players;
136 std::vector<float> m_ranking_changes;
138 irr::core::stringw m_total_players;
140 static std::thread m_background_download;
142 static std::shared_ptr<Online::HTTPRequest> m_download_request;
144 void liveJoinAcknowledged(
Event* event);
145 void handleKartInfo(
Event* event);
146 void finishLiveJoin();
147 std::vector<std::shared_ptr<NetworkPlayerProfile> >
149 std::shared_ptr<STKPeer> peer =
nullptr,
150 bool* is_spectator = NULL)
const;
152 std::vector<std::shared_ptr<NetworkPlayerProfile> >& players)
const;
159 bool receivedServerResult() {
return m_received_server_result; }
160 void startingRaceNow();
161 const std::set<std::string>& getAvailableKarts()
const
162 {
return m_available_karts; }
163 const std::set<std::string>& getAvailableTracks()
const
164 {
return m_available_tracks; }
168 virtual
void setup() OVERRIDE;
169 virtual
void update(
int ticks) OVERRIDE;
171 virtual bool allPlayersReady() const OVERRIDE
172 {
return m_state.load() >= RACING; }
173 bool waitingForServerRespond()
const
174 {
return m_state.load() == REQUESTING_CONNECTION; }
175 bool isLobbyReady()
const {
return !m_first_connect; }
176 bool isWaitingForGame()
const {
return m_waiting_for_game; }
177 bool isServerAutoGameTime()
const {
return m_server_auto_game_time; }
178 virtual bool isRacing() const OVERRIDE {
return m_state.load() == RACING; }
179 void requestKartInfo(uint8_t kart_id);
180 void setSpectator(
bool val) { m_spectator = val; }
181 bool isSpectator()
const
182 {
return m_spectator &&
m_state.load() != RACE_FINISHED; }
183 void startLiveJoinKartSelection();
184 void sendChat(irr::core::stringw text, KartTeam team);
185 const std::vector<LobbyPlayer>& getLobbyPlayers()
const
186 {
return m_lobby_players; }
187 bool isServerLiveJoinable()
const {
return m_server_live_joinable; }
188 void changeSpectateTarget(
PlayerAction action,
int value,
189 Input::InputType type)
const;
190 void addSpectateHelperMessage()
const;
191 bool serverEnabledChat()
const {
return m_server_enabled_chat; }
192 bool serverEnabledTrackVoting()
const
193 {
return m_server_enabled_track_voting; }
194 bool serverEnabledReportPlayer()
const
195 {
return m_server_enabled_report_player; }
196 const std::vector<float>& getRankingChanges()
const
197 {
return m_ranking_changes; }
198 void handleClientCommand(
const std::string& cmd);
199 ClientState getCurrentState()
const {
return m_state.load(); }
200 std::shared_ptr<Server> getJoinedServer()
const {
return m_server; }
201 static bool startedDownloadAddonsPack()
202 {
return m_background_download.joinable() || m_download_request; }
203 static void downloadAddonsPack(std::shared_ptr<Online::HTTPRequest> r);
204 static void destroyBackgroundDownload();
205 void updateAssetsToServer();
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Definition: client_lobby.hpp:62
void doInstallAddonsPack()
Called when the asynchronous download of the addon finished.
Definition: client_lobby.cpp:1930
void raceFinished(Event *event)
Called when all karts have finished the race.
Definition: client_lobby.cpp:1137
void disconnectedPlayer(Event *event)
Called when a new player is disconnected.
Definition: client_lobby.cpp:617
std::atomic< ClientState > m_state
The state of the finite state machine.
Definition: client_lobby.hpp:123
void startSelection(Event *event)
Called when the kart selection starts.
Definition: client_lobby.cpp:1054
virtual void asynchronousUpdate() OVERRIDE
Called by the protocol listener as often as possible.
Definition: client_lobby.hpp:170
virtual void setup() OVERRIDE
A previous GameSetup is deleted and a new one is created.
Definition: client_lobby.cpp:155
void connectionRefused(Event *event)
Callback function on connection refusal.
Definition: client_lobby.cpp:958
virtual void update(int ticks) OVERRIDE
Called by the protocol listener, synchronously with the main loop.
Definition: client_lobby.cpp:402
virtual bool notifyEvent(Event *event) OVERRIDE
Notify a protocol matching the Event type of that event.
Definition: client_lobby.cpp:185
void doneWithResults()
Called from the gui when a client clicked on 'continue' on the race result screen.
Definition: client_lobby.cpp:175
void backToLobby(Event *event)
Called when the server informs the clients to exit the race result screen.
Definition: client_lobby.cpp:1207
virtual bool notifyEventAsynchronous(Event *event) OVERRIDE
Notify a protocol matching the Event type of that event.
Definition: client_lobby.cpp:223
void startGame(Event *event)
Called when the server broadcasts to start the race to all clients.
Definition: client_lobby.cpp:1010
void connectionAccepted(Event *event)
Callback function on connection acceptation.
Definition: client_lobby.cpp:656
virtual void finishedLoadingWorld() OVERRIDE
Callback when the world is loaded.
Definition: client_lobby.cpp:1280
Class representing an event that need to pass trough the system. This is used to remove ENet dependen...
Definition: event.hpp:73
Base class for both client and server lobby. The lobbies are started when a server opens a game,...
Definition: lobby_protocol.hpp:47
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
Definition: server.hpp:44
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:42
PeerDisconnectInfo
Definition: stk_peer.hpp:48
Definition: client_lobby.hpp:46