Changed Event's m_peer from STKPeer** to STKPeer *. Fixes some minor memory leaks.
This commit is contained in:
parent
9cdf7058a7
commit
40629d9816
@ -59,23 +59,22 @@ Event::Event(ENetEvent* event)
|
||||
m_packet = NULL;
|
||||
|
||||
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
|
||||
m_peer = new STKPeer*;
|
||||
*m_peer = NULL;
|
||||
m_peer = NULL;
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
if (peers[i]->m_peer == event->peer)
|
||||
{
|
||||
*m_peer = peers[i];
|
||||
m_peer = peers[i];
|
||||
Log::verbose("Event", "The peer you sought has been found on %p",
|
||||
m_peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (*m_peer == NULL) // peer does not exist, create him
|
||||
if (m_peer == NULL) // peer does not exist, create him
|
||||
{
|
||||
STKPeer* new_peer = new STKPeer();
|
||||
new_peer->m_peer = event->peer;
|
||||
*m_peer = new_peer;
|
||||
m_peer = new_peer;
|
||||
Log::debug("Event",
|
||||
"Creating a new peer, address are STKPeer:%p, Peer:%p",
|
||||
new_peer, event->peer);
|
||||
|
@ -62,7 +62,7 @@ private:
|
||||
EVENT_TYPE m_type;
|
||||
|
||||
/** Pointer to the peer that triggered that event. */
|
||||
STKPeer** m_peer;
|
||||
STKPeer* m_peer;
|
||||
|
||||
public:
|
||||
Event(ENetEvent* event);
|
||||
@ -76,7 +76,7 @@ public:
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the peer of this event. */
|
||||
STKPeer ** getPeer() const { return m_peer; }
|
||||
STKPeer* getPeer() const { return m_peer; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** \brief Get a copy of the data.
|
||||
* \return A copy of the message data. This is empty for events like
|
||||
|
@ -112,7 +112,7 @@ void NetworkManager::notifyEvent(Event* event)
|
||||
{
|
||||
Log::verbose("NetworkManager", "EVENT received of type %d",
|
||||
(int)(event->getType()));
|
||||
STKPeer* peer = *event->getPeer();
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (event->getType() == EVENT_TYPE_CONNECTED)
|
||||
{
|
||||
Log::info("NetworkManager", "A client has just connected. There are "
|
||||
|
@ -64,7 +64,7 @@ bool Protocol::checkDataSizeAndToken(Event* event, int minimum_size)
|
||||
data.size(), data[0]);
|
||||
return false;
|
||||
}
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
uint32_t token = data.gui32(1);
|
||||
if (token != peer->getClientServerToken())
|
||||
{
|
||||
|
@ -210,7 +210,8 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
||||
NetworkManager::getInstance()->disconnected();
|
||||
m_listener->requestTerminate(this);
|
||||
NetworkManager::getInstance()->reset();
|
||||
NetworkManager::getInstance()->removePeer(*event->getPeer()); // prolly the same as m_server
|
||||
// probably the same as m_server
|
||||
NetworkManager::getInstance()->removePeer(event->getPeer());
|
||||
return true;
|
||||
} // disconnection
|
||||
return false;
|
||||
@ -364,7 +365,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
Log::error("ClientLobbyRoomProtocol", "A message notifying an accepted connection wasn't formated as expected.");
|
||||
return;
|
||||
}
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
|
||||
uint32_t global_id = data.gui32(8);
|
||||
if (global_id == PlayerManager::getCurrentOnlineId())
|
||||
@ -406,7 +407,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
|
||||
}
|
||||
|
||||
// add self
|
||||
m_server = *(event->getPeer());
|
||||
m_server = event->getPeer();
|
||||
m_state = CONNECTED;
|
||||
}
|
||||
else
|
||||
@ -604,7 +605,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
|
||||
return;
|
||||
}
|
||||
NetworkString data = event->data();
|
||||
if ((*event->getPeer())->getClientServerToken() != data.gui32(1))
|
||||
if (event->getPeer()->getClientServerToken() != data.gui32(1))
|
||||
{
|
||||
Log::error("ClientLobbyRoomProtocol", "Bad token");
|
||||
return;
|
||||
|
@ -72,7 +72,7 @@ bool ControllerEventsProtocol::notifyEventAsynchronous(Event* event)
|
||||
uint32_t token = data.gui32();
|
||||
NetworkString pure_message = data;
|
||||
pure_message.removeFront(4);
|
||||
if (token != (*event->getPeer())->getClientServerToken())
|
||||
if (token != event->getPeer()->getClientServerToken())
|
||||
{
|
||||
Log::error("ControllerEventsProtocol", "Bad token from peer.");
|
||||
return true;
|
||||
|
@ -27,7 +27,7 @@ bool GameEventsProtocol::notifyEvent(Event* event)
|
||||
Log::warn("GameEventsProtocol", "Too short message.");
|
||||
return true;
|
||||
}
|
||||
if ( (*event->getPeer())->getClientServerToken() != data.gui32())
|
||||
if ( event->getPeer()->getClientServerToken() != data.gui32())
|
||||
{
|
||||
Log::warn("GameEventsProtocol", "Bad token.");
|
||||
return true;
|
||||
|
@ -305,7 +305,7 @@ void ServerLobbyRoomProtocol::checkRaceFinished()
|
||||
|
||||
void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
|
||||
{
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (peer->getPlayerProfile() != NULL) // others knew him
|
||||
{
|
||||
NetworkString msg(3);
|
||||
@ -334,7 +334,7 @@ void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
|
||||
*/
|
||||
void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
{
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
NetworkString data = event->data();
|
||||
if (data.size() != 5 || data[0] != 4)
|
||||
{
|
||||
@ -415,7 +415,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 6))
|
||||
return;
|
||||
|
||||
@ -476,7 +476,7 @@ void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
|
||||
void ServerLobbyRoomProtocol::playerMajorVote(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 7))
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
@ -507,7 +507,7 @@ void ServerLobbyRoomProtocol::playerMajorVote(Event* event)
|
||||
void ServerLobbyRoomProtocol::playerRaceCountVote(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer)();
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 7))
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
@ -538,7 +538,7 @@ void ServerLobbyRoomProtocol::playerRaceCountVote(Event* event)
|
||||
void ServerLobbyRoomProtocol::playerMinorVote(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 7))
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
@ -569,7 +569,7 @@ void ServerLobbyRoomProtocol::playerMinorVote(Event* event)
|
||||
void ServerLobbyRoomProtocol::playerTrackVote(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 8))
|
||||
return;
|
||||
int N = data[5];
|
||||
@ -602,7 +602,7 @@ void ServerLobbyRoomProtocol::playerTrackVote(Event* event)
|
||||
void ServerLobbyRoomProtocol::playerReversedVote(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 9))
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
@ -635,7 +635,7 @@ void ServerLobbyRoomProtocol::playerReversedVote(Event* event)
|
||||
void ServerLobbyRoomProtocol::playerLapsVote(Event* event)
|
||||
{
|
||||
NetworkString data = event->data();
|
||||
STKPeer* peer = *(event->getPeer());
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (!checkDataSizeAndToken(event, 9))
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
|
@ -44,7 +44,7 @@ bool StartGameProtocol::notifyEventAsynchronous(Event* event)
|
||||
}
|
||||
uint32_t token = data.gui32();
|
||||
uint8_t ready = data.gui8(4);
|
||||
STKPeer* peer = (*(event->getPeer()));
|
||||
STKPeer* peer = event->getPeer();
|
||||
if (peer->getClientServerToken() != token)
|
||||
{
|
||||
Log::error("StartGameProtocol", "Bad token received.");
|
||||
|
@ -61,7 +61,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
uint8_t peer_id = 0;
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
if (peers[i]->isSamePeer(*event->getPeer()))
|
||||
if (peers[i]->isSamePeer(event->getPeer()))
|
||||
{
|
||||
peer_id = i;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user