diff --git a/sources.cmake b/sources.cmake index 83ed5503d..76867d6aa 100644 --- a/sources.cmake +++ b/sources.cmake @@ -1,5 +1,5 @@ # Modify this file to change the last-modified date when you add/remove a file. -# This will then trigger a new cmake run automatically. +# This will then trigger a new cmake run automatically. file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp") file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp") file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*") diff --git a/src/karts/moveable.hpp b/src/karts/moveable.hpp index 4a0599dad..9541eb804 100644 --- a/src/karts/moveable.hpp +++ b/src/karts/moveable.hpp @@ -31,14 +31,13 @@ using namespace irr; #include "physics/user_pointer.hpp" #include "utils/no_copy.hpp" #include "utils/vec3.hpp" -#include "network/types.hpp" class Material; /** * \ingroup karts */ -class Moveable: public NoCopy, public CallbackObject +class Moveable: public NoCopy { private: btVector3 m_velocityLC; /**callback(this); + } // terminated // ------------------------------------------------------------------------ /** Returns the current protocol state. */ ProtocolState getState() const { return m_state; } @@ -139,17 +172,6 @@ public: * \return True if the event has been treated, false otherwise */ virtual bool notifyEventAsynchronous(Event* event) { return false; } // ------------------------------------------------------------------------ - /** \brief Called when the protocol is paused (by an other entity or by - * itself). */ - virtual void paused() { } - // ------------------------------------------------------------------------ - /** \brief Called when the protocol is used. - */ - virtual void unpaused() { } - // ------------------------------------------------------------------------ - /** \brief Called when the protocol is to be killed. */ - virtual void terminated() {} - // ------------------------------------------------------------------------ /** \brief Method to get a protocol's type. * \return The protocol type. */ ProtocolType getProtocolType() const { return m_type; } diff --git a/src/network/protocol_manager.hpp b/src/network/protocol_manager.hpp index 34d766406..cca866f81 100644 --- a/src/network/protocol_manager.hpp +++ b/src/network/protocol_manager.hpp @@ -123,6 +123,10 @@ class ProtocolManager : public AbstractSingleton, virtual void requestPause(Protocol* protocol); virtual void requestUnpause(Protocol* protocol); virtual void requestTerminate(Protocol* protocol); + virtual void startProtocol(Protocol *protocol); + virtual void pauseProtocol(Protocol *protocol); + virtual void unpauseProtocol(Protocol *protocol); + virtual void terminateProtocol(Protocol *protocol); virtual void update(); virtual void asynchronousUpdate(); virtual uint32_t getProtocolID(Protocol* protocol); @@ -142,11 +146,6 @@ class ProtocolManager : public AbstractSingleton, virtual ~ProtocolManager(); uint32_t getNextProtocolId(); - virtual void startProtocol(Protocol *protocol); - virtual void pauseProtocol(Protocol *protocol); - virtual void unpauseProtocol(Protocol *protocol); - virtual void terminateProtocol(Protocol *protocol); - bool sendEvent(EventProcessingInfo* event, bool synchronous); // protected members diff --git a/src/network/protocols/connect_to_peer.cpp b/src/network/protocols/connect_to_peer.cpp index 9309ae85b..5aaab2f4d 100644 --- a/src/network/protocols/connect_to_peer.cpp +++ b/src/network/protocols/connect_to_peer.cpp @@ -32,8 +32,7 @@ // ---------------------------------------------------------------------------- -ConnectToPeer::ConnectToPeer(uint32_t peer_id) - : Protocol(NULL, PROTOCOL_CONNECTION) +ConnectToPeer::ConnectToPeer(uint32_t peer_id) : Protocol(PROTOCOL_CONNECTION) { m_peer_id = peer_id; m_state = NONE; @@ -78,47 +77,52 @@ void ConnectToPeer::asynchronousUpdate() { case NONE: { - m_current_protocol = new GetPeerAddress(m_peer_id, &m_peer_address); - ProtocolManager::getInstance()->requestStart(m_current_protocol); - m_state = WAITING_PEER_ADDRESS; + m_current_protocol = new GetPeerAddress(m_peer_id, this); + ProtocolManager::getInstance()->requestStart(m_current_protocol);; + + // Pause this protocol till we receive an answer + // The GetPeerAddress protocol will change the state and + // unpause this protocol + ProtocolManager::getInstance()->pauseProtocol(this); break; } - case WAITING_PEER_ADDRESS: - // Wait till we know the peer address - if (m_current_protocol->getState()== PROTOCOL_STATE_TERMINATED) + case RECEIVED_PEER_ADDRESS: + { + if (m_peer_address.getIP() == 0 || m_peer_address.getPort() == 0) { - if (m_peer_address.getIP() != 0 && m_peer_address.getPort() != 0) - { - // we're in the same lan (same public ip address) !! - if (m_peer_address.getIP() == STKHost::get()->getPublicAddress().getIP()) - { - // just send a broadcast packet with the string aloha_stk inside, the client will know our ip address and will connect - TransportAddress broadcast_address; - broadcast_address.setIP(-1); // 255.255.255.255 - broadcast_address.setPort(m_peer_address.getPort()); // 0b10101100000101101101111111111111; // for test - char data[] = "aloha_stk\0"; - STKHost::get()->sendRawPacket((uint8_t*)(data), 10, broadcast_address); - Log::info("ConnectToPeer", "Broadcast aloha sent."); - StkTime::sleep(1); - broadcast_address.setIP(0x7f000001); // 127.0.0.1 (localhost) - broadcast_address.setPort(m_peer_address.getPort()); - STKHost::get()->sendRawPacket((uint8_t*)(data), 10, broadcast_address); - Log::info("ConnectToPeer", "Broadcast aloha to self."); - } - else - { - m_current_protocol = new PingProtocol(m_peer_address, 2.0); - ProtocolManager::getInstance()->requestStart(m_current_protocol); - } - m_state = CONNECTING; - } - else - { - Log::error("ConnectToPeer", "The peer you want to connect to has hidden his address."); - m_state = DONE; - } + Log::error("ConnectToPeer", + "The peer you want to connect to has hidden his address."); + m_state = DONE; + break; } + + // Now we know the peer address. If it's a non-local host, start + // the Ping protocol to keep the port available. + if (m_peer_address.getIP() != STKHost::get()->getPublicAddress().getIP()) + { + m_current_protocol = new PingProtocol(m_peer_address, 2.0); + ProtocolManager::getInstance()->requestStart(m_current_protocol); + m_state = CONNECTING; + break; + } + + // Otherwise we are in the same LAN (same public ip address) !! + // just send a broadcast packet with the string aloha_stk inside, + // the client will know our ip address and will connect + TransportAddress broadcast_address; + broadcast_address.setIP(-1); // 255.255.255.255 + broadcast_address.setPort(m_peer_address.getPort()); // 0b10101100000101101101111111111111; // for test + char data[] = "aloha_stk\0"; + STKHost::get()->sendRawPacket((uint8_t*)(data), 10, broadcast_address); + Log::info("ConnectToPeer", "Broadcast aloha sent."); + StkTime::sleep(1); + broadcast_address.setIP(0x7f000001); // 127.0.0.1 (localhost) + broadcast_address.setPort(m_peer_address.getPort()); + STKHost::get()->sendRawPacket((uint8_t*)(data), 10, broadcast_address); + Log::info("ConnectToPeer", "Broadcast aloha to self."); + m_state = CONNECTING; break; + } case CONNECTING: // waiting the peer to connect break; case CONNECTED: @@ -143,4 +147,11 @@ void ConnectToPeer::asynchronousUpdate() } // asynchronousUpdate // ---------------------------------------------------------------------------- - +/** Callback from the GetPeerAddress protocol + */ +void ConnectToPeer::callback(Protocol *protocol) +{ + m_peer_address.copy( ((GetPeerAddress*)protocol)->getAddress() ); + // Reactivate this protocol + ProtocolManager::getInstance()->unpauseProtocol(this); +} // callback \ No newline at end of file diff --git a/src/network/protocols/connect_to_peer.hpp b/src/network/protocols/connect_to_peer.hpp index 4d2cd0ab1..a74efeeb8 100644 --- a/src/network/protocols/connect_to_peer.hpp +++ b/src/network/protocols/connect_to_peer.hpp @@ -21,6 +21,8 @@ #include "network/protocol.hpp" #include "network/types.hpp" +#include "utils/cpp2011.hpp" + #include class ConnectToPeer : public Protocol, public CallbackObject @@ -36,7 +38,7 @@ protected: enum STATE { NONE, - WAITING_PEER_ADDRESS, + RECEIVED_PEER_ADDRESS, CONNECTING, CONNECTED, DONE, @@ -52,7 +54,7 @@ public: virtual void setup(); virtual void update() {} virtual void asynchronousUpdate(); - -}; + virtual void callback(Protocol *protocol) OVERRIDE; +}; // class ConnectToPeer #endif // CONNECT_TO_SERVER_HPP diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp index 3b28a7cb0..51496206b 100644 --- a/src/network/protocols/connect_to_server.cpp +++ b/src/network/protocols/connect_to_server.cpp @@ -18,6 +18,7 @@ #include "network/protocols/connect_to_server.hpp" +#include "config/player_manager.hpp" #include "network/event.hpp" #include "network/protocols/get_public_address.hpp" #include "network/protocols/get_peer_address.hpp" @@ -25,8 +26,8 @@ #include "network/protocols/hide_public_address.hpp" #include "network/protocols/request_connection.hpp" #include "network/protocols/ping_protocol.hpp" -#include "network/protocols/quick_join_protocol.hpp" #include "network/protocols/client_lobby_room_protocol.hpp" +#include "network/protocol_manager.hpp" #include "network/stk_host.hpp" #include "network/stk_peer.hpp" #include "utils/time.hpp" @@ -39,9 +40,10 @@ #endif // ---------------------------------------------------------------------------- -/** Quick join/ +/** Connects to a server. This is the quick connect constructor, which + * will pick a server randomly. */ -ConnectToServer::ConnectToServer() : Protocol(NULL, PROTOCOL_CONNECTION) +ConnectToServer::ConnectToServer() : Protocol(PROTOCOL_CONNECTION) { m_server_id = 0; m_host_id = 0; @@ -55,7 +57,7 @@ ConnectToServer::ConnectToServer() : Protocol(NULL, PROTOCOL_CONNECTION) * \param host_id Id of host. */ ConnectToServer::ConnectToServer(uint32_t server_id, uint32_t host_id) - : Protocol(NULL, PROTOCOL_CONNECTION) + : Protocol(PROTOCOL_CONNECTION) { m_server_id = server_id; m_host_id = host_id; @@ -84,6 +86,8 @@ bool ConnectToServer::notifyEventAsynchronous(Event* event) } // notifyEventAsynchronous // ---------------------------------------------------------------------------- +/** Initialise the protocol. + */ void ConnectToServer::setup() { Log::info("ConnectToServer", "SETUP"); @@ -110,6 +114,7 @@ void ConnectToServer::asynchronousUpdate() if (m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED) { m_state = SHOWING_SELF_ADDRESS; + delete m_current_protocol; m_current_protocol = new ShowPublicAddress(); m_current_protocol->requestStart(); Log::info("ConnectToServer", "Public address known"); @@ -118,28 +123,30 @@ void ConnectToServer::asynchronousUpdate() case SHOWING_SELF_ADDRESS: if (m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED) { + delete m_current_protocol; + + m_current_protocol = NULL; // now our public address is in the database Log::info("ConnectToServer", "Public address shown"); if (m_quick_join) { - m_current_protocol = new QuickJoinProtocol(&m_server_address, - &m_server_id); - m_current_protocol->requestStart(); - m_state = REQUESTING_CONNECTION; + handleQuickConnect(); } else { - m_current_protocol = new GetPeerAddress(m_host_id, - &m_server_address); + m_current_protocol = new GetPeerAddress(m_host_id, this); m_current_protocol->requestStart(); m_state = GETTING_SERVER_ADDRESS; + // Pause this protocol till GetPeerAddress finishes. + // The callback then will unpause this protocol/ + ProtocolManager::getInstance()->pauseProtocol(this); } } break; case GETTING_SERVER_ADDRESS: - // Wait till we know the server address - if (m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED) { + if(m_current_protocol) + delete m_current_protocol; Log::info("ConnectToServer", "Server's address known"); // we're in the same lan (same public ip address) !! if (m_server_address.getIP() == @@ -229,7 +236,52 @@ void ConnectToServer::asynchronousUpdate() case EXITING: break; } -} +} // asynchronousUpdate + + // ---------------------------------------------------------------------------- +/** Called when the GetPeerAddress protocol terminates. +*/ +void ConnectToServer::callback(Protocol *protocol) +{ + ProtocolManager::getInstance()->unpauseProtocol(this); +} // callback + +// ---------------------------------------------------------------------------- +/** Called to request a quick connect from the STK server. + */ +void ConnectToServer::handleQuickConnect() +{ + Online::XMLRequest *request = new Online::XMLRequest(); + PlayerManager::setUserDetails(request, "quick-join", + Online::API::SERVER_PATH); + request->executeNow(); + + const XMLNode * result = request->getXMLData(); + delete request; + std::string success; + + if(result->get("success", &success) && success=="yes") + { + uint32_t ip; + result->get("ip", &ip); + m_server_address.setIP(ip); + + uint16_t port; + // If we are using a LAN connection, we need the private (local) port + if (m_server_address.getIP() == STKHost::get()->getPublicAddress().getIP()) + result->get("private_port", &port); + else + result->get("port", &port); + + m_server_address.setPort(port); + + Log::debug("GetPeerAddress", "Address gotten successfully."); + } + else + { + Log::error("GetPeerAddress", "Fail to get address."); + } +} // handleQuickConnect // ---------------------------------------------------------------------------- /** Called when the server is on the same LAN. It uses broadcast to diff --git a/src/network/protocols/connect_to_server.hpp b/src/network/protocols/connect_to_server.hpp index fba1135f1..eaab38e4e 100644 --- a/src/network/protocols/connect_to_server.hpp +++ b/src/network/protocols/connect_to_server.hpp @@ -42,25 +42,29 @@ private: SHOWING_SELF_ADDRESS, GETTING_SERVER_ADDRESS, REQUESTING_CONNECTION, + QUICK_JOIN, CONNECTING, CONNECTED, HIDING_ADDRESS, DONE, EXITING }; + /** State for finite state machine. */ State m_state; + void handleQuickConnect(); void handleSameLAN(); public: - ConnectToServer(); - ConnectToServer(uint32_t server_id, uint32_t host_id); + ConnectToServer(); + ConnectToServer(uint32_t server_id, uint32_t host_id); virtual ~ConnectToServer(); virtual bool notifyEventAsynchronous(Event* event) OVERRIDE; virtual void setup() OVERRIDE; virtual void asynchronousUpdate(); + virtual void callback(Protocol *protocol); virtual void update() OVERRIDE {} }; // class ConnectToServer diff --git a/src/network/protocols/controller_events_protocol.cpp b/src/network/protocols/controller_events_protocol.cpp index ba65054d5..a7bcbce40 100644 --- a/src/network/protocols/controller_events_protocol.cpp +++ b/src/network/protocols/controller_events_protocol.cpp @@ -13,8 +13,8 @@ //----------------------------------------------------------------------------- -ControllerEventsProtocol::ControllerEventsProtocol() : - Protocol(NULL, PROTOCOL_CONTROLLER_EVENTS) +ControllerEventsProtocol::ControllerEventsProtocol() + : Protocol( PROTOCOL_CONTROLLER_EVENTS) { } diff --git a/src/network/protocols/game_events_protocol.cpp b/src/network/protocols/game_events_protocol.cpp index d071fd138..4777e22fa 100644 --- a/src/network/protocols/game_events_protocol.cpp +++ b/src/network/protocols/game_events_protocol.cpp @@ -14,7 +14,7 @@ #include -GameEventsProtocol::GameEventsProtocol() : Protocol(NULL, PROTOCOL_GAME_EVENTS) +GameEventsProtocol::GameEventsProtocol() : Protocol(PROTOCOL_GAME_EVENTS) { } diff --git a/src/network/protocols/get_peer_address.cpp b/src/network/protocols/get_peer_address.cpp index 7662b792c..45580055f 100644 --- a/src/network/protocols/get_peer_address.cpp +++ b/src/network/protocols/get_peer_address.cpp @@ -26,7 +26,7 @@ #include "utils/log.hpp" GetPeerAddress::GetPeerAddress(uint32_t peer_id, CallbackObject* callback_object) - : Protocol(callback_object, PROTOCOL_SILENT) + : Protocol(PROTOCOL_SILENT, callback_object) { m_peer_id = peer_id; } // GetPeerAddress @@ -39,8 +39,9 @@ GetPeerAddress::~GetPeerAddress() // ---------------------------------------------------------------------------- void GetPeerAddress::setup() { - m_state = NONE; + m_state = NONE; m_request = NULL; + m_address.clear(); } // setup // ---------------------------------------------------------------------------- @@ -65,18 +66,17 @@ void GetPeerAddress::asynchronousUpdate() { if (rec_success == "yes") { - TransportAddress* addr = static_cast(m_callback_object); uint32_t ip; result->get("ip", &ip); - addr->setIP(ip); + m_address.setIP(ip); uint16_t port; - if (addr->getIP() == + if (m_address.getIP() == STKHost::get()->getPublicAddress().getIP()) result->get("private_port", &port); else result->get("port", &port); - addr->setPort(port); + m_address.setPort(port); Log::debug("GetPeerAddress", "Address gotten successfully."); } diff --git a/src/network/protocols/get_peer_address.hpp b/src/network/protocols/get_peer_address.hpp index da2d4e9e2..bda7e857c 100644 --- a/src/network/protocols/get_peer_address.hpp +++ b/src/network/protocols/get_peer_address.hpp @@ -38,6 +38,9 @@ private: }; STATE m_state; + /** Stores the address found. Used in a callback from the parent protocol + * to get the result. */ + TransportAddress m_address; public: GetPeerAddress(uint32_t peer_id, CallbackObject* callback_object); virtual ~GetPeerAddress(); @@ -46,6 +49,9 @@ public: virtual void asynchronousUpdate(); void setPeerID(uint32_t m_peer_id); + // ------------------------------------------------------------------------ + /** Returns the address found. */ + const TransportAddress &getAddress() const { return m_address; } // ------------------------------------------------------------------------ virtual void update() {} // ------------------------------------------------------------------------ diff --git a/src/network/protocols/get_public_address.cpp b/src/network/protocols/get_public_address.cpp index 86e64d11e..d3ad7c8e7 100644 --- a/src/network/protocols/get_public_address.cpp +++ b/src/network/protocols/get_public_address.cpp @@ -44,8 +44,7 @@ // make the linker happy const uint32_t GetPublicAddress::m_stun_magic_cookie = 0x2112A442; -GetPublicAddress::GetPublicAddress() - : Protocol(NULL, PROTOCOL_SILENT) +GetPublicAddress::GetPublicAddress() : Protocol(PROTOCOL_SILENT) { m_state = NOTHING_DONE; } // GetPublicAddress diff --git a/src/network/protocols/hide_public_address.cpp b/src/network/protocols/hide_public_address.cpp index 44b7393c0..e245431f6 100644 --- a/src/network/protocols/hide_public_address.cpp +++ b/src/network/protocols/hide_public_address.cpp @@ -24,7 +24,7 @@ #include "online/request_manager.hpp" #include "utils/log.hpp" -HidePublicAddress::HidePublicAddress() : Protocol(NULL, PROTOCOL_SILENT) +HidePublicAddress::HidePublicAddress() : Protocol(PROTOCOL_SILENT) { } diff --git a/src/network/protocols/kart_update_protocol.cpp b/src/network/protocols/kart_update_protocol.cpp index fad08ed5a..043e6801e 100644 --- a/src/network/protocols/kart_update_protocol.cpp +++ b/src/network/protocols/kart_update_protocol.cpp @@ -8,8 +8,7 @@ #include "network/stk_host.hpp" #include "utils/time.hpp" -KartUpdateProtocol::KartUpdateProtocol() - : Protocol(NULL, PROTOCOL_KART_UPDATE) +KartUpdateProtocol::KartUpdateProtocol() : Protocol(PROTOCOL_KART_UPDATE) { m_karts = World::getWorld()->getKarts(); for (unsigned int i = 0; i < m_karts.size(); i++) diff --git a/src/network/protocols/lobby_room_protocol.cpp b/src/network/protocols/lobby_room_protocol.cpp index 28ea342bd..447aee5fb 100644 --- a/src/network/protocols/lobby_room_protocol.cpp +++ b/src/network/protocols/lobby_room_protocol.cpp @@ -18,8 +18,8 @@ #include "network/protocols/lobby_room_protocol.hpp" -LobbyRoomProtocol::LobbyRoomProtocol(CallbackObject* callback_object) : - Protocol(callback_object, PROTOCOL_LOBBY_ROOM) +LobbyRoomProtocol::LobbyRoomProtocol(CallbackObject* callback_object) + : Protocol(PROTOCOL_LOBBY_ROOM, callback_object) { m_setup = NULL; } diff --git a/src/network/protocols/ping_protocol.cpp b/src/network/protocols/ping_protocol.cpp index 15b6790d5..ceb7989be 100644 --- a/src/network/protocols/ping_protocol.cpp +++ b/src/network/protocols/ping_protocol.cpp @@ -21,8 +21,9 @@ #include "network/stk_host.hpp" #include "utils/time.hpp" -PingProtocol::PingProtocol(const TransportAddress& ping_dst, double delay_between_pings) - : Protocol(NULL, PROTOCOL_SILENT) +PingProtocol::PingProtocol(const TransportAddress& ping_dst, + double delay_between_pings) + : Protocol(PROTOCOL_SILENT) { m_ping_dst.copy(ping_dst); m_delay_between_pings = delay_between_pings; diff --git a/src/network/protocols/quick_join_protocol.cpp b/src/network/protocols/quick_join_protocol.cpp deleted file mode 100644 index 515438474..000000000 --- a/src/network/protocols/quick_join_protocol.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013-2015 SuperTuxKart-Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include "quick_join_protocol.hpp" - -#include "config/player_manager.hpp" -#include "config/user_config.hpp" -#include "network/stk_host.hpp" -#include "online/request_manager.hpp" -#include "utils/log.hpp" - -QuickJoinProtocol::QuickJoinProtocol(CallbackObject* callback_object, uint32_t* server_id) : Protocol(callback_object, PROTOCOL_SILENT) -{ - m_server_id = server_id; -} - -QuickJoinProtocol::~QuickJoinProtocol() -{ -} - -void QuickJoinProtocol::setup() -{ - m_state = NONE; -} - -void QuickJoinProtocol::asynchronousUpdate() -{ - if (m_state == NONE) - { - const TransportAddress& addr = STKHost::get()->getPublicAddress(); - m_request = new Online::XMLRequest(); - PlayerManager::setUserDetails(m_request, "quick-join", Online::API::SERVER_PATH); - - Online::RequestManager::get()->addRequest(m_request); - m_state = REQUEST_PENDING; - } - else if (m_state == REQUEST_PENDING && m_request->isDone()) - { - const XMLNode * result = m_request->getXMLData(); - std::string rec_success; - TransportAddress* res = static_cast(m_callback_object); - - if(result->get("success", &rec_success)) - { - if(rec_success == "yes") - { - uint32_t ip; - result->get("ip", &ip); - res->setIP(ip); - uint16_t port; - result->get("port", &port); - res->setPort(port); - result->get("hostid", m_server_id); - Log::info("QuickJoinProtocol", "Quick joining %s (server#%d).", - res->toString().c_str(), *m_server_id); - } - else - { - Log::error("QuickJoinProtocol", "Fail to quick join."); - } - } - else - { - Log::error("QuickJoinProtocol", "Fail to quick join."); - } - m_state = DONE; - } - else if (m_state == DONE) - { - m_state = EXITING; - delete m_request; - m_request = NULL; - requestTerminate(); - } -} diff --git a/src/network/protocols/quick_join_protocol.hpp b/src/network/protocols/quick_join_protocol.hpp deleted file mode 100644 index f7f374d97..000000000 --- a/src/network/protocols/quick_join_protocol.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef QUICK_JOIN_PROTOCOL_HPP -#define QUICK_JOIN_PROTOCOL_HPP - -#include "network/protocol.hpp" - -namespace Online { class XMLRequest; } - -class QuickJoinProtocol : public Protocol -{ - public: - QuickJoinProtocol(CallbackObject* callback_object, uint32_t* server_id); - virtual ~QuickJoinProtocol(); - - virtual bool notifyEvent(Event* event) { return true; } - virtual bool notifyEventAsynchronous(Event* event) { return true; } - virtual void setup(); - virtual void update() {} - virtual void asynchronousUpdate(); - - protected: - uint32_t* m_server_id; - Online::XMLRequest* m_request; - enum STATE - { - NONE, - REQUEST_PENDING, - DONE, - EXITING - }; - STATE m_state; -}; - -#endif // QUICK_JOIN_PROTOCOL_HPP diff --git a/src/network/protocols/request_connection.cpp b/src/network/protocols/request_connection.cpp index e7608f121..feadea532 100644 --- a/src/network/protocols/request_connection.cpp +++ b/src/network/protocols/request_connection.cpp @@ -29,7 +29,7 @@ using namespace Online; * \param server_id Id of the server. */ RequestConnection::RequestConnection(uint32_t server_id) - : Protocol(NULL, PROTOCOL_SILENT) + : Protocol(PROTOCOL_SILENT) { m_server_id = server_id; } // RequestConnection diff --git a/src/network/protocols/show_public_address.cpp b/src/network/protocols/show_public_address.cpp index 5db5799a0..6286fad13 100644 --- a/src/network/protocols/show_public_address.cpp +++ b/src/network/protocols/show_public_address.cpp @@ -24,7 +24,7 @@ #include "online/request_manager.hpp" #include "utils/log.hpp" -ShowPublicAddress::ShowPublicAddress() : Protocol(NULL, PROTOCOL_SILENT) +ShowPublicAddress::ShowPublicAddress() : Protocol(PROTOCOL_SILENT) { } diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index be9349293..eefea582b 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -21,7 +21,7 @@ #include "utils/time.hpp" StartGameProtocol::StartGameProtocol(GameSetup* game_setup) - : Protocol(NULL, PROTOCOL_START_GAME) + : Protocol(PROTOCOL_START_GAME) { m_game_setup = game_setup; std::vector players = m_game_setup->getPlayers(); diff --git a/src/network/protocols/stop_server.cpp b/src/network/protocols/stop_server.cpp index f34c6deab..ea20d5c53 100644 --- a/src/network/protocols/stop_server.cpp +++ b/src/network/protocols/stop_server.cpp @@ -23,7 +23,7 @@ #include "network/stk_host.hpp" #include "online/request_manager.hpp" -StopServer::StopServer() : Protocol(NULL, PROTOCOL_SILENT) +StopServer::StopServer() : Protocol(PROTOCOL_SILENT) { } diff --git a/src/network/protocols/synchronization_protocol.cpp b/src/network/protocols/synchronization_protocol.cpp index 80020fb08..fd37464e2 100644 --- a/src/network/protocols/synchronization_protocol.cpp +++ b/src/network/protocols/synchronization_protocol.cpp @@ -10,7 +10,8 @@ //----------------------------------------------------------------------------- -SynchronizationProtocol::SynchronizationProtocol() : Protocol(NULL, PROTOCOL_SYNCHRONIZATION) +SynchronizationProtocol::SynchronizationProtocol() + : Protocol(PROTOCOL_SYNCHRONIZATION) { unsigned int size = STKHost::get()->getPeerCount(); m_pings.resize(size, std::map()); diff --git a/src/network/types.hpp b/src/network/types.hpp index dbb3fb84c..b4ff0beb8 100644 --- a/src/network/types.hpp +++ b/src/network/types.hpp @@ -30,24 +30,12 @@ #include -// ============================================================================ -/*! \class CallbackObject - * \brief Class that must be inherited to pass objects to protocols. - */ -class CallbackObject -{ - public: - CallbackObject() {} - ~CallbackObject() {} - -}; // CallbackObject - // ============================================================================ /*! \class TransportAddress * \brief Describes a transport-layer address. * For IP networks, a transport address is the couple ip:port. */ -class TransportAddress : public CallbackObject, public NoCopy +class TransportAddress : public NoCopy { private: uint32_t m_ip; //!< The IPv4 address