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

#include "PetitionMgr.h"

Public Member Functions

void LoadPetitions ()
 
void LoadSignatures ()
 
void AddPetition (ObjectGuid petitionGUID, ObjectGuid ownerGuid, std::string const &name, uint8 type)
 
void RemovePetition (ObjectGuid petitionGUID)
 
void RemovePetitionByOwnerAndType (ObjectGuid ownerGuid, uint8 type)
 
Petition const * GetPetition (ObjectGuid petitionGUID) const
 
Petition const * GetPetitionByOwnerWithType (ObjectGuid ownerGuid, uint8 type) const
 
PetitionContainerGetPetitionStore ()
 
void AddSignature (ObjectGuid petitionGUID, uint32 accountId, ObjectGuid playerGuid)
 
void RemoveSignaturesByPlayer (ObjectGuid playerGuid)
 
void RemoveSignaturesByPlayerAndType (ObjectGuid playerGuid, uint8 type)
 
Signatures const * GetSignature (ObjectGuid petitionGUID) const
 
SignatureContainerGetSignatureStore ()
 

Static Public Member Functions

static PetitionMgrinstance ()
 

Protected Attributes

PetitionContainer PetitionStore
 
SignatureContainer SignatureStore
 

Private Member Functions

 PetitionMgr ()
 
 ~PetitionMgr ()
 

Detailed Description

Constructor & Destructor Documentation

◆ PetitionMgr()

PetitionMgr::PetitionMgr ( )
private
27{
28}

◆ ~PetitionMgr()

PetitionMgr::~PetitionMgr ( )
private
31{
32}

Member Function Documentation

◆ AddPetition()

void PetitionMgr::AddPetition ( ObjectGuid  petitionGUID,
ObjectGuid  ownerGuid,
std::string const &  name,
uint8  type 
)
91{
92 Petition& p = PetitionStore[petitionGUID];
93 p.petitionGuid = petitionGUID;
94 p.ownerGuid = ownerGuid;
95 p.petitionName = name;
96 p.petitionType = type;
97
98 Signatures& s = SignatureStore[petitionGUID];
99 s.petitionGuid = petitionGUID;
100 s.signatureMap.clear();
101}
Definition: PetitionMgr.h:40
ObjectGuid petitionGuid
Definition: PetitionMgr.h:41
ObjectGuid ownerGuid
Definition: PetitionMgr.h:42
std::string petitionName
Definition: PetitionMgr.h:44
uint8 petitionType
Definition: PetitionMgr.h:43
Definition: PetitionMgr.h:48
SignatureMap signatureMap
Definition: PetitionMgr.h:50
ObjectGuid petitionGuid
Definition: PetitionMgr.h:49
PetitionContainer PetitionStore
Definition: PetitionMgr.h:84
SignatureContainer SignatureStore
Definition: PetitionMgr.h:85

References Petition::ownerGuid, Petition::petitionGuid, Signatures::petitionGuid, Petition::petitionName, PetitionStore, Petition::petitionType, Signatures::signatureMap, and SignatureStore.

Referenced by LoadPetitions().

◆ AddSignature()

void PetitionMgr::AddSignature ( ObjectGuid  petitionGUID,
uint32  accountId,
ObjectGuid  playerGuid 
)
156{
157 Signatures& s = SignatureStore[petitionGUID];
158 s.signatureMap[playerGuid] = accountId;
159}

References Signatures::signatureMap, and SignatureStore.

Referenced by LoadSignatures().

◆ GetPetition()

Petition const * PetitionMgr::GetPetition ( ObjectGuid  petitionGUID) const
139{
140 PetitionContainer::const_iterator itr = PetitionStore.find(petitionGUID);
141 if (itr != PetitionStore.end())
142 return &itr->second;
143 return nullptr;
144}

References PetitionStore.

◆ GetPetitionByOwnerWithType()

Petition const * PetitionMgr::GetPetitionByOwnerWithType ( ObjectGuid  ownerGuid,
uint8  type 
) const
147{
148 for (PetitionContainer::const_iterator itr = PetitionStore.begin(); itr != PetitionStore.end(); ++itr)
149 if (itr->second.ownerGuid == ownerGuid && itr->second.petitionType == type)
150 return &itr->second;
151
152 return nullptr;
153}

References PetitionStore.

◆ GetPetitionStore()

PetitionContainer * PetitionMgr::GetPetitionStore ( )
inline
74{ return &PetitionStore; }

References PetitionStore.

◆ GetSignature()

Signatures const * PetitionMgr::GetSignature ( ObjectGuid  petitionGUID) const
162{
163 SignatureContainer::const_iterator itr = SignatureStore.find(petitionGUID);
164 if (itr != SignatureStore.end())
165 return &itr->second;
166 return nullptr;
167}

References SignatureStore.

◆ GetSignatureStore()

SignatureContainer * PetitionMgr::GetSignatureStore ( )
inline
81{ return &SignatureStore; }

References SignatureStore.

◆ instance()

PetitionMgr * PetitionMgr::instance ( )
static
35{
36 static PetitionMgr instance;
37 return &instance;
38}
Definition: PetitionMgr.h:57
static PetitionMgr * instance()
Definition: PetitionMgr.cpp:34

References instance().

Referenced by instance().

◆ LoadPetitions()

