diff --git a/src/main.cpp b/src/main.cpp index ad589fbe4..5eb03098e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1431,6 +1431,9 @@ int handleCmdLine(bool has_server_config, bool has_parent_process) // Server owner online account will keep online as long as // server is live Online::RequestManager::m_disable_polling = true; + // For server we assume it is an IPv4 one, because if it fails + // to detect the server won't start at all + NetworkConfig::get()->setIPType(NetworkConfig::IP_V4); NetworkConfig::get()->detectIPType(); NetworkConfig::get()->setIsWAN(); NetworkConfig::get()->setIsPublicServer(); diff --git a/src/network/network_config.hpp b/src/network/network_config.hpp index 764cabe93..b8b8efd73 100644 --- a/src/network/network_config.hpp +++ b/src/network/network_config.hpp @@ -262,6 +262,8 @@ public: // ------------------------------------------------------------------------ IPType getIPType() const { return m_ip_type.load(); } // ------------------------------------------------------------------------ + void setIPType(IPType ip_type) { m_ip_type.store(ip_type); } + // ------------------------------------------------------------------------ const std::string& getNAT64Prefix() const { return m_nat64_prefix; } }; // class NetworkConfig diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 99fbf36b3..087e3732d 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -1359,7 +1359,7 @@ void ServerLobby::asynchronousUpdate() } auto ip_type = NetworkConfig::get()->getIPType(); // Set the IPv6 address first for possible IPv6 only server - if (ip_type >= NetworkConfig::IP_V6) + if (isIPv6Socket() && ip_type >= NetworkConfig::IP_V6) { STKHost::get()->setPublicAddress(false/*ipv4*/); } diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index e4dc917a1..e1f547c3e 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -728,7 +728,11 @@ void STKHost::setPublicAddress(bool ipv4) if (NetworkConfig::get()->isServer() && ipv4 && port != m_public_address.getPort()) { - Log::error("STKHost", "IPv6 has different port than IPv4."); + if (ServerConfig::m_ipv6_server) + { + Log::error("STKHost", + "IPv6 has different port than IPv4."); + } m_public_ipv6_address.clear(); } if (ipv4)