Fixed crashed caused by sending messages that have been read previously

(which were sent with incorrect length).
This commit is contained in:
hiker 2016-03-09 21:21:50 +11:00
parent 45b2fef88a
commit 6d1e5dc8ae
2 changed files with 8 additions and 1 deletions

View File

@ -152,6 +152,12 @@ public:
/** Returns the remaining length of the network string. */
unsigned int size() const { return (int)m_buffer.size()-m_current_offset; }
// ------------------------------------------------------------------------
/** Returns the send size, which is the full length of the buffer. A
* difference to size() happens if the string to be sent was previously
* read, and has m_current_offset != 0. Even in this case the whole
* string must be sent. */
unsigned int getTotalSize() const { return m_buffer.size(); }
// ------------------------------------------------------------------------
// All functions related to adding data to a network string
/** Add 8 bit unsigned int. */

View File

@ -69,7 +69,8 @@ void STKPeer::sendPacket(NetworkString *data, bool reliable)
Log::verbose("STKPeer", "sending packet of size %d to %s",
data->size(), a.toString().c_str());
ENetPacket* packet = enet_packet_create(data->getData(), data->size(),
ENetPacket* packet = enet_packet_create(data->getData(),
data->getTotalSize(),
(reliable ? ENET_PACKET_FLAG_RELIABLE
: ENET_PACKET_FLAG_UNSEQUENCED));
enet_peer_send(m_enet_peer, 0, packet);