Coding style fixes.
This commit is contained in:
parent
54a0e50fe3
commit
94e87796f5
@ -23,6 +23,9 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/** \brief Constructor
|
||||
* \param event : The event that needs to be translated.
|
||||
*/
|
||||
Event::Event(ENetEvent* event)
|
||||
{
|
||||
switch (event->type)
|
||||
@ -42,15 +45,17 @@ Event::Event(ENetEvent* event)
|
||||
}
|
||||
if (type == EVENT_TYPE_MESSAGE)
|
||||
{
|
||||
m_data = NetworkString(std::string((char*)(event->packet->data), event->packet->dataLength-1));
|
||||
m_data = NetworkString(std::string((char*)(event->packet->data),
|
||||
event->packet->dataLength-1));
|
||||
}
|
||||
|
||||
m_packet = NULL;
|
||||
if (event->packet)
|
||||
{
|
||||
m_packet = event->packet;
|
||||
|
||||
if (m_packet)
|
||||
enet_packet_destroy(m_packet); // we got all we need, just remove the data.
|
||||
// we got all we need, just remove the data.
|
||||
enet_packet_destroy(m_packet);
|
||||
}
|
||||
m_packet = NULL;
|
||||
|
||||
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
|
||||
@ -61,7 +66,8 @@ Event::Event(ENetEvent* event)
|
||||
if (peers[i]->m_peer == event->peer)
|
||||
{
|
||||
*peer = peers[i];
|
||||
Log::verbose("Event", "The peer you sought has been found on %p", peer);
|
||||
Log::verbose("Event", "The peer you sought has been found on %p",
|
||||
peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -70,28 +76,38 @@ Event::Event(ENetEvent* event)
|
||||
STKPeer* new_peer = new STKPeer();
|
||||
new_peer->m_peer = event->peer;
|
||||
*peer = new_peer;
|
||||
Log::debug("Event", "Creating a new peer, address are STKPeer:%p, Peer:%p", new_peer, event->peer);
|
||||
Log::debug("Event",
|
||||
"Creating a new peer, address are STKPeer:%p, Peer:%p",
|
||||
new_peer, event->peer);
|
||||
}
|
||||
}
|
||||
} // Event(ENetEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** \brief Constructor
|
||||
* \param event : The event to copy.
|
||||
*/
|
||||
Event::Event(const Event& event)
|
||||
{
|
||||
m_packet = NULL;
|
||||
m_data = event.m_data;
|
||||
// copy the peer
|
||||
peer = event.peer;
|
||||
type = event.type;
|
||||
}
|
||||
m_packet = NULL;
|
||||
m_data = event.m_data;
|
||||
// copy the peer
|
||||
peer = event.peer;
|
||||
} // Event(Event)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** \brief Destructor that frees the memory of the package.
|
||||
*/
|
||||
Event::~Event()
|
||||
{
|
||||
delete peer;
|
||||
peer = NULL;
|
||||
m_packet = NULL;
|
||||
}
|
||||
} // ~Event
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Event::removeFront(int size)
|
||||
{
|
||||
m_data.removeFront(size);
|
||||
}
|
||||
} // removeFront
|
||||
|
||||
|
@ -51,37 +51,32 @@ enum EVENT_TYPE
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
/*! \brief Constructor
|
||||
* \param event : The event that needs to be translated.
|
||||
*/
|
||||
Event(ENetEvent* event);
|
||||
/*! \brief Constructor
|
||||
* \param event : The event to copy.
|
||||
*/
|
||||
Event(const Event& event);
|
||||
/*! \brief Destructor
|
||||
* frees the memory of the ENetPacket.
|
||||
*/
|
||||
~Event();
|
||||
private:
|
||||
/** Copy of the data passed by the event. */
|
||||
NetworkString m_data;
|
||||
|
||||
/*! \brief Remove bytes at the beginning of data.
|
||||
* \param size : The number of bytes to remove.
|
||||
*/
|
||||
void removeFront(int size);
|
||||
/** A pointer on the ENetPacket to be deleted. */
|
||||
ENetPacket* m_packet;
|
||||
|
||||
/*! \brief Get a copy of the data.
|
||||
* \return A copy of the message data. This is empty for events like
|
||||
* connection or disconnections.
|
||||
*/
|
||||
NetworkString data() const { return m_data; }
|
||||
public:
|
||||
Event(ENetEvent* event);
|
||||
Event(const Event& event);
|
||||
~Event();
|
||||
|
||||
EVENT_TYPE type; //!< Type of the event.
|
||||
STKPeer** peer; //!< Pointer to the peer that triggered that event.
|
||||
/*! \brief Remove bytes at the beginning of data.
|
||||
* \param size : The number of bytes to remove.
|
||||
*/
|
||||
void removeFront(int size);
|
||||
|
||||
private:
|
||||
NetworkString m_data; //!< Copy of the data passed by the event.
|
||||
ENetPacket* m_packet; //!< A pointer on the ENetPacket to be deleted.
|
||||
};
|
||||
/*! \brief Get a copy of the data.
|
||||
* \return A copy of the message data. This is empty for events like
|
||||
* connection or disconnections.
|
||||
*/
|
||||
NetworkString data() const { return m_data; }
|
||||
|
||||
EVENT_TYPE type; //!< Type of the event.
|
||||
STKPeer** peer; //!< Pointer to the peer that triggered that event.
|
||||
|
||||
}; // class Event
|
||||
|
||||
#endif // EVENT_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user