Moved NetworkManager::connect and STKPeer::connextTo functions into STKHost.
This commit is contained in:
parent
0bd2b48ea0
commit
51d39879b4
@ -39,15 +39,3 @@ void NetworkManager::run()
|
||||
{
|
||||
} // run
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** \brief Try to establish a connection to a given transport address.
|
||||
* \param peer : The transport address which you want to connect to.
|
||||
* \return True if we're successfully connected. False elseway.
|
||||
*/
|
||||
bool NetworkManager::connect(const TransportAddress& address)
|
||||
{
|
||||
if (STKHost::get()->peerExists(address))
|
||||
return isConnectedTo(address);
|
||||
|
||||
return STKPeer::connectToHost(STKHost::get(), address, 2, 0);
|
||||
} // connect
|
||||
|
@ -60,7 +60,6 @@ private:
|
||||
friend class AbstractSingleton<NetworkManager>;
|
||||
public:
|
||||
virtual void run();
|
||||
virtual bool connect(const TransportAddress& peer);
|
||||
virtual void sendPacket(const NetworkString& data,
|
||||
bool reliable = true) = 0;
|
||||
// Game related functions
|
||||
|
@ -188,7 +188,7 @@ void ConnectToServer::asynchronousUpdate()
|
||||
if (StkTime::getRealTime() > timer+5.0) // every 5 seconds
|
||||
{
|
||||
timer = StkTime::getRealTime();
|
||||
NetworkManager::getInstance()->connect(m_server_address);
|
||||
STKHost::get()->connect(m_server_address);
|
||||
Log::info("ConnectToServer", "Trying to connect to %s",
|
||||
m_server_address.toString().c_str());
|
||||
}
|
||||
|
@ -157,6 +157,28 @@ void STKHost::abort()
|
||||
ProtocolManager::getInstance()->abort();
|
||||
} // abort
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** \brief Try to establish a connection to a given transport address.
|
||||
* \param peer : The transport address which you want to connect to.
|
||||
* \return True if we're successfully connected. False elseway.
|
||||
*/
|
||||
bool STKHost::connect(const TransportAddress& address)
|
||||
{
|
||||
if (peerExists(address))
|
||||
return isConnectedTo(address);
|
||||
|
||||
ENetPeer* peer = connectTo(address);
|
||||
|
||||
if (peer == NULL)
|
||||
{
|
||||
Log::error("STKHost", "Could not try to connect to server.");
|
||||
return false;
|
||||
}
|
||||
TransportAddress a(peer->address);
|
||||
Log::verbose("STKPeer", "Connecting to %s", a.toString().c_str());
|
||||
return true;
|
||||
} // connect
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** \brief Starts the listening of events from ENet.
|
||||
* Starts a thread for receiveData that updates it as often as possible.
|
||||
|
@ -125,8 +125,10 @@ public:
|
||||
virtual GameSetup* setupNewGame();
|
||||
void setPublicAddress(const TransportAddress& addr);
|
||||
void abort();
|
||||
void deleteAllPeers ();
|
||||
void deleteAllPeers();
|
||||
void reset();
|
||||
bool connect(const TransportAddress& peer);
|
||||
|
||||
void sendPacketExcept(STKPeer* peer,
|
||||
const NetworkString& data,
|
||||
bool reliable = true);
|
||||
|
@ -47,24 +47,6 @@ STKPeer::~STKPeer()
|
||||
m_client_server_token = 0;
|
||||
} // ~STKPeer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Connect to the specified host.
|
||||
*/
|
||||
bool STKPeer::connectToHost(STKHost* localhost, const TransportAddress &address,
|
||||
uint32_t channel_count, uint32_t data)
|
||||
{
|
||||
ENetPeer* peer = localhost->connectTo(address);
|
||||
|
||||
if (peer == NULL)
|
||||
{
|
||||
Log::error("STKPeer", "Could not try to connect to server.\n");
|
||||
return false;
|
||||
}
|
||||
TransportAddress a(peer->address);
|
||||
Log::verbose("STKPeer", "Connecting to %s", a.toString().c_str());
|
||||
return true;
|
||||
} // connectToHost
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Disconnect from the server.
|
||||
*/
|
||||
|
@ -57,8 +57,6 @@ public:
|
||||
virtual ~STKPeer();
|
||||
|
||||
virtual void sendPacket(const NetworkString& data, bool reliable = true);
|
||||
static bool connectToHost(STKHost* localhost, const TransportAddress& host,
|
||||
uint32_t channel_count, uint32_t data);
|
||||
void disconnect();
|
||||
bool isConnected() const;
|
||||
bool exists() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user