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

The WardenPayloadMgr is responsible for maintaining custom payloads used by modules. More...

#include "WardenPayloadMgr.h"

Public Member Functions

 WardenPayloadMgr ()
 
uint16 GetFreePayloadId ()
 Finds a free payload id in WardenPayloadMgr::CachedChecks. More...
 
uint16 RegisterPayload (const std::string &payload)
 Register a payload into cache and returns its payload id. More...
 
bool RegisterPayload (std::string const &payload, uint16 payloadId, bool replace=false)
 Register a payload into cache with a custom id and returns the result. More...
 
bool UnregisterPayload (uint16 payloadId)
 Unregister a payload from cache and return if successful. More...
 
WardenCheckGetPayloadById (uint16 payloadId)
 Get a payload by id from the WardenPayloadMgr::CachedChecks. More...
 
void QueuePayload (uint16 payloadId, bool pushToFront=false)
 Queue the payload into the normal warden checks. More...
 
bool DequeuePayload (uint16 payloadId)
 Dequeue the payload from the WardenPayloadMgr::QueuedPayloads queue. More...
 
void ClearQueuedPayloads ()
 Clear the payloads from the WardenPayloadMgr::QueuedPayloads queue. More...
 
uint32 GetPayloadCountInQueue ()
 Get the amount of payloads waiting in WardenPayloadMgr::QueuedPayloads. More...
 
std::list< uint16 > * GetPayloadsInQueue ()
 Get payloads waiting in WardenPayloadMgr::QueuedPayloads. More...
 

Public Attributes

std::list< uint16QueuedPayloads
 The list of currently queued payload ids to be sent through Warden. More...
 
std::map< uint16, WardenCheckCachedChecks
 The cached payloads that are accessed by payload id. More...
 

Static Public Attributes

static uint16 constexpr WardenPayloadOffsetMin = 5000
 The minimum id available for custom payloads. More...
 
static uint16 constexpr WardenPayloadOffsetMax = 9999
 The maximum id available for custom payloads. More...
 
static uint32 constexpr WardenPayloadCheckType = 139
 The checktype used for warden payloads. More...
 

Detailed Description

The WardenPayloadMgr is responsible for maintaining custom payloads used by modules.

This allows users to send custom lua payloads up to a size of 512 bytes to the game client. Some of the things you can achieve with this is:

  • Interaction with the client interface (add custom frames)
  • Access to client CVars
  • Access to protected lua functions.

Opening up many possiblilties for a patch-less custom server.

Constructor & Destructor Documentation

◆ WardenPayloadMgr()

WardenPayloadMgr::WardenPayloadMgr ( )
23{ }

Member Function Documentation

◆ ClearQueuedPayloads()

void WardenPayloadMgr::ClearQueuedPayloads ( )

Clear the payloads from the WardenPayloadMgr::QueuedPayloads queue.

138{
139 QueuedPayloads.clear();
140}
std::list< uint16 > QueuedPayloads
The list of currently queued payload ids to be sent through Warden.
Definition: WardenPayloadMgr.h:130

References QueuedPayloads.

◆ DequeuePayload()

bool WardenPayloadMgr::DequeuePayload ( uint16  payloadId)

Dequeue the payload from the WardenPayloadMgr::QueuedPayloads queue.

Parameters
payloadIdThe payloadId to be dequeued.
Returns
bool If the payload was removed.
130{
131 std::size_t const queueSize = QueuedPayloads.size();
132 QueuedPayloads.remove(payloadId);
133
134 return queueSize != QueuedPayloads.size();
135}

References QueuedPayloads.

◆ GetFreePayloadId()

uint16 WardenPayloadMgr::GetFreePayloadId ( )

Finds a free payload id in WardenPayloadMgr::CachedChecks.

