Converted the CallbackObject to actually call a function. This
means that if protocol A starts protocol B and needs a result from B, previously B would set a (potential private) variable in A. Now B calls a callback in A, where the result can be set.
This commit is contained in:
parent
966d31dc45
commit
83154ae3a7
@ -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; /**<Velocity in kart coordinates. */
|
||||
|
@ -31,7 +31,7 @@
|
||||
* it to NULL.
|
||||
* \param type The type of the protocol.
|
||||
*/
|
||||
Protocol::Protocol(CallbackObject* callback_object, ProtocolType type)
|
||||
Protocol::Protocol(ProtocolType type, CallbackObject* callback_object)
|
||||
{
|
||||
m_callback_object = callback_object;
|
||||
m_type = type;
|
||||
|
@ -63,7 +63,22 @@ enum ProtocolState
|
||||
PROTOCOL_STATE_TERMINATED //!< The protocol is terminated/does not exist.
|
||||
}; // ProtocolState
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class Protocol;
|
||||
|
||||
// ============================================================================*
|
||||
/** \class CallbackObject
|
||||
* \brief Class that must be inherited to pass objects to protocols.
|
||||
*/
|
||||
class CallbackObject
|
||||
{
|
||||
public:
|
||||
CallbackObject() {}
|
||||
virtual ~CallbackObject() {}
|
||||
|
||||
virtual void callback(Protocol *protocol) = 0;
|
||||
}; // CallbackObject
|
||||
|
||||
// ============================================================================
|
||||
/** \class Protocol
|
||||
* \brief Abstract class used to define the global protocol functions.
|
||||
* A protocol is an entity that is started at a point, and that is updated
|
||||
@ -89,12 +104,13 @@ protected:
|
||||
uint32_t m_id;
|
||||
|
||||
public:
|
||||
|
||||
Protocol(CallbackObject* callback_object, ProtocolType type);
|
||||
Protocol(ProtocolType type, CallbackObject* callback_object=NULL);
|
||||
virtual ~Protocol();
|
||||
|
||||
/** \brief Called when the protocol is going to start. Must be re-defined
|
||||
* by subclasses. */
|
||||
virtual void setup() = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** \brief Called by the protocol listener, synchronously with the main
|
||||
* loop. Must be re-defined.*/
|
||||
@ -115,6 +131,23 @@ public:
|
||||
bool reliable = true);
|
||||
void requestStart();
|
||||
void requestTerminate();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** \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 was just killed. It triggers the
|
||||
* callback if defined. */
|
||||
virtual void terminated()
|
||||
{
|
||||
if (m_callback_object)
|
||||
m_callback_object->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; }
|
||||
|
@ -123,6 +123,10 @@ class ProtocolManager : public AbstractSingleton<ProtocolManager>,
|
||||
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<ProtocolManager>,
|
||||
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
|
||||
|
@ -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
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "network/protocol.hpp"
|
||||
#include "network/types.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ControllerEventsProtocol::ControllerEventsProtocol() :
|
||||
Protocol(NULL, PROTOCOL_CONTROLLER_EVENTS)
|
||||
ControllerEventsProtocol::ControllerEventsProtocol()
|
||||
: Protocol( PROTOCOL_CONTROLLER_EVENTS)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
GameEventsProtocol::GameEventsProtocol() : Protocol(NULL, PROTOCOL_GAME_EVENTS)
|
||||
GameEventsProtocol::GameEventsProtocol() : Protocol(PROTOCOL_GAME_EVENTS)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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<TransportAddress*>(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.");
|
||||
}
|
||||
|
@ -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() {}
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "online/request_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
HidePublicAddress::HidePublicAddress() : Protocol(NULL, PROTOCOL_SILENT)
|
||||
HidePublicAddress::HidePublicAddress() : Protocol(PROTOCOL_SILENT)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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++)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<TransportAddress*>(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();
|
||||
}
|
||||
}
|
@ -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
|
@ -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
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "online/request_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
ShowPublicAddress::ShowPublicAddress() : Protocol(NULL, PROTOCOL_SILENT)
|
||||
ShowPublicAddress::ShowPublicAddress() : Protocol(PROTOCOL_SILENT)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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<NetworkPlayerProfile*> players = m_game_setup->getPlayers();
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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<uint32_t,double>());
|
||||
|
@ -30,24 +30,12 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
// ============================================================================
|
||||
/*! \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
|
||||
|
Loading…
Reference in New Issue
Block a user