mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +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);
|
||||
|
||||
@@ -130,8 +130,6 @@ public:
|
||||
|
||||
void SendHolePunchingMessage(const CStr& ip, u16 port);
|
||||
|
||||
bool SetConnectionData();
|
||||
|
||||
/**
|
||||
* Return the externally accessible IP.
|
||||
*/
|
||||
|
||||
@@ -108,14 +108,6 @@ void StartNetworkHost(const CStrW& playerName, const u16 serverPort, const CStr&
|
||||
const std::string secret = ps_generate_guid();
|
||||
g_NetServer = new CNetServer(continueSavedGame, serverPort, hasLobby, hashedPassword, secret);
|
||||
|
||||
// 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.
|
||||
if (hasLobby && !g_NetServer->SetConnectionData())
|
||||
{
|
||||
SAFE_DELETE(g_NetServer);
|
||||
throw std::runtime_error{"Failed to resolve public IP-address."};
|
||||
}
|
||||
|
||||
// Generate a secret to identify the host client.
|
||||
|
||||
g_Game = new CGame(storeReplay);
|
||||
|
||||
Reference in New Issue
Block a user