Don't try to hide address in LAN networking, other minor fixes.

This commit is contained in:
hiker 2015-11-16 18:43:46 +11:00
parent 4a3c4c552e
commit 785b9a9130

View File

@ -184,7 +184,8 @@ void ConnectToServer::asynchronousUpdate()
if (m_server_address.getIP() if (m_server_address.getIP()
== NetworkConfig::get()->getMyAddress().getIP()) == NetworkConfig::get()->getMyAddress().getIP())
{ {
// we're in the same lan (same public ip address) !! // We're in the same lan (same public ip address).
// The state will change to CONNECTING
handleSameLAN(); handleSameLAN();
} }
else else
@ -200,8 +201,8 @@ void ConnectToServer::asynchronousUpdate()
static double timer = 0; static double timer = 0;
if (StkTime::getRealTime() > timer+5.0) // every 5 seconds if (StkTime::getRealTime() > timer+5.0) // every 5 seconds
{ {
timer = StkTime::getRealTime();
STKHost::get()->connect(m_server_address); STKHost::get()->connect(m_server_address);
timer = StkTime::getRealTime();
Log::info("ConnectToServer", "Trying to connect to %s", Log::info("ConnectToServer", "Trying to connect to %s",
m_server_address.toString().c_str()); m_server_address.toString().c_str());
} }
@ -210,20 +211,32 @@ void ConnectToServer::asynchronousUpdate()
case CONNECTED: case CONNECTED:
{ {
Log::info("ConnectToServer", "Connected"); Log::info("ConnectToServer", "Connected");
if(m_current_protocol)
{
// Kill the ping protocol because we're connected // Kill the ping protocol because we're connected
m_current_protocol->requestTerminate(); m_current_protocol->requestTerminate();
}
delete m_current_protocol;
m_current_protocol = NULL;
// LAN networking does not use the stk server tables.
if(NetworkConfig::get()->isWAN())
{
m_current_protocol = new HidePublicAddress(); m_current_protocol = new HidePublicAddress();
m_current_protocol->requestStart(); m_current_protocol->requestStart();
// FIXME - is that necessary? ClientNetworkManager::getInstance()->setConnected(true); }
// FIXME We can test if the peer is connected, which is handled by ENet
m_state = HIDING_ADDRESS; m_state = HIDING_ADDRESS;
break; break;
} }
case HIDING_ADDRESS: case HIDING_ADDRESS:
// Wait till we have hidden our address // Wait till we have hidden our address
if (m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED) if (!m_current_protocol ||
m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED)
{ {
if(m_current_protocol)
{
delete m_current_protocol;
m_current_protocol = NULL;
}
Log::info("ConnectToServer", "Address hidden"); Log::info("ConnectToServer", "Address hidden");
m_state = DONE; m_state = DONE;
// lobby room protocol if we're connected only // lobby room protocol if we're connected only
@ -445,7 +458,12 @@ bool ConnectToServer::notifyEventAsynchronous(Event* event)
{ {
Log::info("ConnectToServer", "The Connect To Server protocol has " Log::info("ConnectToServer", "The Connect To Server protocol has "
"received an event notifying that he's connected to the peer."); "received an event notifying that he's connected to the peer.");
//STKHost::get()->addPeer(event->getPeer());
m_state = CONNECTED; // we received a message, we are connected m_state = CONNECTED; // we received a message, we are connected
Server *server = ServersManager::get()->getJoinedServer();
// STKHost::get()->connect(server->getAddress());
event->getPeer();
} }
return true; return true;
} // notifyEventAsynchronous } // notifyEventAsynchronous