void PetitionMgr::LoadPetitions ( )
41{
42 uint32 oldMSTime = getMSTime();
43 PetitionStore.clear();
44
45 QueryResult result = CharacterDatabase.Query("SELECT ownerguid, petitionguid, name, type FROM petition");
46 if (!result)
47 {
48 LOG_WARN("server.loading", ">> Loaded 0 Petitions!");
49 LOG_INFO("server.loading", " ");
50 return;
51 }
52
53 uint32 count = 0;
54 do
55 {
56 Field* fields = result->Fetch();
57 AddPetition(ObjectGuid::Create<HighGuid::Item>(fields[1].Get<uint32>()), ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>()), fields[2].Get<std::string>(), fields[3].Get<uint8>());
58 ++count;
59 } while (result->NextRow());
60
61 LOG_INFO("server.loading", ">> Loaded {} Petitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
62 LOG_INFO("server.loading", " ");
63}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
Class used to access individual fields of database query result.
Definition: Field.h:99
void AddPetition(ObjectGuid petitionGUID, ObjectGuid ownerGuid, std::string const &name, uint8 type)
Definition: PetitionMgr.cpp:90

References AddPetition(), CharacterDatabase, getMSTime(), GetMSTimeDiffToNow(), LOG_INFO, LOG_WARN, and PetitionStore.

◆ LoadSignatures()

void PetitionMgr::LoadSignatures ( )
66{
67 uint32 oldMSTime = getMSTime();
68 SignatureStore.clear();
69
70 QueryResult result = CharacterDatabase.Query("SELECT petitionguid, playerguid, player_account FROM petition_sign");
71 if (!result)
72 {
73 LOG_WARN("server.loading", ">> Loaded 0 Petition signs!");
74 LOG_INFO("server.loading", " ");
75 return;
76 }
77
78 uint32 count = 0;
79 do
80 {
81 Field* fields = result->Fetch();
82 AddSignature(ObjectGuid::Create<HighGuid::Item>(fields[0].Get<uint32>()), fields[2].Get<uint32>(), ObjectGuid::Create<HighGuid::Player>(fields[1].Get<uint32>()));
83 ++count;
84 } while (result->NextRow());
85
86 LOG_INFO("server.loading", ">> Loaded {} Petition signs in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
87 LOG_INFO("server.loading", " ");
88}
void AddSignature(ObjectGuid petitionGUID, uint32 accountId, ObjectGuid playerGuid)
Definition: PetitionMgr.cpp:155

References AddSignature(), CharacterDatabase, getMSTime(), GetMSTimeDiffToNow(), LOG_INFO, LOG_WARN, and SignatureStore.

◆ RemovePetition()

void PetitionMgr::RemovePetition ( ObjectGuid  petitionGUID)
104{
105 PetitionStore.erase(petitionGUID);
106
107 // remove signatures
108 SignatureStore.erase(petitionGUID);
109}

References PetitionStore, and SignatureStore.

◆ RemovePetitionByOwnerAndType()

void PetitionMgr::RemovePetitionByOwnerAndType ( ObjectGuid  ownerGuid,
uint8  type 
)
112{
113 for (PetitionContainer::iterator itr = PetitionStore.begin(); itr != PetitionStore.end();)
114 {
115 if (itr->second.ownerGuid == ownerGuid && (!type || type == itr->second.petitionType))
116 {
117 // Remove invalid charter item
118 if (type == itr->second.petitionType)
119 {
120 if (Player* owner = ObjectAccessor::FindConnectedPlayer(ownerGuid))
121 {
122 if (Item* item = owner->GetItemByGuid(itr->first))
123 {
124 owner->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
125 }
126 }
127 }
128
129 // remove signatures
130 SignatureStore.erase(itr->first);
131 PetitionStore.erase(itr++);
132 }
133 else
134 ++itr;
135 }
136}
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:260
Definition: Item.h:214
Definition: Player.h:1056

References ObjectAccessor::FindConnectedPlayer(), PetitionStore, and SignatureStore.

◆ RemoveSignaturesByPlayer()

void PetitionMgr::RemoveSignaturesByPlayer ( ObjectGuid  playerGuid)
170{
171 for (SignatureContainer::iterator itr = SignatureStore.begin(); itr != SignatureStore.end(); ++itr)
172 {
173 SignatureMap::iterator signItr = itr->second.signatureMap.find(playerGuid);
174 if (signItr != itr->second.signatureMap.end())
175 itr->second.signatureMap.erase(signItr);
176 }
177}

References SignatureStore.

◆ RemoveSignaturesByPlayerAndType()

void PetitionMgr::RemoveSignaturesByPlayerAndType ( ObjectGuid  playerGuid,
uint8  type 
)
180{
181 for (SignatureContainer::iterator itr = SignatureStore.begin(); itr != SignatureStore.end(); ++itr)
182 {
183 Petition const* petition = sPetitionMgr->GetPetition(itr->first);
184 if (!petition || petition->petitionType != type)
185 continue;
186
187 SignatureMap::iterator signItr = itr->second.signatureMap.find(playerGuid);
188 if (signItr != itr->second.signatureMap.end())
189 itr->second.signatureMap.erase(signItr);
190 }
191}
#define sPetitionMgr
Definition: PetitionMgr.h:88

References Petition::petitionType, SignatureStore, and sPetitionMgr.

Member Data Documentation

◆ PetitionStore

◆ SignatureStore