Added debug option to disable automatic LAN connection.

This commit is contained in:
hiker 2016-11-10 18:21:27 +11:00
parent 9201a08daf
commit 6065a6ce3e
5 changed files with 19 additions and 6 deletions

View File

@ -578,6 +578,7 @@ void cmdLineHelp()
" --password=s Automatically log in (set the password).\n"
" --port=n Port number to use.\n"
" --my-address=1.1.1.1:1 Own IP address (can replace stun protocol)\n"
" --disable-lan Disable LAN detection (connect using WAN).\n"
" --max-players=n Maximum number of clients (server only).\n"
" --no-console Does not write messages in the console but to\n"
" stdout.log.\n"
@ -1016,6 +1017,11 @@ int handleCmdLine()
if (CommandLine::has("--my-address", &s))
GetPublicAddress::setMyIPAddress(s);
/** Disable detection of LAN connection when connecting via WAN. This is
* mostly a debugging feature to force using WAN connection. */
if (CommandLine::has("--disable-lan"))
NetworkConfig::m_disable_lan = true;
// Race parameters
if(CommandLine::has("--kartsize-debug"))
{

View File

@ -19,6 +19,7 @@
#include "network/network_config.hpp"
NetworkConfig *NetworkConfig::m_network_config = NULL;
bool NetworkConfig::m_disable_lan = false;
/** \class NetworkConfig
* This class is the interface between STK and the online code, particularly

View File

@ -72,6 +72,10 @@ private:
NetworkConfig();
public:
/** Stores the command line flag to disable lan detection (i.e. force
* WAN code to be used when connection client and server). */
static bool m_disable_lan;
/** Singleton get, which creates this object if necessary. */
static NetworkConfig *get()
{

View File

@ -125,9 +125,10 @@ void ConnectToPeer::asynchronousUpdate()
// the Ping protocol to keep the port available. We can't rely on
// STKHost::isLAN(), since we might get a LAN connection even if
// the server itself accepts connections from anywhere.
if (!m_is_lan &&
m_peer_address.getIP() != NetworkConfig::get()
->getMyAddress().getIP())
if ( (!m_is_lan &&
m_peer_address.getIP() !=
NetworkConfig::get()->getMyAddress().getIP() ) ||
NetworkConfig::m_disable_lan )
{
m_current_protocol = new PingProtocol(m_peer_address,
/*time-between-ping*/2.0);

View File

@ -175,9 +175,10 @@ void ConnectToServer::asynchronousUpdate()
m_current_protocol->requestStart();
return;
}
if (m_server_address.getIP()
== NetworkConfig::get()->getMyAddress().getIP() ||
NetworkConfig::get()->isLAN())
if( ( !NetworkConfig::m_disable_lan &&
m_server_address.getIP()
== NetworkConfig::get()->getMyAddress().getIP() ) ||
NetworkConfig::get()->isLAN() )
{
// We're in the same lan (same public ip address).
// The state will change to CONNECTING