diff --git a/src/main.cpp b/src/main.cpp index 2c97add07..040c37c49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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")) { diff --git a/src/network/network_config.cpp b/src/network/network_config.cpp index 549b4b9db..83e8111d8 100644 --- a/src/network/network_config.cpp +++ b/src/network/network_config.cpp @@ -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 diff --git a/src/network/network_config.hpp b/src/network/network_config.hpp index d57903c3e..935a373d2 100644 --- a/src/network/network_config.hpp +++ b/src/network/network_config.hpp @@ -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() { diff --git a/src/network/protocols/connect_to_peer.cpp b/src/network/protocols/connect_to_peer.cpp index 45a38bc55..41e0bf6a9 100644 --- a/src/network/protocols/connect_to_peer.cpp +++ b/src/network/protocols/connect_to_peer.cpp @@ -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); diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp index 28d94812d..5f4729440 100644 --- a/src/network/protocols/connect_to_server.cpp +++ b/src/network/protocols/connect_to_server.cpp @@ -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 diff --git a/src/network/protocols/get_peer_address.cpp b/src/network/protocols/get_peer_address.cpp index c2c736d20..2ef5a6a96 100644 --- a/src/network/protocols/get_peer_address.cpp +++ b/src/network/protocols/get_peer_address.cpp @@ -66,7 +66,7 @@ void GetPeerAddress::asynchronousUpdate() uint16_t port; uint32_t my_ip = NetworkConfig::get()->getMyAddress().getIP(); - if (m_address.getIP() == my_ip) + if (m_address.getIP() == my_ip && !NetworkConfig::m_disable_lan) result->get("private_port", &port); else result->get("port", &port); diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index b5aea6a29..38ee66f35 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -136,6 +136,12 @@ bool StartGameProtocol::notifyEventAsynchronous(Event* event) if (NetworkConfig::get()->isServer() && ready) // on server, player is ready { Log::info("StartGameProtocol", "One of the players is ready."); + if (m_player_states[player_id] != LOADING) + { + Log::error("StartGameProtocol", + "Player %d send more than one ready message.", + player_id); + } m_player_states[player_id] = READY; m_ready_count++; if (m_ready_count == m_game_setup->getPlayerCount()) @@ -159,7 +165,7 @@ void StartGameProtocol::startRace() Protocol *p = ProtocolManager::getInstance() ->getProtocol(PROTOCOL_SYNCHRONIZATION); SynchronizationProtocol* protocol = - static_cast(p); + dynamic_cast(p); if (protocol) { protocol->startCountdown(5.0f); // 5 seconds countdown @@ -185,7 +191,7 @@ void StartGameProtocol::update(float dt) Protocol *p = ProtocolManager::getInstance() ->getProtocol(PROTOCOL_SYNCHRONIZATION); SynchronizationProtocol* protocol = - static_cast(p); + dynamic_cast(p); if (protocol) { // Now the synchronization protocol exists. diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index e1ba50798..d9c4d8523 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -184,7 +184,7 @@ void STKHost::create() * This triggers the creation of the kart selection screen in * CLR::startSelection / CLR::update for all clients. The clients create * the ActivePlayer object (which stores which device is used by which - * plauyer). The kart selection in a client calls + * player). The kart selection in a client calls * (NetworkKartSelection::playerConfirm) which calls CLR::requestKartSelection. * This sends a message to SLR::kartSelectionRequested, which verifies the * selected kart and sends this information to all clients (including the @@ -219,7 +219,7 @@ void STKHost::create() * NULL ActivePlayer (the ActivePlayer is only used for assigning the input * device to each kart, achievements and highscores, so it's not needed for * remote players). It will also start the SynchronizationProtocol. - * The StartGameProtocol has a callback ready which is called from world + * The StartGameProtocol has a callback ready() which is called from world * when the world is loaded (i.e. track and all karts are ready). When * this callback is invoked, each client will send a 'ready' message to * the server's StartGameProtocol. Once the server has received all @@ -228,7 +228,7 @@ void STKHost::create() * sending regular (once per second) pings to the clients and measure * the averate latency. Upon starting the countdown this information * is included in the ping request, so the clients can start the countdown - * at that stage as wellk. + * at that stage as well. * * Once the countdown is 0 (or below), the Synchronization Protocol will * start the protocols: KartUpdateProtocol, ControllerEventsProtocol, diff --git a/src/states_screens/networking_lobby.cpp b/src/states_screens/networking_lobby.cpp index 863cfb1d7..b8c908c5f 100644 --- a/src/states_screens/networking_lobby.cpp +++ b/src/states_screens/networking_lobby.cpp @@ -199,10 +199,11 @@ void NetworkingLobby::tearDown() bool NetworkingLobby::onEscapePressed() { // notify the server that we left - ClientLobbyRoomProtocol* protocol = static_cast( + ClientLobbyRoomProtocol* protocol = dynamic_cast( ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM)); if (protocol) protocol->leave(); + STKHost::get()->shutdown(); return true; // close the screen } // onEscapePressed