22#ifndef HEADER_NETWORK_CONFIG
23#define HEADER_NETWORK_CONFIG
25#include "race/race_manager.hpp"
26#include "utils/stk_process.hpp"
27#include "utils/no_copy.hpp"
57 IP_NONE, IP_V4, IP_V6, IP_V6_NAT64, IP_DUAL_STACK
63 static bool m_system_ipv4;
65 static bool m_system_ipv6;
67 enum NetworkType :
int
69 NETWORK_NONE, NETWORK_WAN, NETWORK_LAN
72 std::atomic<IPType> m_ip_type;
89 bool m_done_adding_network_players;
108 std::string m_cur_user_token;
113 std::vector<std::tuple<InputDevice*, PlayerProfile*, HandicapLevel> > m_network_players;
117 uint32_t m_joined_server_version;
130 std::array<uint32_t, 8> m_nat64_prefix_data;
132 static void fillStunList(std::vector<std::pair<std::string, int> >* l,
133 const std::string& dns);
141 ProcessType type = STKProcess::getType();
152 static void clearDetectIPThread(
bool quit_stk);
156 static void destroy()
158 ProcessType type = STKProcess::getType();
162 clearDetectIPThread(
true);
206 std::vector<std::tuple<InputDevice*, PlayerProfile*, HandicapLevel> >&
207 getNetworkPlayers() {
return m_network_players; }
209 bool isAddingNetworkPlayers()
const
210 {
return !m_done_adding_network_players; }
212 void doneAddingNetworkPlayers() { m_done_adding_network_players =
true; }
217 for (
auto& p : m_network_players)
221 if (std::get<1>(p) == profile)
224 m_network_players.emplace_back(device, profile, h);
230 for (
auto& p : m_network_players)
232 if (std::get<1>(p) == profile)
238 void cleanNetworkPlayers()
240 m_network_players.clear();
241 m_done_adding_network_players =
false;
263 void setCurrentUserToken(
const std::string& t) { m_cur_user_token = t; }
267 const std::string& getCurrentUserToken()
const {
return m_cur_user_token; }
269 void setUserDetails(std::shared_ptr<Online::XMLRequest> r,
270 const std::string& name);
272 void setServerDetails(std::shared_ptr<Online::XMLRequest> r,
273 const std::string& name);
279 std::vector<GUIEngine::Screen*> getResetScreens(
bool lobby =
false)
const;
281 void setJoinedServerVersion(uint32_t v) { m_joined_server_version = v; }
283 uint32_t getJoinedServerVersion()
const {
return m_joined_server_version; }
293 void setServerCapabilities(std::set<std::string>& caps)
298 const std::set<std::string>& getServerCapabilities()
const
303 IPType getIPType()
const {
return m_ip_type.load(); }
305 void setIPType(IPType ip_type) { m_ip_type.store(ip_type); }
307 const std::string& getNAT64Prefix()
const {
return m_nat64_prefix; }
309 const std::array<uint32_t, 8>& getNAT64PrefixData()
const
310 {
return m_nat64_prefix_data; }
318 static const std::vector<std::pair<std::string, int> >&
319 getStunList(
bool ipv4);
This class is the interface between STK and the online code, particularly STKHost.
Definition: network_config.hpp:53
void initClientPort()
Separated from constructor because this needs to be run after user config is load.
Definition: network_config.cpp:169
void clearActivePlayersForClient() const
Called before (re)starting network race, must be used before adding split screen players.
Definition: network_config.cpp:262
bool isClient() const
Returns if this instance is a client.
Definition: network_config.hpp:248
uint32_t m_cur_user_id
Used by wan server.
Definition: network_config.hpp:107
static NetworkConfig * get()
Singleton get, which creates this object if necessary.
Definition: network_config.hpp:139
bool m_network_ai_instance
True if this STK instance is an AI instance which is used for server AI.
Definition: network_config.hpp:93
bool m_is_public_server
If set it allows clients to connect directly to this server without using the stk server in between.
Definition: network_config.hpp:80
void setIsLAN()
Set that this is a LAN networked game.
Definition: network_config.hpp:199
std::string m_nat64_prefix
For IPv6 only network we try to detect the NAT64 prefix so we can use it to connect to ipv4 only serv...
Definition: network_config.hpp:129
bool m_auto_connect
True if a client should connect to the first server it finds and immediately start a race.
Definition: network_config.hpp:87
bool isPublicServer() const
Returns if connections directly to the server are to be accepted.
Definition: network_config.hpp:186
int m_state_frequency
Set by client or server which is required to be the same.
Definition: network_config.hpp:120
bool roundValuesNow() const
True when client needs to round the bodies phyiscal info for current ticks, server doesn't as it will...
Definition: network_config.cpp:279
bool isServer() const
Returns if this instance is a server.
Definition: network_config.hpp:245
uint16_t m_client_port
The LAN port on which a client is waiting for a server connection.
Definition: network_config.hpp:104
void unsetNetworking()
Set that this is not a networked game.
Definition: network_config.cpp:178
void setIsPublicServer()
Sets that this server can be contacted directly.
Definition: network_config.hpp:183
void getIPDetectionResult(uint64_t timeout)
Use stun servers to detect current ip type.
Definition: network_config.cpp:379
bool isNetworking() const
Return if a network setting is happening.
Definition: network_config.hpp:190
static NetworkConfig * m_network_config[PT_COUNT]
The singleton instance.
Definition: network_config.hpp:61
void setIsWAN()
Set that this is a WAN networked game.
Definition: network_config.hpp:202
std::set< std::string > m_server_capabilities
List of server capabilities set when joining it, to determine features available in same version.
Definition: network_config.hpp:124
std::atomic< NetworkType > m_network_type
Keeps the type of network connection: none (yet), LAN or WAN.
Definition: network_config.hpp:75
bool isAutoConnect() const
Returns if an immediate connection to the first server was requested.
Definition: network_config.hpp:255
static void queueIPDetection()
Use stun servers to detect current ip type.
Definition: network_config.cpp:328
std::atomic_bool m_is_server
True if this host is a server, false otherwise.
Definition: network_config.hpp:83
NetworkConfig()
Constructor.
Definition: network_config.cpp:146
unsigned m_num_fixed_ai
No.
Definition: network_config.hpp:101
void setAutoConnect(bool b)
Sets if a client should immediately connect to the first server.
Definition: network_config.hpp:251
std::string m_server_id_file
Used by client server to determine if the child server is created.
Definition: network_config.hpp:111
void setClientPort(uint16_t port)
Sets the port on which a client listens for server connection.
Definition: network_config.hpp:177
uint16_t getClientPort() const
Returns the port on which a client listens for server connections.
Definition: network_config.hpp:180
bool isLAN() const
Return true if it's a networked game with a LAN server.
Definition: network_config.hpp:193
bool isWAN() const
Return true if it's a networked game but with a WAN server.
Definition: network_config.hpp:196
void setIsServer(bool b)
Sets if this instance is a server or client.
Definition: network_config.hpp:171
bool m_tux_hitbox_addon
When live join is disabled addon kart will use their real hitbox.
Definition: network_config.hpp:96
static void initSystemIP()
Initialize detection of system IPv4 or IPv6 support.
Definition: network_config.cpp:95
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:54
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:42