Skip to content

Commit 5cacd48

Browse files
committed
Add ipv6 server configuration
1 parent 3f0db67 commit 5cacd48

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

NETWORKING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ The current server configuration xml looks like this:
7878
<!-- Disable it to turn off all stun related code in server, it allows saving server resource if your server is not behind a firewall. -->
7979
<firewalled-server value="true" />
8080

81+
<!-- Enable to allow ipv6 connection if you have a public ipv6 address. STK currently use dual-stack mode which requires server to have both ipv4 and ipv6 and listen to same port, firewalled-server will be disabled so you need to make sure this server has port forward configured properly if needed. -->
82+
<ipv6-server value="false" />
83+
8184
<!-- No server owner in lobby which can control the starting of game or kick any players. -->
8285
<owner-less value="false" />
8386

src/network/server_config.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ void loadServerLobbyFromConfig()
340340
m_server_max_players > 10)
341341
m_server_max_players = 10;
342342

343+
if (m_ipv6_server)
344+
{
345+
#ifdef ENABLE_IPV6
346+
m_firewalled_server = false;
347+
#else
348+
Log::warn("ServerConfig", "IPV6 support not compiled.");
349+
#endif
350+
}
351+
343352
if (m_ranked)
344353
{
345354
m_validating_player = true;

src/network/server_config.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ namespace ServerConfig
176176
"it allows saving server resource if your server is not "
177177
"behind a firewall."));
178178

179+
SERVER_CFG_PREFIX BoolServerConfigParam m_ipv6_server
180+
SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "ipv6-server",
181+
"Enable to allow ipv6 connection if you have a public ipv6 address. "
182+
"STK currently use dual-stack mode which requires server to have both "
183+
"ipv4 and ipv6 and listen to same port, firewalled-server will be "
184+
"disabled so you need to make sure this server has port forward "
185+
"configured properly if needed."));
186+
179187
SERVER_CFG_PREFIX BoolServerConfigParam m_owner_less
180188
SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "owner-less",
181189
"No server owner in lobby which can control the starting of game or "

src/network/stk_host.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ STKHost::STKHost(bool server)
261261

262262
if (server)
263263
{
264+
setIPV6(ServerConfig::m_ipv6_server ? 1 : 0);
264265
addr.port = ServerConfig::m_server_port;
265266
if (addr.port == 0 && !UserConfigParams::m_random_server_port)
266267
addr.port = stk_config->m_server_port;
@@ -856,12 +857,18 @@ void STKHost::mainLoop()
856857

857858
// A separate network connection (socket) to handle LAN requests.
858859
Network* direct_socket = NULL;
859-
if (!isIPV6() && ((NetworkConfig::get()->isLAN() && is_server) ||
860-
NetworkConfig::get()->isPublicServer()))
860+
if ((NetworkConfig::get()->isLAN() && is_server) ||
861+
NetworkConfig::get()->isPublicServer())
861862
{
862863
TransportAddress address(0, stk_config->m_server_discovery_port);
863864
ENetAddress eaddr = address.toEnetAddress();
865+
bool socket_ipv6 = isIPV6() == 1 ? true : false;
866+
if (socket_ipv6)
867+
setIPV6(0);
868+
// direct_socket use IPV4 only atm
864869
direct_socket = new Network(1, 1, 0, 0, &eaddr);
870+
if (socket_ipv6)
871+
setIPV6(1);
865872
if (direct_socket->getENetHost() == NULL)
866873
{
867874
Log::warn("STKHost", "No direct socket available, this "

src/network/unix_ipv6.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ int isIPV6()
141141
return 0;
142142
} // isIPV6
143143

144+
// ----------------------------------------------------------------------------
145+
void setIPV6(int val)
146+
{
147+
} // setIPV6
148+
144149
// ----------------------------------------------------------------------------
145150
std::string getIPV6ReadableFromMappedAddress(const ENetAddress* ea)
146151
{
@@ -180,7 +185,7 @@ void unixInitialize()
180185
{
181186
// Clear previous setting, in case user changed wifi or mobile data
182187
g_mapped_ipv6_used = 0;
183-
g_ipv6 = 1;
188+
g_ipv6 = 0;
184189
g_mapped_ips.clear();
185190
} // unixInitialize
186191

0 commit comments

Comments
 (0)