Returns
uint16 The free payload id. Returns 0 if there is no free id.
26{
28
29 while (CachedChecks.find(payloadId) != CachedChecks.end())
30 {
31 payloadId++;
32
34 {
35 LOG_ERROR("warden", "Max warden payload id of '{}' passed!", WardenPayloadMgr::WardenPayloadOffsetMax);
36 return 0;
37 }
38 }
39
40 return payloadId;
41}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::uint16_t uint16
Definition: Define.h:108
static uint16 constexpr WardenPayloadOffsetMax
The maximum id available for custom payloads.
Definition: WardenPayloadMgr.h:120
std::map< uint16, WardenCheck > CachedChecks
The cached payloads that are accessed by payload id.
Definition: WardenPayloadMgr.h:135
static uint16 constexpr WardenPayloadOffsetMin
The minimum id available for custom payloads.
Definition: WardenPayloadMgr.h:115

References CachedChecks, LOG_ERROR, WardenPayloadOffsetMax, and WardenPayloadOffsetMin.

Referenced by RegisterPayload().

◆ GetPayloadById()

WardenCheck * WardenPayloadMgr::GetPayloadById ( uint16  payloadId)

Get a payload by id from the WardenPayloadMgr::CachedChecks.

Parameters
payloadIdThe payload to fetched from WardenPayloadMgr::CachedChecks.
Returns
WardenCheck* A pointer to the WardenCheck payload.
97{
98 auto it = CachedChecks.find(payloadId);
99
100 if (it != CachedChecks.end())
101 {
102 return &it->second;
103 }
104
105 return nullptr;
106}

References CachedChecks.

◆ GetPayloadCountInQueue()

uint32 WardenPayloadMgr::GetPayloadCountInQueue ( )

Get the amount of payloads waiting in WardenPayloadMgr::QueuedPayloads.

Returns
The amount of payloads in queue.
143{
144 return QueuedPayloads.size();
145}

References QueuedPayloads.

◆ GetPayloadsInQueue()

std::list< uint16 > * WardenPayloadMgr::GetPayloadsInQueue ( )

Get payloads waiting in WardenPayloadMgr::QueuedPayloads.

Returns
The payloads in queue.
148{
149 return &QueuedPayloads;
150}

References QueuedPayloads.

◆ QueuePayload()

void WardenPayloadMgr::QueuePayload ( uint16  payloadId,
bool  pushToFront = false 
)

Queue the payload into the normal warden checks.

Parameters
payloadIdThe payloadId to be queued.
pushToFrontIf payload should be pushed to the front queue.
109{
110 auto it = CachedChecks.find(payloadId);
111
112 //Do not queue a payload if there is no payload matching the payloadId.
113 if (it == CachedChecks.end())
114 {
115 LOG_ERROR("warden", "Failed to queue payload id '{}' as it does not exist in CachedChecks.", payloadId);
116 return;
117 }
118
119 if (pushToFront)
120 {
121 QueuedPayloads.push_front(payloadId);
122 }
123 else
124 {
125 QueuedPayloads.push_back(payloadId);
126 }
127}

References CachedChecks, LOG_ERROR, and QueuedPayloads.

◆ RegisterPayload() [1/2]

uint16 WardenPayloadMgr::RegisterPayload ( const std::string &  payload)

Register a payload into cache and returns its payload id.

Parameters
payloadThe payload to be stored in WardenPayloadMgr::CachedChecks.
Returns
uint16 The payload id for use with WardenPayloadMgr::QueuePayload. Returns 0 if it failed to register.
Note
  • Payloads are truncated to 512 bytes on the client, you may have to register your payloads in chunks if they are larger than this.
44{
45 uint16 payloadId = GetFreePayloadId();
46
47 if (!payloadId || !RegisterPayload(payload, payloadId, false))
48 {
49 LOG_ERROR("warden", "Failed to register payload.");
50 return 0;
51 }
52
53 return payloadId;
54}
uint16 GetFreePayloadId()
Finds a free payload id in WardenPayloadMgr::CachedChecks.
Definition: WardenPayloadMgr.cpp:25
uint16 RegisterPayload(const std::string &payload)
Register a payload into cache and returns its payload id.
Definition: WardenPayloadMgr.cpp:43

References GetFreePayloadId(), LOG_ERROR, and RegisterPayload().

Referenced by RegisterPayload().

◆ RegisterPayload() [2/2]

bool WardenPayloadMgr::RegisterPayload ( std::string const &  payload,
uint16  payloadId,
bool  replace = false 
)

