[7968] In packet compression use real writed data size.

This commit is contained in:
VladimirMangos 2009-06-06 08:53:39 +04:00
parent 3b72c6f207
commit ef2d0df05d
3 changed files with 6 additions and 7 deletions

View file

@ -103,7 +103,7 @@ void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size)
bool UpdateData::BuildPacket(WorldPacket *packet) bool UpdateData::BuildPacket(WorldPacket *packet)
{ {
ByteBuffer buf(m_data.size()); 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); buf << (uint32) (!m_outOfRangeGUIDs.empty() ? m_blockCount + 1 : m_blockCount);
@ -122,15 +122,14 @@ bool UpdateData::BuildPacket(WorldPacket *packet)
packet->clear(); packet->clear();
size_t pSize = buf.size(); size_t pSize = buf.wpos(); // use real used data size
if (pSize > 100 ) // compress large packets if (pSize > 100 ) // compress large packets
{ {
packet->resize(pSize); uint32 destsize = pSize;
packet->resize( destsize + sizeof(uint32) );
packet->put<uint32>(0, pSize); packet->put<uint32>(0, pSize);
uint32 destsize = pSize;
Compress(const_cast<uint8*>(packet->contents()) + sizeof(uint32), &destsize, (void*)buf.contents(), pSize); Compress(const_cast<uint8*>(packet->contents()) + sizeof(uint32), &destsize, (void*)buf.contents(), pSize);
if (destsize == 0) if (destsize == 0)
return false; return false;

View file

@ -309,7 +309,7 @@ class ByteBuffer
} }
void append(const ByteBuffer& buffer) void append(const ByteBuffer& buffer)
{ {
if(buffer.size()) append(buffer.contents(),buffer.wpos()); if(buffer.wpos()) append(buffer.contents(),buffer.wpos());
} }
void appendPackGUID(uint64 guid) void appendPackGUID(uint64 guid)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7967" #define REVISION_NR "7968"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__