diff --git a/src/network/protocols/connect_to_peer.cpp b/src/network/protocols/connect_to_peer.cpp index 81a2d09b1..9e0ccd206 100644 --- a/src/network/protocols/connect_to_peer.cpp +++ b/src/network/protocols/connect_to_peer.cpp @@ -18,45 +18,20 @@ #include "network/protocols/connect_to_peer.hpp" -#include "network/event.hpp" -#include "network/network_config.hpp" -#include "network/protocols/get_peer_address.hpp" -#include "network/protocols/request_connection.hpp" -#include "network/protocol_manager.hpp" #include "network/stk_host.hpp" #include "utils/time.hpp" #include "utils/log.hpp" // ---------------------------------------------------------------------------- -/** Constructor for a WAN request. In this case we need to get the peer's - * ip address first. - * \param peer_id ID of the peer in the stk client table. - */ -ConnectToPeer::ConnectToPeer(uint32_t peer_id) : Protocol(PROTOCOL_CONNECTION) -{ - m_peer_address.clear(); - m_peer_id = peer_id; - m_state = NONE; -} // ConnectToPeer(peer_id) - -// ---------------------------------------------------------------------------- -/** Constructor for a LAN connection. +/** Constructor for peer address. * \param address The address to connect to. */ ConnectToPeer::ConnectToPeer(const TransportAddress &address) : Protocol(PROTOCOL_CONNECTION) { m_peer_address = address; - // We don't need to find the peer address, so we can start - // with the state when we found the peer address. - m_state = WAIT_FOR_CONNECTION; -} // ConnectToPeers(TransportAddress) - -// ---------------------------------------------------------------------------- - -ConnectToPeer::~ConnectToPeer() -{ -} // ~ConnectToPeer + m_state = WAIT_FOR_CONNECTION; +} // ConnectToPeer // ---------------------------------------------------------------------------- /** Simple finite state machine: Start a GetPeerAddress protocol. Once the @@ -69,35 +44,6 @@ void ConnectToPeer::asynchronousUpdate() { switch(m_state) { - case NONE: - { - m_current_protocol = std::make_shared(m_peer_id); - m_current_protocol->requestStart(); - m_state = RECEIVED_PEER_ADDRESS; - break; - } - case RECEIVED_PEER_ADDRESS: - { - // Wait until we have peer address - auto get_peer_address = - std::dynamic_pointer_cast(m_current_protocol); - assert(get_peer_address); - if (get_peer_address->getAddress().isUnset()) - return; - m_peer_address = get_peer_address->getAddress(); - m_current_protocol = nullptr; - if (m_peer_address.isUnset()) - { - Log::error("ConnectToPeer", - "The peer you want to connect to has hidden his address."); - m_state = DONE; - break; - } - - m_state = WAIT_FOR_CONNECTION; - m_timer = 0.0; - break; - } case WAIT_FOR_CONNECTION: { if (STKHost::get()->peerExists(m_peer_address)) diff --git a/src/network/protocols/connect_to_peer.hpp b/src/network/protocols/connect_to_peer.hpp index 775328252..d9318f681 100644 --- a/src/network/protocols/connect_to_peer.hpp +++ b/src/network/protocols/connect_to_peer.hpp @@ -31,13 +31,6 @@ class ConnectToPeer : public Protocol protected: TransportAddress m_peer_address; - uint32_t m_peer_id; - - /** Pointer to the protocol which is monitored for state changes, this - * need to be shared_ptr because we need to get the result from - * \ref GetPeerAddress, otherwise when it terminated the result will be - * gone. */ - std::shared_ptr m_current_protocol; /** Timer use for tracking broadcast. */ double m_timer = 0.0; @@ -47,18 +40,14 @@ protected: enum STATE { - NONE, - RECEIVED_PEER_ADDRESS, WAIT_FOR_CONNECTION, DONE, EXITING } m_state; public: - ConnectToPeer(uint32_t peer_id); ConnectToPeer(const TransportAddress &address); - virtual ~ConnectToPeer(); - + virtual ~ConnectToPeer() {} virtual void setup() OVERRIDE {} virtual void update(int ticks) OVERRIDE {} virtual void asynchronousUpdate() OVERRIDE; diff --git a/src/network/protocols/get_peer_address.cpp b/src/network/protocols/get_peer_address.cpp deleted file mode 100644 index a462b5a44..000000000 --- a/src/network/protocols/get_peer_address.cpp +++ /dev/null @@ -1,79 +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 "network/protocols/get_peer_address.hpp" - -#include "config/user_config.hpp" -#include "network/network_config.hpp" -#include "network/stk_host.hpp" -#include "online/request_manager.hpp" -#include "online/xml_request.hpp" -#include "utils/log.hpp" - -GetPeerAddress::GetPeerAddress(uint32_t peer_id) - : Protocol(PROTOCOL_SILENT, NULL) -{ - m_peer_id = peer_id; -} // GetPeerAddress - -// ---------------------------------------------------------------------------- -GetPeerAddress::~GetPeerAddress() -{ -} // ~GetPeerAddress - -// ---------------------------------------------------------------------------- -void GetPeerAddress::setup() -{ - m_address.clear(); - m_request = new Online::XMLRequest(); - NetworkConfig::get()->setServerDetails(m_request, "get"); - m_request->addParameter("peer_id", m_peer_id); - - Online::RequestManager::get()->addRequest(m_request); -} // setup - -// ---------------------------------------------------------------------------- -void GetPeerAddress::asynchronousUpdate() -{ - if (m_request->isDone()) - { - const XMLNode * result = m_request->getXMLData(); - - std::string success; - if(result->get("success", &success) && success == "yes") - { - uint32_t ip; - result->get("ip", &ip); - m_address.setIP(ip); - - uint16_t port; - result->get("port", &port); - m_address.setPort(port); - - Log::debug("GetPeerAddress", "Peer address retrieved."); - } - else - { - Log::error("GetPeerAddress", "Failed to get peer address."); - } - requestTerminate(); - - delete m_request; - m_request = NULL; - } -} // asynchronousUpdate diff --git a/src/network/protocols/get_peer_address.hpp b/src/network/protocols/get_peer_address.hpp deleted file mode 100644 index 6a251faba..000000000 --- a/src/network/protocols/get_peer_address.hpp +++ /dev/null @@ -1,56 +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. - -#ifndef GET_PEER_ADDRESS_HPP -#define GET_PEER_ADDRESS_HPP - -#include "network/protocol.hpp" -#include "network/transport_address.hpp" -#include "utils/cpp2011.hpp" - -namespace Online { class XMLRequest; } - -class GetPeerAddress : public Protocol -{ -private: - uint32_t m_peer_id; - Online::XMLRequest* m_request; - - /** 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); - virtual ~GetPeerAddress(); - - virtual void setup() OVERRIDE; - virtual void asynchronousUpdate() OVERRIDE; - void setPeerID(uint32_t peer_id) { m_peer_id = peer_id; } - // ------------------------------------------------------------------------ - /** Returns the address found. */ - const TransportAddress &getAddress() const { return m_address; } - // ------------------------------------------------------------------------ - virtual void update(int ticks) OVERRIDE {} - // ------------------------------------------------------------------------ - virtual bool notifyEvent(Event* event) OVERRIDE { return true; } - // ------------------------------------------------------------------------ - virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; } - -}; // class GetPeerAddress - -#endif // GET_PEER_ADDRESS_HPP diff --git a/src/network/protocols/hide_public_address.cpp b/src/network/protocols/hide_public_address.cpp deleted file mode 100644 index a7e7e3a7f..000000000 --- a/src/network/protocols/hide_public_address.cpp +++ /dev/null @@ -1,77 +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 "network/protocols/hide_public_address.hpp" - -#include "network/network_config.hpp" -#include "online/request_manager.hpp" -#include "online/xml_request.hpp" -#include "utils/log.hpp" - -HidePublicAddress::HidePublicAddress() : Protocol(PROTOCOL_SILENT) -{ -} - -HidePublicAddress::~HidePublicAddress() -{ -} - -void HidePublicAddress::setup() -{ - m_state = NONE; -} - -void HidePublicAddress::asynchronousUpdate() -{ - if (m_state == NONE) - { - m_request = new Online::XMLRequest(); - NetworkConfig::get()->setServerDetails(m_request, "unset"); - 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; - - if(result->get("success", &rec_success)) - { - if(rec_success == "yes") - { - Log::info("HidePublicAddress", "Address hidden successfully."); - } - else - { - Log::error("HidePublicAddress", "Fail to hide address."); - } - } - else - { - Log::error("HidePublicAddress", "Fail to hide address."); - } - m_state = DONE; - } - else if (m_state == DONE) - { - m_state = EXITING; - delete m_request; - m_request = NULL; - requestTerminate(); - } -} diff --git a/src/network/protocols/hide_public_address.hpp b/src/network/protocols/hide_public_address.hpp deleted file mode 100644 index 48adb355c..000000000 --- a/src/network/protocols/hide_public_address.hpp +++ /dev/null @@ -1,56 +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. - -#ifndef HIDE_PUBLIC_ADDRESS_HPP -#define HIDE_PUBLIC_ADDRESS_HPP - -#include "network/protocol.hpp" -#include "utils/cpp2011.hpp" - -#include - -namespace Online { class XMLRequest; } - -class HidePublicAddress : public Protocol -{ -private: - Online::XMLRequest* m_request; - enum STATE - { - NONE, - REQUEST_PENDING, - DONE, - EXITING - }; - STATE m_state; - -public: - HidePublicAddress(); - virtual ~HidePublicAddress(); - - virtual void asynchronousUpdate() OVERRIDE; - virtual void setup() OVERRIDE; - // ------------------------------------------------------------------------ - virtual bool notifyEvent(Event* event) OVERRIDE { return true; } - // ------------------------------------------------------------------------ - virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; } - // ------------------------------------------------------------------------ - virtual void update(int ticks) OVERRIDE {} -}; // class HidePublicAddress - -#endif // HIDE_PUBLIC_ADDRESS_HPP