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

References CONFIG_COMPRESSION, LOG_ERROR, and sWorld.

Referenced by EncryptableAndCompressiblePacket::CompressIfNeeded().