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

#include "WorldSocket.h"

Inheritance diagram for EncryptableAndCompressiblePacket:
WorldPacket ByteBuffer

Public Member Functions

 EncryptableAndCompressiblePacket (WorldPacket const &packet, bool encrypt)
 
bool NeedsEncryption () const
 
bool NeedsCompression () const
 
void CompressIfNeeded ()
 
- Public Member Functions inherited from WorldPacket
 WorldPacket ()
 
 WorldPacket (uint16 opcode, std::size_t res=200)
 
 WorldPacket (WorldPacket &&packet) noexcept
 
 WorldPacket (WorldPacket &&packet, TimePoint receivedTime)
 
 WorldPacket (WorldPacket const &right)
 
WorldPacketoperator= (WorldPacket const &right)
 
WorldPacketoperator= (WorldPacket &&right) noexcept
 
 WorldPacket (uint16 opcode, MessageBuffer &&buffer)
 
void Initialize (uint16 opcode, std::size_t newres=200)
 
uint16 GetOpcode () const
 
void SetOpcode (uint16 opcode)
 
TimePoint GetReceivedTime () const
 
- Public Member Functions inherited from ByteBuffer
 ByteBuffer ()
 
 ByteBuffer (std::size_t reserve)
 
 ByteBuffer (ByteBuffer &&buf) noexcept
 
 ByteBuffer (ByteBuffer const &right)=default
 
 ByteBuffer (MessageBuffer &&buffer)
 
virtual ~ByteBuffer ()=default
 
ByteBufferoperator= (ByteBuffer const &right)
 
ByteBufferoperator= (ByteBuffer &&right) noexcept
 
void clear ()
 
template<typename T >
void append (T value)
 
template<typename T >
void put (std::size_t pos, T value)
 
ByteBufferoperator<< (bool value)
 
ByteBufferoperator<< (uint8 value)
 
ByteBufferoperator<< (uint16 value)
 
ByteBufferoperator<< (uint32 value)
 
ByteBufferoperator<< (uint64 value)
 
ByteBufferoperator<< (int8 value)
 
ByteBufferoperator<< (int16 value)
 
ByteBufferoperator<< (int32 value)
 
ByteBufferoperator<< (int64 value)
 
ByteBufferoperator<< (float value)
 
ByteBufferoperator<< (double value)
 
ByteBufferoperator<< (std::string_view value)
 
ByteBufferoperator<< (std::string const &str)
 
ByteBufferoperator<< (char const *str)
 
ByteBufferoperator>> (bool &value)
 
ByteBufferoperator>> (uint8 &value)
 
ByteBufferoperator>> (uint16 &value)
 
ByteBufferoperator>> (uint32 &value)
 
ByteBufferoperator>> (uint64 &value)
 
ByteBufferoperator>> (int8 &value)
 
ByteBufferoperator>> (int16 &value)
 
ByteBufferoperator>> (int32 &value)
 
ByteBufferoperator>> (int64 &value)
 
ByteBufferoperator>> (float &value)
 
ByteBufferoperator>> (double &value)
 
ByteBufferoperator>> (std::string &value)
 
uint8operator[] (std::size_t const pos)
 
uint8 const & operator[] (std::size_t const pos) const
 
std::size_t rpos () const
 
std::size_t rpos (std::size_t rpos_)
 
void rfinish ()
 
std::size_t wpos () const
 
std::size_t wpos (std::size_t wpos_)
 
template<typename T >
void read_skip ()
 
void read_skip (std::size_t skip)
 
template<typename T >
read ()
 
template<typename T >
read (std::size_t pos) const
 
void read (uint8 *dest, std::size_t len)
 
template<std::size_t Size>
void read (std::array< uint8, Size > &arr)
 
void readPackGUID (uint64 &guid)
 
std::string ReadCString (bool requireValidUtf8=true)
 
uint32 ReadPackedTime ()
 
ByteBufferReadPackedTime (uint32 &time)
 
uint8contents ()
 
uint8 const * contents () const
 
std::size_t size () const
 
bool empty () const
 
void resize (std::size_t newsize)
 
void reserve (std::size_t ressize)
 
void shrink_to_fit ()
 
void append (char const *src, std::size_t cnt)
 
template<class T >
void append (const T *src, std::size_t cnt)
 
void append (uint8 const *src, std::size_t cnt)
 
void append (ByteBuffer const &buffer)
 
template<std::size_t Size>
void append (std::array< uint8, Size > const &arr)
 
