From 7665f308280a0060d2464354ae0d51bb73bfc19e Mon Sep 17 00:00:00 2001 From: hilnius Date: Thu, 11 Jul 2013 00:03:47 +0000 Subject: [PATCH] sync work git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13173 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/network/event.cpp | 1 + src/network/network_manager.cpp | 14 ++++++++------ src/network/protocol_manager.cpp | 9 +++++++-- src/network/stk_peer.cpp | 23 ++++++++++------------- src/network/stk_peer.hpp | 6 ++---- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/network/event.cpp b/src/network/event.cpp index 8328f0e2f..3d875bf39 100644 --- a/src/network/event.cpp +++ b/src/network/event.cpp @@ -76,6 +76,7 @@ Event::Event(ENetEvent* event) Event::Event(const Event& event) { + Log::verbose("Event", "Constructing a copy of the event."); m_packet = NULL; data = event.data; // copy the peer diff --git a/src/network/network_manager.cpp b/src/network/network_manager.cpp index f19d8ce55..33926027e 100644 --- a/src/network/network_manager.cpp +++ b/src/network/network_manager.cpp @@ -92,7 +92,7 @@ void NetworkManager::notifyEvent(Event* event) 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)); // create the new 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++) { 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]; m_peers.erase(m_peers.begin()+i, m_peers.begin()+i+1); Log::verbose("NetworkManager", "The peer has been removed from the Network Manager."); 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."); } @@ -134,10 +134,10 @@ void NetworkManager::notifyEvent(Event* event) if (!removed) 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++) { - if (m_peers[i] != peer) + if (!m_peers[i]->isSamePeer(peer)) + { m_peers[i]->sendPacket(data); + } } } diff --git a/src/network/protocol_manager.cpp b/src/network/protocol_manager.cpp index 6915ce46c..a7b358ce5 100644 --- a/src/network/protocol_manager.cpp +++ b/src/network/protocol_manager.cpp @@ -80,9 +80,14 @@ ProtocolManager::~ProtocolManager() 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); - 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); } diff --git a/src/network/stk_peer.cpp b/src/network/stk_peer.cpp index e542739bb..c482a832a 100644 --- a/src/network/stk_peer.cpp +++ b/src/network/stk_peer.cpp @@ -27,6 +27,15 @@ STKPeer::STKPeer() m_peer = 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() { @@ -84,20 +93,8 @@ bool STKPeer::isConnected() const Log::info("STKPeer", "The peer state is %i\n", m_peer->state); 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; } -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; -} diff --git a/src/network/stk_peer.hpp b/src/network/stk_peer.hpp index ef9dbbcb5..2aed5da6a 100644 --- a/src/network/stk_peer.hpp +++ b/src/network/stk_peer.hpp @@ -29,6 +29,7 @@ class STKPeer friend class Event; public: STKPeer(); + STKPeer(const STKPeer& peer); virtual ~STKPeer(); virtual void sendPacket(const NetworkString& data); @@ -48,10 +49,7 @@ class STKPeer bool isClientServerTokenSet() const { return m_token_set; } NetworkPlayerProfile* getPlayerProfile() { return m_player_profile; } - bool operator==(const STKPeer* peer) const; - bool operator==(const ENetPeer* peer) const; - bool operator!=(const STKPeer* peer) const; - bool operator!=(const ENetPeer* peer) const; + bool isSamePeer(const STKPeer* peer) const; protected: ENetPeer* m_peer;