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 "zlib.h"
#include <memory>
#include "ServerPktHeader.h"

Go to the source code of this file.

Classes

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

References CONFIG_COMPRESSION, LOG_ERROR, and sWorld.

Referenced by EncryptableAndCompressiblePacket::CompressIfNeeded().