From 6d1e5dc8aeede097586fa90c5b09e4fcd77c02ac Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 9 Mar 2016 21:21:50 +1100 Subject: [PATCH] Fixed crashed caused by sending messages that have been read previously (which were sent with incorrect length). --- src/network/network_string.hpp | 6 ++++++ src/network/stk_peer.cpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/network/network_string.hpp b/src/network/network_string.hpp index 560e0451a..9877720d8 100644 --- a/src/network/network_string.hpp +++ b/src/network/network_string.hpp @@ -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. */ diff --git a/src/network/stk_peer.cpp b/src/network/stk_peer.cpp index 899dd5b12..6c9b2c7ac 100644 --- a/src/network/stk_peer.cpp +++ b/src/network/stk_peer.cpp @@ -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);