FindPublicIP in the CNetServer constructor

When using the lobby, after constructing `CNetServer` the public IP has
to be queried. The consructor knows whether the lobby is used, so do it
in the constructor.
This commit is contained in:
phosit
2026-03-03 21:20:33 +01:00
parent bc17e212bb
commit d5384ad742
3 changed files with 8 additions and 18 deletions
+8 -8
View File
@@ -1675,6 +1675,14 @@ CNetServer::CNetServer(const bool continueSavedGame, std::uint16_t port, const b
m_LobbyAuth{useLobbyAuth},
m_Password{std::move(password)}
{
if (!useLobbyAuth)
return;
// In lobby, we send our public ip and port on request to the players who want to connect.
// Thus we need to know our public IP and use STUN to get it.
std::lock_guard<std::mutex> lock(m_Worker->m_WorkerMutex);
if (!m_Worker->m_Host || !StunClient::FindPublicIP(*m_Worker->m_Host, m_PublicIp, m_PublicPort))
throw std::runtime_error{"Failed to resolve public IP-address."};
}
CNetServer::~CNetServer()
@@ -1705,14 +1713,6 @@ u16 CNetServer::GetLocalPort() const
return m_Worker->m_Host->address.port;
}
bool CNetServer::SetConnectionData()
{
std::lock_guard<std::mutex> lock(m_Worker->m_WorkerMutex);
if (!m_Worker->m_Host)
return false;
return StunClient::FindPublicIP(*m_Worker->m_Host, m_PublicIp, m_PublicPort);
}
bool CNetServer::CheckPasswordAndIncrement(const std::string& username, const std::string& password, const std::string& salt)
{
std::unordered_map<std::string, int>::iterator it = m_FailedAttempts.find(username);