aboutsummaryrefslogtreecommitdiff
path: root/src/game/UpdateData.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/UpdateData.cpp')
-rw-r--r--src/game/UpdateData.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/game/UpdateData.cpp b/src/game/UpdateData.cpp
index 7b2c86cd49a..e461d63e248 100644
--- a/src/game/UpdateData.cpp
+++ b/src/game/UpdateData.cpp
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#include "Common.h"
#include "ByteBuffer.h"
#include "WorldPacket.h"
@@ -25,28 +26,35 @@
#include "Opcodes.h"
#include "World.h"
#include <zlib/zlib.h>
+
UpdateData::UpdateData() : m_blockCount(0)
{
}
+
void UpdateData::AddOutOfRangeGUID(std::set<uint64>& guids)
{
m_outOfRangeGUIDs.insert(guids.begin(),guids.end());
}
+
void UpdateData::AddOutOfRangeGUID(const uint64 &guid)
{
m_outOfRangeGUIDs.insert(guid);
}
+
void UpdateData::AddUpdateBlock(const ByteBuffer &block)
{
m_data.append(block);
++m_blockCount;
}
+
void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size)
{
z_stream c_stream;
+
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
+
// default Z_BEST_SPEED (1)
int z_res = deflateInit(&c_stream, sWorld.getConfig(CONFIG_COMPRESSION));
if (z_res != Z_OK)
@@ -55,10 +63,12 @@ void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size)
*dst_size = 0;
return;
}
+
c_stream.next_out = (Bytef*)dst;
c_stream.avail_out = *dst_size;
c_stream.next_in = (Bytef*)src;
c_stream.avail_in = (uInt)src_size;
+
z_res = deflate(&c_stream, Z_NO_FLUSH);
if (z_res != Z_OK)
{
@@ -66,12 +76,14 @@ void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size)
*dst_size = 0;
return;
}
+
if (c_stream.avail_in != 0)
{
sLog.outError("Can't compress update packet (zlib: deflate not greedy)");
*dst_size = 0;
return;
}
+
z_res = deflate(&c_stream, Z_FINISH);
if (z_res != Z_STREAM_END)
{
@@ -79,6 +91,7 @@ void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size)
*dst_size = 0;
return;
}
+
z_res = deflateEnd(&c_stream);
if (z_res != Z_OK)
{
@@ -86,32 +99,43 @@ void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size)
*dst_size = 0;
return;
}
+
*dst_size = c_stream.total_out;
}
+
bool UpdateData::BuildPacket(WorldPacket *packet)
{
ASSERT(packet->empty()); // shouldn't happen
+
ByteBuffer buf(4 + (m_outOfRangeGUIDs.empty() ? 0 : 1 + 4 + 9 * m_outOfRangeGUIDs.size()) + m_data.wpos());
+
buf << (uint32) (!m_outOfRangeGUIDs.empty() ? m_blockCount + 1 : m_blockCount);
+
if(!m_outOfRangeGUIDs.empty())
{
buf << (uint8) UPDATETYPE_OUT_OF_RANGE_OBJECTS;
buf << (uint32) m_outOfRangeGUIDs.size();
+
for(std::set<uint64>::const_iterator i = m_outOfRangeGUIDs.begin(); i != m_outOfRangeGUIDs.end(); ++i)
{
buf.appendPackGUID(*i);
}
}
+
buf.append(m_data);
+
size_t pSize = buf.wpos(); // use real used data size
+
if (pSize > 100 ) // compress large packets
{
uint32 destsize = compressBound(pSize);
packet->resize( destsize + sizeof(uint32) );
+
packet->put<uint32>(0, pSize);
Compress(const_cast<uint8*>(packet->contents()) + sizeof(uint32), &destsize, (void*)buf.contents(), pSize);
if (destsize == 0)
return false;
+
packet->resize( destsize + sizeof(uint32) );
packet->SetOpcode( SMSG_COMPRESSED_UPDATE_OBJECT );
}
@@ -120,8 +144,10 @@ bool UpdateData::BuildPacket(WorldPacket *packet)
packet->append( buf );
packet->SetOpcode( SMSG_UPDATE_OBJECT );
}
+
return true;
}
+
void UpdateData::Clear()
{
m_data.clear();