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

References CONFIG_COMPRESSION, LOG_ERROR, and sWorld.

Referenced by EncryptableAndCompressiblePacket::CompressIfNeeded().