Avoid sending to wrong peer in case of disconnection
This commit is contained in:
parent
8e1cc2b0c8
commit
22ca1cb751
@ -63,8 +63,13 @@ void STKPeer::disconnect()
|
||||
*/
|
||||
void STKPeer::sendPacket(NetworkString *data, bool reliable)
|
||||
{
|
||||
data->setToken(m_client_server_token);
|
||||
TransportAddress a(m_enet_peer->address);
|
||||
// Enet will reuse a disconnected peer so we check here to avoid sending
|
||||
// to wrong peer
|
||||
if (m_enet_peer->state != ENET_PEER_STATE_CONNECTED ||
|
||||
a != m_peer_address)
|
||||
return;
|
||||
data->setToken(m_client_server_token);
|
||||
Log::verbose("STKPeer", "sending packet of size %d to %s at %f",
|
||||
data->size(), a.toString().c_str(),StkTime::getRealTime());
|
||||
|
||||
@ -85,13 +90,6 @@ bool STKPeer::isConnected() const
|
||||
return (m_enet_peer->state == ENET_PEER_STATE_CONNECTED);
|
||||
} // isConnected
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool STKPeer::exists() const
|
||||
{
|
||||
return (m_enet_peer != NULL); // assert that the peer exists
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns if this STKPeer is the same as the given peer.
|
||||
*/
|
||||
|
@ -70,7 +70,6 @@ public:
|
||||
bool reliable = true);
|
||||
void disconnect();
|
||||
bool isConnected() const;
|
||||
bool exists() const;
|
||||
const TransportAddress& getAddress() const { return m_peer_address; }
|
||||
bool isSamePeer(const STKPeer* peer) const;
|
||||
bool isSamePeer(const ENetPeer* peer) const;
|
||||
|
Loading…
Reference in New Issue
Block a user