sync work
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13173 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
b00bb5c050
commit
7665f30828
@ -76,6 +76,7 @@ Event::Event(ENetEvent* event)
|
|||||||
|
|
||||||
Event::Event(const Event& event)
|
Event::Event(const Event& event)
|
||||||
{
|
{
|
||||||
|
Log::verbose("Event", "Constructing a copy of the event.");
|
||||||
m_packet = NULL;
|
m_packet = NULL;
|
||||||
data = event.data;
|
data = event.data;
|
||||||
// copy the peer
|
// copy the peer
|
||||||
|
@ -92,7 +92,7 @@ void NetworkManager::notifyEvent(Event* event)
|
|||||||
|
|
||||||
if (event->type == EVENT_TYPE_CONNECTED)
|
if (event->type == EVENT_TYPE_CONNECTED)
|
||||||
{
|
{
|
||||||
Log::debug("NetworkManager", "A client has just connected. There are now %lu peers.", m_peers.size() + 1);
|
Log::info("NetworkManager", "A client has just connected. There are now %lu peers.", m_peers.size() + 1);
|
||||||
Log::verbose("NetworkManager", "Address of event->peer after connection : %ld", (long int)(event->peer));
|
Log::verbose("NetworkManager", "Address of event->peer after connection : %ld", (long int)(event->peer));
|
||||||
// create the new peer:
|
// create the new peer:
|
||||||
m_peers.push_back(event->peer);
|
m_peers.push_back(event->peer);
|
||||||
@ -119,14 +119,14 @@ void NetworkManager::notifyEvent(Event* event)
|
|||||||
for (unsigned int i = 0; i < m_peers.size(); i++)
|
for (unsigned int i = 0; i < m_peers.size(); i++)
|
||||||
{
|
{
|
||||||
Log::error("NetworkManager", "Saved : %ld, Sender : %ld", (long int)(m_peers[i]), (long int)(event->peer));
|
Log::error("NetworkManager", "Saved : %ld, Sender : %ld", (long int)(m_peers[i]), (long int)(event->peer));
|
||||||
if (m_peers[i] == event->peer && !removed) // remove only one
|
if (m_peers[i]->isSamePeer(event->peer) && !removed) // remove only one
|
||||||
{
|
{
|
||||||
delete m_peers[i];
|
delete m_peers[i];
|
||||||
m_peers.erase(m_peers.begin()+i, m_peers.begin()+i+1);
|
m_peers.erase(m_peers.begin()+i, m_peers.begin()+i+1);
|
||||||
Log::verbose("NetworkManager", "The peer has been removed from the Network Manager.");
|
Log::verbose("NetworkManager", "The peer has been removed from the Network Manager.");
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
else if (m_peers[i] == event->peer)
|
else if (m_peers[i]->isSamePeer(event->peer))
|
||||||
{
|
{
|
||||||
Log::fatal("NetworkManager", "Multiple peers match the disconnected one.");
|
Log::fatal("NetworkManager", "Multiple peers match the disconnected one.");
|
||||||
}
|
}
|
||||||
@ -134,10 +134,10 @@ void NetworkManager::notifyEvent(Event* event)
|
|||||||
if (!removed)
|
if (!removed)
|
||||||
Log::warn("NetworkManager", "The peer that has been disconnected was not registered by the Network Manager.");
|
Log::warn("NetworkManager", "The peer that has been disconnected was not registered by the Network Manager.");
|
||||||
|
|
||||||
Log::debug("NetworkManager", "Somebody is now disconnected. There are now %lu peers.", m_peers.size());
|
Log::info("NetworkManager", "Somebody is now disconnected. There are now %lu peers.", m_peers.size());
|
||||||
|
delete event; // in this case only, the event has been copied by the protocol manager
|
||||||
}
|
}
|
||||||
|
|
||||||
delete event;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -154,8 +154,10 @@ void NetworkManager::sendPacketExcept(STKPeer* peer, const NetworkString& data)
|
|||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < m_peers.size(); i++)
|
for (unsigned int i = 0; i < m_peers.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_peers[i] != peer)
|
if (!m_peers[i]->isSamePeer(peer))
|
||||||
|
{
|
||||||
m_peers[i]->sendPacket(data);
|
m_peers[i]->sendPacket(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +80,14 @@ ProtocolManager::~ProtocolManager()
|
|||||||
|
|
||||||
void ProtocolManager::notifyEvent(Event* event)
|
void ProtocolManager::notifyEvent(Event* event)
|
||||||
{
|
{
|
||||||
Event* event2 = new Event(*event);
|
if (event->type == EVENT_TYPE_DISCONNECTED)
|
||||||
|
{
|
||||||
|
// make a copy if needed (the peer will be lost elseway)
|
||||||
|
event = new Event(*event);
|
||||||
|
Log::warn("ProtocolManager", "Trying to copy the event");
|
||||||
|
}
|
||||||
pthread_mutex_lock(&m_events_mutex);
|
pthread_mutex_lock(&m_events_mutex);
|
||||||
m_events_to_process.push_back(event2); // add the event to the queue
|
m_events_to_process.push_back(event); // add the event to the queue
|
||||||
pthread_mutex_unlock(&m_events_mutex);
|
pthread_mutex_unlock(&m_events_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,15 @@ STKPeer::STKPeer()
|
|||||||
m_peer = NULL;
|
m_peer = NULL;
|
||||||
m_player_profile = NULL;
|
m_player_profile = NULL;
|
||||||
}
|
}
|
||||||
|
STKPeer::STKPeer(const STKPeer& peer)
|
||||||
|
{
|
||||||
|
Log::verbose("STKPeer", "Construction a copy of a STKPeer.");
|
||||||
|
m_peer = peer.m_peer;
|
||||||
|
m_player_profile = peer.m_player_profile;
|
||||||
|
m_client_server_token = peer.m_client_server_token;
|
||||||
|
m_token_set = peer.m_token_set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
STKPeer::~STKPeer()
|
STKPeer::~STKPeer()
|
||||||
{
|
{
|
||||||
@ -84,20 +93,8 @@ bool STKPeer::isConnected() const
|
|||||||
Log::info("STKPeer", "The peer state is %i\n", m_peer->state);
|
Log::info("STKPeer", "The peer state is %i\n", m_peer->state);
|
||||||
return (m_peer->state == ENET_PEER_STATE_CONNECTED);
|
return (m_peer->state == ENET_PEER_STATE_CONNECTED);
|
||||||
}
|
}
|
||||||
bool STKPeer::operator==(const STKPeer* peer) const
|
bool STKPeer::isSamePeer(const STKPeer* peer) const
|
||||||
{
|
{
|
||||||
return peer->m_peer==m_peer;
|
return peer->m_peer==m_peer;
|
||||||
}
|
}
|
||||||
bool STKPeer::operator!=(const STKPeer* peer) const
|
|
||||||
{
|
|
||||||
return peer->m_peer!=m_peer;
|
|
||||||
}
|
|
||||||
bool STKPeer::operator==(const ENetPeer* peer) const
|
|
||||||
{
|
|
||||||
return peer==m_peer;
|
|
||||||
}
|
|
||||||
bool STKPeer::operator!=(const ENetPeer* peer) const
|
|
||||||
{
|
|
||||||
return peer!=m_peer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ class STKPeer
|
|||||||
friend class Event;
|
friend class Event;
|
||||||
public:
|
public:
|
||||||
STKPeer();
|
STKPeer();
|
||||||
|
STKPeer(const STKPeer& peer);
|
||||||
virtual ~STKPeer();
|
virtual ~STKPeer();
|
||||||
|
|
||||||
virtual void sendPacket(const NetworkString& data);
|
virtual void sendPacket(const NetworkString& data);
|
||||||
@ -48,10 +49,7 @@ class STKPeer
|
|||||||
bool isClientServerTokenSet() const { return m_token_set; }
|
bool isClientServerTokenSet() const { return m_token_set; }
|
||||||
NetworkPlayerProfile* getPlayerProfile() { return m_player_profile; }
|
NetworkPlayerProfile* getPlayerProfile() { return m_player_profile; }
|
||||||
|
|
||||||
bool operator==(const STKPeer* peer) const;
|
bool isSamePeer(const STKPeer* peer) const;
|
||||||
bool operator==(const ENetPeer* peer) const;
|
|
||||||
bool operator!=(const STKPeer* peer) const;
|
|
||||||
bool operator!=(const ENetPeer* peer) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ENetPeer* m_peer;
|
ENetPeer* m_peer;
|
||||||
|
Loading…
Reference in New Issue
Block a user