Stop STKHost if cannot register public address

This commit is contained in:
Benau 2020-02-28 22:49:06 +08:00
parent eff00140f1
commit ee22c0f714
2 changed files with 12 additions and 8 deletions

View File

@ -244,12 +244,15 @@ void ConnectToServer::asynchronousUpdate()
{ {
STKHost::get()->setPublicAddress( STKHost::get()->setPublicAddress(
m_server->useIPV6Connection() ? AF_INET6 : AF_INET); m_server->useIPV6Connection() ? AF_INET6 : AF_INET);
if (!STKHost::get()->getValidPublicAddress().empty()) if (STKHost::get()->getValidPublicAddress().empty() ||
registerWithSTKServer(); registerWithSTKServer() == false)
} {
// Set to DONE will stop STKHost is not connected // Set to DONE will stop STKHost is not connected
m_state = STKHost::get()->getValidPublicAddress().empty() ? m_state = DONE;
DONE : GOT_SERVER_ADDRESS; break;
}
}
m_state = GOT_SERVER_ADDRESS;
break; break;
} }
case GOT_SERVER_ADDRESS: case GOT_SERVER_ADDRESS:
@ -467,7 +470,7 @@ bool ConnectToServer::tryConnect(int timeout, int retry, bool another_port,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Register this client with the STK server. /** Register this client with the STK server.
*/ */
void ConnectToServer::registerWithSTKServer() bool ConnectToServer::registerWithSTKServer()
{ {
// Our public address is now known, register details with // Our public address is now known, register details with
// STK server // STK server
@ -498,13 +501,14 @@ void ConnectToServer::registerWithSTKServer()
if(result->get("success", &success) && success == "yes") if(result->get("success", &success) && success == "yes")
{ {
Log::debug("ConnectToServer", "Address registered successfully."); Log::debug("ConnectToServer", "Address registered successfully.");
return true;
} }
else else
{ {
irr::core::stringc error(request->getInfo().c_str()); irr::core::stringc error(request->getInfo().c_str());
Log::error("ConnectToServer", "Failed to register client address: %s", Log::error("ConnectToServer", "Failed to register client address: %s",
error.c_str()); error.c_str());
m_state = DONE; return false;
} }
} // registerWithSTKServer } // registerWithSTKServer

View File

@ -53,7 +53,7 @@ private:
std::atomic<ConnectState> m_state; std::atomic<ConnectState> m_state;
void getClientServerInfo(); void getClientServerInfo();
void registerWithSTKServer(); bool registerWithSTKServer();
bool tryConnect(int timeout, int retry, bool another_port = false, bool tryConnect(int timeout, int retry, bool another_port = false,
bool ipv6 = false); bool ipv6 = false);
static ENetAddress m_server_address; static ENetAddress m_server_address;