diff options
Diffstat (limited to 'src/game/UpdateData.cpp')
-rw-r--r-- | src/game/UpdateData.cpp | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/game/UpdateData.cpp b/src/game/UpdateData.cpp index 91ef84bb372..a3192b74b0e 100644 --- a/src/game/UpdateData.cpp +++ b/src/game/UpdateData.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -103,49 +103,43 @@ void UpdateData::Compress(void* dst, uint32 *dst_size, void* src, int src_size) *dst_size = c_stream.total_out; } -bool UpdateData::BuildPacket(WorldPacket *packet, bool hasTransport) +bool UpdateData::BuildPacket(WorldPacket *packet) { - ByteBuffer buf(m_data.size() + 10 + m_outOfRangeGUIDs.size()*8); + 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); - buf << (uint8) (hasTransport ? 1 : 0); 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++) + for(std::set<uint64>::const_iterator i = m_outOfRangeGUIDs.begin(); i != m_outOfRangeGUIDs.end(); ++i) { - //buf.appendPackGUID(*i); - buf << (uint8)0xFF; - buf << (uint64) *i; + buf.appendPackGUID(*i); } } buf.append(m_data); - packet->clear(); + size_t pSize = buf.wpos(); // use real used data size - if (m_data.size() > 50 ) + if (pSize > 100 ) // compress large packets { - uint32 destsize = buf.size() + buf.size()/10 + 16; - packet->resize( destsize ); - - packet->put(0, (uint32)buf.size()); + uint32 destsize = pSize; + packet->resize( destsize + sizeof(uint32) ); - Compress(const_cast<uint8*>(packet->contents()) + sizeof(uint32), - &destsize, - (void*)buf.contents(), - buf.size()); + 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 ); } - else + else // send small packets without compression { packet->append( buf ); packet->SetOpcode( SMSG_UPDATE_OBJECT ); |