Register a payload into cache with a custom id and returns the result.

Parameters
payloadThe payload to be stored in WardenPayloadMgr::CachedChecks.
payloadIdThe payload id to be stored as the key in WardenPayloadMgr::CachedChecks.
replaceWhether the key should replace an existing entry value.
Returns
bool The payload insertion result. If exists it will return false, otherwise true.
Note
  • Payloads are truncated to 512 bytes on the client, you may have to register your payloads in chunks if they are larger than this.
  • It's a good idea to keep the value for payloadId between 9000-9999 for self defined payloads as they're the least likely occupied ids.
57{
58 //Payload id should be over or equal to the offset to prevent conflicts.
60 {
61 LOG_ERROR("warden", "Tried to register payloadId lower than '{}'.", WardenPayloadMgr::WardenPayloadOffsetMin);
62 return false;
63 }
64
65 auto it = CachedChecks.find(payloadId);
66 if (it != CachedChecks.end() && !replace)
67 {
68 LOG_ERROR("warden", "Payload Id '{}' already exists in CachedChecks.", payloadId);
69 return false;
70 }
71
72 WardenCheck wCheck;
74 wCheck.Str = payload;
75 wCheck.CheckId = payloadId;
76
77 std::string idStr = Acore::StringFormat("{:04}", payloadId);
78 ASSERT(idStr.size() == 4);
79 std::copy(idStr.begin(), idStr.end(), wCheck.IdStr.begin());
80
81 if (replace)
82 {
83 CachedChecks.erase(payloadId);
84 }
85
86 CachedChecks.emplace(payloadId, wCheck);
87
88 return true;
89}
#define ASSERT
Definition: Errors.h:68
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
Definition: WardenCheckMgr.h:44
std::array< char, 4 > IdStr
Definition: WardenCheckMgr.h:52
std::string Str
Definition: WardenCheckMgr.h:49
uint16 CheckId
Definition: WardenCheckMgr.h:51
uint8 Type
Definition: WardenCheckMgr.h:45
static uint32 constexpr WardenPayloadCheckType
The checktype used for warden payloads.
Definition: WardenPayloadMgr.h:125

References ASSERT, CachedChecks, WardenCheck::CheckId, WardenCheck::IdStr, LOG_ERROR, WardenCheck::Str, Acore::StringFormat(), WardenCheck::Type, WardenPayloadCheckType, and WardenPayloadOffsetMin.

◆ UnregisterPayload()

bool WardenPayloadMgr::UnregisterPayload ( uint16  payloadId)

Unregister a payload from cache and return if successful.

Parameters
payloadIdThe payload to removed from WardenPayloadMgr::CachedChecks.
Returns
bool If the payloadId was present.
92{
93 return CachedChecks.erase(payloadId);
94}

References CachedChecks.

Member Data Documentation

◆ CachedChecks

std::map<uint16, WardenCheck> WardenPayloadMgr::CachedChecks

◆ QueuedPayloads

std::list<uint16> WardenPayloadMgr::QueuedPayloads

The list of currently queued payload ids to be sent through Warden.

Referenced by ClearQueuedPayloads(), DequeuePayload(), GetPayloadCountInQueue(), GetPayloadsInQueue(), QueuePayload(), and WardenWin::RequestChecks().

◆ WardenPayloadCheckType

uint32 constexpr WardenPayloadMgr::WardenPayloadCheckType = 139
staticconstexpr

The checktype used for warden payloads.

Referenced by RegisterPayload().

◆ WardenPayloadOffsetMax

uint16 constexpr WardenPayloadMgr::WardenPayloadOffsetMax = 9999
staticconstexpr

The maximum id available for custom payloads.

Referenced by GetFreePayloadId().

◆ WardenPayloadOffsetMin

uint16 constexpr WardenPayloadMgr::WardenPayloadOffsetMin = 5000
staticconstexpr

The minimum id available for custom payloads.

Referenced by GetCheckPacketSize(), GetFreePayloadId(), WardenWin::HandleData(), RegisterPayload(), and WardenWin::RequestChecks().