Only register server with a valid address

This commit is contained in:
Benau 2020-01-28 01:26:12 +08:00
parent 3d0ef44014
commit 05732c2e7d
4 changed files with 9 additions and 8 deletions

View File

@ -258,10 +258,11 @@ void ConnectToServer::asynchronousUpdate()
{
STKHost::get()->setPublicAddress(
!m_server->useIPV6Connection());
registerWithSTKServer();
if (!STKHost::get()->getValidPublicAddress().empty())
registerWithSTKServer();
}
// Set to DONE will stop STKHost is not connected
m_state = STKHost::get()->getVaildPublicAddress().empty() ?
m_state = STKHost::get()->getValidPublicAddress().empty() ?
DONE : GOT_SERVER_ADDRESS;
break;
}
@ -517,7 +518,7 @@ void ConnectToServer::registerWithSTKServer()
request->addParameter("aes-iv", Crypto::getClientIV());
Log::info("ConnectToServer", "Registering addr %s",
STKHost::get()->getVaildPublicAddress().c_str());
STKHost::get()->getValidPublicAddress().c_str());
// This can be done blocking: till we are registered with the
// stk server, there is no need to to react to any other

View File

@ -2260,7 +2260,7 @@ bool ServerLobby::registerServer(bool now)
request->addParameter("address_ipv6",
STKHost::get()->getPublicIPV6Address());
Log::info("ServerLobby", "Public IPv6 server address %s",
STKHost::get()->getVaildPublicAddress().c_str());
STKHost::get()->getValidPublicAddress().c_str());
}
if (now)
{
@ -2298,7 +2298,7 @@ void ServerLobby::unregisterServer(bool now)
else
{
Log::info("ServerLobby", "Unregister server address %s",
STKHost::get()->getVaildPublicAddress().c_str());
STKHost::get()->getValidPublicAddress().c_str());
}
// No need to check for result as server will be auto-cleared anyway

View File

@ -1652,7 +1652,7 @@ bool STKHost::hasServerAI() const
// ----------------------------------------------------------------------------
/** Return an valid public IPv4 or IPv6 address with port, empty if both are
* unset, IPv6 will come first if both exists. */
std::string STKHost::getVaildPublicAddress() const
std::string STKHost::getValidPublicAddress() const
{
if (!m_public_ipv6_address.empty() && m_public_address.getPort() != 0)
{
@ -1662,7 +1662,7 @@ std::string STKHost::getVaildPublicAddress() const
if (!m_public_address.isUnset())
return m_public_address.toString();
return "";
} // getVaildPublicAddress
} // getValidPublicAddress
// ----------------------------------------------------------------------------
int STKHost::receiveRawPacket(char *buffer, int buffer_len,

View File

@ -207,7 +207,7 @@ public:
const std::string& getPublicIPV6Address() const
{ return m_public_ipv6_address; }
// ------------------------------------------------------------------------
std::string getVaildPublicAddress() const;
std::string getValidPublicAddress() const;
// ------------------------------------------------------------------------
const TransportAddress& getStunAddress() const { return m_stun_address; }
// ------------------------------------------------------------------------