mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:04:06 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user