AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
UpdateData Class Reference

#include "UpdateData.h"

Public Member Functions

 UpdateData ()
 
void AddOutOfRangeGUID (ObjectGuid guid)
 
void AddUpdateBlock (const ByteBuffer &block)
 
void AddUpdateBlock (const UpdateData &block)
 
bool BuildPacket (WorldPacket *packet)
 
bool HasData () const
 
void Clear ()
 

Protected Member Functions

void Compress (void *dst, uint32 *dst_size, void *src, int src_size)
 

Protected Attributes

uint32 m_blockCount
 
GuidVector m_outOfRangeGUIDs
 
ByteBuffer m_data
 

Detailed Description

Constructor & Destructor Documentation

◆ UpdateData()

UpdateData::UpdateData ( )
27 : m_blockCount(0)
28{
29 m_outOfRangeGUIDs.reserve(15);
30}
GuidVector m_outOfRangeGUIDs
Definition: UpdateData.h:65
uint32 m_blockCount
Definition: UpdateData.h:64

References m_outOfRangeGUIDs.

Member Function Documentation

◆ AddOutOfRangeGUID()

void UpdateData::AddOutOfRangeGUID ( ObjectGuid  guid)

◆ AddUpdateBlock() [1/2]

void UpdateData::AddUpdateBlock ( const ByteBuffer block)
38{
39 m_data.append(block);
41}
ByteBuffer m_data
Definition: UpdateData.h:66
void append(T value)
Definition: ByteBuffer.h:129

References ByteBuffer::append(), m_blockCount, and m_data.

Referenced by Object::BuildCreateUpdateBlockForPlayer(), Object::BuildMovementUpdateBlock(), and Object::BuildValuesUpdateBlockForPlayer().

◆ AddUpdateBlock() [2/2]

void UpdateData::AddUpdateBlock ( const UpdateData block)
44{
45 m_data.append(block.m_data);
47}

References ByteBuffer::append(), m_blockCount, and m_data.

◆ BuildPacket()

bool UpdateData::BuildPacket ( WorldPacket packet)
106{
107 ASSERT(packet->empty()); // shouldn't happen
108
109 ByteBuffer buf(4 + (m_outOfRangeGUIDs.empty() ? 0 : 1 + 4 + 9 * m_outOfRangeGUIDs.size()) + m_data.wpos());
110
111 buf << (uint32) (!m_outOfRangeGUIDs.empty() ? m_blockCount + 1 : m_blockCount);
112
113 if (!m_outOfRangeGUIDs.empty())
114 {
116 buf << (uint32) m_outOfRangeGUIDs.size();
117
118 for (ObjectGuid const& guid : m_outOfRangeGUIDs)
119 {
120 buf << guid.WriteAsPacked();
121 }
122 }
123
124 buf.append(m_data);
125
126 size_t pSize = buf.wpos(); // use real used data size
127
128 if (pSize > 100) // compress large packets
129 {
130 uint32 destsize = compressBound(pSize);
131 packet->resize(destsize + sizeof(uint32));
132
133 packet->put<uint32>(0, pSize);
134 Compress(const_cast<uint8*>(packet->contents()) + sizeof(uint32), &destsize, (void*)buf.contents(), pSize);
135 if (destsize == 0)
136 return false;
137
138 packet->resize(destsize + sizeof(uint32));
140 }
141 else // send small packets without compression
142 {
143 packet->append(buf);
145 }
146
147 return true;
148}
#define ASSERT
Definition: Errors.h:68
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
@ UPDATETYPE_OUT_OF_RANGE_OBJECTS
Definition: UpdateData.h:32
@ SMSG_COMPRESSED_UPDATE_OBJECT
Definition: Opcodes.h:532
@ SMSG_UPDATE_OBJECT
Definition: Opcodes.h:199
Definition: ObjectGuid.h:120
void Compress(void *dst, uint32 *dst_size, void *src, int src_size)
Definition: UpdateData.cpp:49
void SetOpcode(uint16 opcode)
Definition: WorldPacket.h:77
Definition: ByteBuffer.h:70
void resize(size_t newsize)
Definition: ByteBuffer.h:447
size_t wpos() const
Definition: ByteBuffer.h:330
void put(std::size_t pos, T value)
Definition: ByteBuffer.h:137
bool empty() const
Definition: ByteBuffer.h:445
uint8 * contents()
Definition: ByteBuffer.h:424