void appendPackXYZ (float x, float y, float z)
 
void appendPackGUID (uint64 guid)
 
void AppendPackedTime (time_t time)
 
void put (std::size_t pos, uint8 const *src, std::size_t cnt)
 
void print_storage () const
 
void textlike () const
 
void hexlike () const
 
template<>
void read_skip ()
 
template<>
void read_skip ()
 

Public Attributes

std::atomic< EncryptableAndCompressiblePacket * > SocketQueueLink
 

Private Attributes

bool _encrypt
 

Additional Inherited Members

- Static Public Attributes inherited from ByteBuffer
static constexpr std::size_t DEFAULT_SIZE = 0x1000
 
- Protected Attributes inherited from WorldPacket
uint16 m_opcode {NULL_OPCODE}
 
TimePoint m_receivedTime
 
- Protected Attributes inherited from ByteBuffer
std::size_t _rpos {0}
 
std::size_t _wpos {0}
 
std::vector< uint8_storage
 

Detailed Description

Constructor & Destructor Documentation

◆ EncryptableAndCompressiblePacket()

EncryptableAndCompressiblePacket::EncryptableAndCompressiblePacket ( WorldPacket const &  packet,
bool  encrypt 
)
inline
36 : WorldPacket(packet), _encrypt(encrypt)
37 {
38 SocketQueueLink.store(nullptr, std::memory_order_relaxed);
39 }
WorldPacket()
Definition: WorldPacket.h:30
bool _encrypt
Definition: WorldSocket.h:50
std::atomic< EncryptableAndCompressiblePacket * > SocketQueueLink
Definition: WorldSocket.h:47

References SocketQueueLink.

Member Function Documentation

◆ CompressIfNeeded()

void EncryptableAndCompressiblePacket::CompressIfNeeded ( )
95{
96 if (!NeedsCompression())
97 return;
98
99 uint32 pSize = size();
100
101 uint32 destsize = compressBound(pSize);
102 ByteBuffer buf(destsize + sizeof(uint32));
103 buf.resize(destsize + sizeof(uint32));
104
105 buf.put<uint32>(0, pSize);
106 compressBuff(const_cast<uint8*>(buf.contents()) + sizeof(uint32), &destsize, (void*)contents(), pSize);
107 if (destsize == 0)
108 return;
109
110 buf.resize(destsize + sizeof(uint32));
111
112 ByteBuffer::operator=(std::move(buf));
114}
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
void compressBuff(void *dst, uint32 *dst_size, void *src, int src_size)
Definition: WorldSocket.cpp:38
@ SMSG_COMPRESSED_UPDATE_OBJECT
Definition: Opcodes.h:532
void SetOpcode(uint16 opcode)
Definition: WorldPacket.h:77
bool NeedsCompression() const
Definition: WorldSocket.h:43
Definition: ByteBuffer.h:70
std::size_t size() const
Definition: ByteBuffer.h:444
ByteBuffer & operator=(ByteBuffer const &right)
Definition: ByteBuffer.h:96
uint8 * contents()
Definition: ByteBuffer.h:424

References compressBuff(), ByteBuffer::contents(), NeedsCompression(), ByteBuffer::operator=(), ByteBuffer::put(), ByteBuffer::resize(), WorldPacket::SetOpcode(), ByteBuffer::size(), and SMSG_COMPRESSED_UPDATE_OBJECT.

Referenced by WorldSocket::Update().

◆ NeedsCompression()

bool EncryptableAndCompressiblePacket::NeedsCompression ( ) const
inline
43{ return GetOpcode() == SMSG_UPDATE_OBJECT && size() > 100; }
@ SMSG_UPDATE_OBJECT
Definition: Opcodes.h:199
uint16 GetOpcode() const
Definition: WorldPacket.h:76

References WorldPacket::GetOpcode(), ByteBuffer::size(), and SMSG_UPDATE_OBJECT.

Referenced by CompressIfNeeded().

◆ NeedsEncryption()

bool EncryptableAndCompressiblePacket::NeedsEncryption ( ) const
inline
41{ return _encrypt; }

References _encrypt.

Referenced by WorldSocket::Update().

Member Data Documentation

◆ _encrypt

bool EncryptableAndCompressiblePacket::_encrypt
private

Referenced by NeedsEncryption().

◆ SocketQueueLink

std::atomic<EncryptableAndCompressiblePacket*> EncryptableAndCompressiblePacket::SocketQueueLink