AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WorldSocket.cpp File Reference
#include "WorldSocket.h"
#include "AccountMgr.h"
#include "Config.h"
#include "CryptoHash.h"
#include "CryptoRandom.h"
#include "DatabaseEnv.h"
#include "GameTime.h"
#include "IPLocation.h"
#include "Opcodes.h"
#include "PacketLog.h"
#include "Random.h"
#include "Realm.h"
#include "ScriptMgr.h"
#include "World.h"
#include "WorldSession.h"
#include "WorldSessionMgr.h"
#include "RBAC.h"
#include "zlib.h"
#include <memory>
#include "ServerPktHeader.h"

Go to the source code of this file.

Classes

struct  ClientAuthSession
 
struct  AccountInfo
 

Functions

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

Function Documentation

◆ compressBuff()

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

References CONFIG_COMPRESSION, LOG_ERROR, and sWorld.

Referenced by EncryptableAndCompressiblePacket::CompressIfNeeded().