References ByteBuffer::append(), ASSERT, Compress(), ByteBuffer::contents(), ByteBuffer::empty(), m_blockCount, m_data, m_outOfRangeGUIDs, ByteBuffer::put(), ByteBuffer::resize(), WorldPacket::SetOpcode(), SMSG_COMPRESSED_UPDATE_OBJECT, SMSG_UPDATE_OBJECT, UPDATETYPE_OUT_OF_RANGE_OBJECTS, and ByteBuffer::wpos().

Referenced by Group::AddMember(), Map::AddToMap(), spell_madrigosa_activate_barrier::spell_madrigosa_activate_barrier_SpellScript::HandleActivateObject(), spell_madrigosa_deactivate_barrier::spell_madrigosa_deactivate_barrier_SpellScript::HandleActivateObject(), spell_pri_lightwell_renew::HandleUpdateSpellclick(), Map::RemoveFromMap(), Map::SendInitSelf(), Map::SendInitTransports(), Map::SendRemoveTransports(), Acore::VisibleNotifier::SendToSelf(), BattlegroundSA::SendTransportInit(), BattlegroundSA::SendTransportsRemove(), Object::SendUpdateToPlayer(), Unit::SetOwnerGUID(), BattlegroundSA::StartShips(), GameObject::Update(), Player::UpdateForQuestWorldObjects(), and Player::UpdateTriggerVisibility().

◆ Clear()

void UpdateData::Clear ( )
151{
152 m_data.clear();
153 m_outOfRangeGUIDs.clear();
154 m_blockCount = 0;
155}
void clear()
Definition: ByteBuffer.h:122

References ByteBuffer::clear(), m_blockCount, m_data, and m_outOfRangeGUIDs.

◆ Compress()

void UpdateData::Compress ( void *  dst,
uint32 dst_size,
void *  src,
int  src_size 
)
protected
50{
51 z_stream c_stream;
52
53 c_stream.zalloc = (alloc_func)0;
54 c_stream.zfree = (free_func)0;
55 c_stream.opaque = (voidpf)0;
56
57 // default Z_BEST_SPEED (1)
58 int z_res = deflateInit(&c_stream, sWorld->getIntConfig(CONFIG_COMPRESSION));
59 if (z_res != Z_OK)
60 {
61 LOG_ERROR("entities.object", "Can't compress update packet (zlib: deflateInit) Error code: {} ({})", z_res, zError(z_res));
62 *dst_size = 0;
63 return;
64 }
65
66 c_stream.next_out = (Bytef*)dst;
67 c_stream.avail_out = *dst_size;
68 c_stream.next_in = (Bytef*)src;
69 c_stream.avail_in = (uInt)src_size;
70
71 z_res = deflate(&c_stream, Z_NO_FLUSH);
72 if (z_res != Z_OK)
73 {
74 LOG_ERROR("entities.object", "Can't compress update packet (zlib: deflate) Error code: {} ({})", z_res, zError(z_res));
75 *dst_size = 0;
76 return;
77 }
78
79 if (c_stream.avail_in != 0)
80 {
81 LOG_ERROR("entities.object", "Can't compress update packet (zlib: deflate not greedy)");
82 *dst_size = 0;
83 return;
84 }
85
86 z_res = deflate(&c_stream, Z_FINISH);
87 if (z_res != Z_STREAM_END)
88 {
89 LOG_ERROR("entities.object", "Can't compress update packet (zlib: deflate should report Z_STREAM_END instead {} ({})", z_res, zError(z_res));
90 *dst_size = 0;
91 return;
92 }
93
94 z_res = deflateEnd(&c_stream);
95 if (z_res != Z_OK)
96 {
97 LOG_ERROR("entities.object", "Can't compress update packet (zlib: deflateEnd) Error code: {} ({})", z_res, zError(z_res));
98 *dst_size = 0;
99 return;
100 }
101
102 *dst_size = c_stream.total_out;
103}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
@ CONFIG_COMPRESSION
Definition: IWorld.h:208
#define sWorld
Definition: World.h:451

References CONFIG_COMPRESSION, LOG_ERROR, and sWorld.

Referenced by BuildPacket().

◆ HasData()

bool UpdateData::HasData ( ) const
inline

Member Data Documentation

◆ m_blockCount

uint32 UpdateData::m_blockCount
protected

◆ m_data

ByteBuffer UpdateData::m_data
protected

Referenced by AddUpdateBlock(), BuildPacket(), and Clear().

◆ m_outOfRangeGUIDs

GuidVector UpdateData::m_outOfRangeGUIDs
protected