[Code] PetitionList Global to Singleton Cleanup

This commit is contained in:
Kinglykrab
2025-06-20 23:06:57 -04:00
parent 1be7e56b86
commit 451a0c03e5
8 changed files with 36 additions and 38 deletions
+1 -2
View File
@@ -85,7 +85,6 @@ extern Zone* zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern WorldServer worldserver; extern WorldServer worldserver;
extern uint32 numclients; extern uint32 numclients;
extern PetitionList petition_list;
void UpdateWindowTitle(char* iNewTitle); void UpdateWindowTitle(char* iNewTitle);
@@ -2232,7 +2231,7 @@ void Client::UpdateAdmin(bool from_database) {
if (m_pp.gm) { if (m_pp.gm) {
LogInfo("[{}] - [{}] is a GM", __FUNCTION__ , GetName()); LogInfo("[{}] - [{}] is a GM", __FUNCTION__ , GetName());
petition_list.UpdateGMQueue(); PetitionList::Instance()->UpdateGMQueue();
} }
UpdateWho(); UpdateWho();
+23 -24
View File
@@ -79,7 +79,6 @@ extern QueryServ* QServ;
extern Zone* zone; extern Zone* zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern WorldServer worldserver; extern WorldServer worldserver;
extern PetitionList petition_list;
extern EntityList entity_list; extern EntityList entity_list;
typedef void (Client::*ClientPacketProc)(const EQApplicationPacket *app); typedef void (Client::*ClientPacketProc)(const EQApplicationPacket *app);
@@ -11058,7 +11057,7 @@ void Client::Handle_OP_PDeletePetition(const EQApplicationPacket *app)
LogError("Wrong size: OP_PDeletePetition, size=[{}], expected [{}]", app->size, 2); LogError("Wrong size: OP_PDeletePetition, size=[{}], expected [{}]", app->size, 2);
return; return;
} }
if (petition_list.DeletePetitionByCharName((char*)app->pBuffer)) if (PetitionList::Instance()->DeletePetitionByCharName((char*)app->pBuffer))
MessageString(Chat::White, PETITION_DELETED); MessageString(Chat::White, PETITION_DELETED);
else else
MessageString(Chat::White, PETITION_NO_DELETE); MessageString(Chat::White, PETITION_NO_DELETE);
@@ -11736,7 +11735,7 @@ void Client::Handle_OP_Petition(const EQApplicationPacket *app)
}*/ }*/
else else
{ {
if (petition_list.FindPetitionByAccountName(AccountName())) if (PetitionList::Instance()->FindPetitionByAccountName(AccountName()))
{ {
Message(Chat::White, "You already have a petition in the queue, you must wait for it to be answered or use /deletepetition to delete it."); Message(Chat::White, "You already have a petition in the queue, you must wait for it to be answered or use /deletepetition to delete it.");
return; return;
@@ -11752,10 +11751,10 @@ void Client::Handle_OP_Petition(const EQApplicationPacket *app)
pet->SetPetitionText((char*)app->pBuffer); pet->SetPetitionText((char*)app->pBuffer);
pet->SetZone(zone->GetZoneID()); pet->SetZone(zone->GetZoneID());
pet->SetUrgency(0); pet->SetUrgency(0);
petition_list.AddPetition(pet); PetitionList::Instance()->AddPetition(pet);
database.InsertPetitionToDB(pet); database.InsertPetitionToDB(pet);
petition_list.UpdateGMQueue(); PetitionList::Instance()->UpdateGMQueue();
petition_list.UpdateZoneListQueue(); PetitionList::Instance()->UpdateZoneListQueue();
worldserver.SendEmoteMessage( worldserver.SendEmoteMessage(
0, 0,
0, 0,
@@ -11786,16 +11785,16 @@ void Client::Handle_OP_PetitionCheckIn(const EQApplicationPacket *app)
} }
Petition_Struct* inpet = (Petition_Struct*)app->pBuffer; Petition_Struct* inpet = (Petition_Struct*)app->pBuffer;
Petition* pet = petition_list.GetPetitionByID(inpet->petnumber); Petition* pet = PetitionList::Instance()->GetPetitionByID(inpet->petnumber);
//if (inpet->urgency != pet->GetUrgency()) //if (inpet->urgency != pet->GetUrgency())
pet->SetUrgency(inpet->urgency); pet->SetUrgency(inpet->urgency);
pet->SetLastGM(GetName()); pet->SetLastGM(GetName());
pet->SetGMText(inpet->gmtext); pet->SetGMText(inpet->gmtext);
pet->SetCheckedOut(false); pet->SetCheckedOut(false);
petition_list.UpdatePetition(pet); PetitionList::Instance()->UpdatePetition(pet);
petition_list.UpdateGMQueue(); PetitionList::Instance()->UpdateGMQueue();
petition_list.UpdateZoneListQueue(); PetitionList::Instance()->UpdateZoneListQueue();
return; return;
} }
@@ -11809,14 +11808,14 @@ void Client::Handle_OP_PetitionCheckout(const EQApplicationPacket *app)
Message(Chat::Red, "Error: World server disconnected"); Message(Chat::Red, "Error: World server disconnected");
else { else {
uint32 getpetnum = *((uint32*)app->pBuffer); uint32 getpetnum = *((uint32*)app->pBuffer);
Petition* getpet = petition_list.GetPetitionByID(getpetnum); Petition* getpet = PetitionList::Instance()->GetPetitionByID(getpetnum);
if (getpet != 0) { if (getpet != 0) {
getpet->AddCheckout(); getpet->AddCheckout();
getpet->SetCheckedOut(true); getpet->SetCheckedOut(true);
getpet->SendPetitionToPlayer(CastToClient()); getpet->SendPetitionToPlayer(CastToClient());
petition_list.UpdatePetition(getpet); PetitionList::Instance()->UpdatePetition(getpet);
petition_list.UpdateGMQueue(); PetitionList::Instance()->UpdateGMQueue();
petition_list.UpdateZoneListQueue(); PetitionList::Instance()->UpdateZoneListQueue();
} }
} }
return; return;
@@ -11836,16 +11835,16 @@ void Client::Handle_OP_PetitionDelete(const EQApplicationPacket *app)
pet->senttime = 0; pet->senttime = 0;
strcpy(pet->accountid, ""); strcpy(pet->accountid, "");
strcpy(pet->gmsenttoo, ""); strcpy(pet->gmsenttoo, "");
pet->quetotal = petition_list.GetTotalPetitions(); pet->quetotal = PetitionList::Instance()->GetTotalPetitions();
strcpy(pet->charname, ""); strcpy(pet->charname, "");
FastQueuePacket(&outapp); FastQueuePacket(&outapp);
if (petition_list.DeletePetition(pet->petnumber) == -1) if (PetitionList::Instance()->DeletePetition(pet->petnumber) == -1)
std::cout << "Something is borked with: " << pet->petnumber << std::endl; std::cout << "Something is borked with: " << pet->petnumber << std::endl;
petition_list.ClearPetitions(); PetitionList::Instance()->ClearPetitions();
petition_list.UpdateGMQueue(); PetitionList::Instance()->UpdateGMQueue();
petition_list.ReadDatabase(); PetitionList::Instance()->ReadDatabase();
petition_list.UpdateZoneListQueue(); PetitionList::Instance()->UpdateZoneListQueue();
return; return;
} }
@@ -11880,12 +11879,12 @@ void Client::Handle_OP_PetitionUnCheckout(const EQApplicationPacket *app)
Message(Chat::Red, "Error: World server disconnected"); Message(Chat::Red, "Error: World server disconnected");
else { else {
uint32 getpetnum = *((uint32*)app->pBuffer); uint32 getpetnum = *((uint32*)app->pBuffer);
Petition* getpet = petition_list.GetPetitionByID(getpetnum); Petition* getpet = PetitionList::Instance()->GetPetitionByID(getpetnum);
if (getpet != 0) { if (getpet != 0) {
getpet->SetCheckedOut(false); getpet->SetCheckedOut(false);
petition_list.UpdatePetition(getpet); PetitionList::Instance()->UpdatePetition(getpet);
petition_list.UpdateGMQueue(); PetitionList::Instance()->UpdateGMQueue();
petition_list.UpdateZoneListQueue(); PetitionList::Instance()->UpdateZoneListQueue();
} }
} }
return; return;
-1
View File
@@ -57,7 +57,6 @@ extern QueryServ* QServ;
extern Zone* zone; extern Zone* zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern WorldServer worldserver; extern WorldServer worldserver;
extern PetitionList petition_list;
extern EntityList entity_list; extern EntityList entity_list;
bool Client::Process() { bool Client::Process() {
+2 -3
View File
@@ -55,7 +55,6 @@ extern Zone *zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern WorldServer worldserver; extern WorldServer worldserver;
extern uint32 numclients; extern uint32 numclients;
extern PetitionList petition_list;
extern char errorname[32]; extern char errorname[32];
@@ -3447,7 +3446,7 @@ void EntityList::SendPetitionToAdmins(Petition *pet)
strcpy(pcus->accountid, pet->GetAccountName()); strcpy(pcus->accountid, pet->GetAccountName());
strcpy(pcus->charname, pet->GetCharName()); strcpy(pcus->charname, pet->GetCharName());
} }
pcus->quetotal = petition_list.GetTotalPetitions(); pcus->quetotal = PetitionList::Instance()->GetTotalPetitions();
auto it = client_list.begin(); auto it = client_list.begin();
while (it != client_list.end()) { while (it != client_list.end()) {
if (it->second->CastToClient()->Admin() >= AccountStatus::QuestTroupe) { if (it->second->CastToClient()->Admin() >= AccountStatus::QuestTroupe) {
@@ -3472,7 +3471,7 @@ void EntityList::ClearClientPetitionQueue()
strcpy(pet->accountid, ""); strcpy(pet->accountid, "");
strcpy(pet->gmsenttoo, ""); strcpy(pet->gmsenttoo, "");
strcpy(pet->charname, ""); strcpy(pet->charname, "");
pet->quetotal = petition_list.GetTotalPetitions(); pet->quetotal = PetitionList::Instance()->GetTotalPetitions();
auto it = client_list.begin(); auto it = client_list.begin();
while (it != client_list.end()) { while (it != client_list.end()) {
if (it->second->CastToClient()->Admin() >= AccountStatus::GMAdmin) { if (it->second->CastToClient()->Admin() >= AccountStatus::GMAdmin) {
-1
View File
@@ -9,7 +9,6 @@
#include "../common/repositories/guild_bank_repository.h" #include "../common/repositories/guild_bank_repository.h"
#include "../zone/petitions.h" #include "../zone/petitions.h"
extern PetitionList petition_list;
//extern GuildRanks_Struct guilds[512]; //extern GuildRanks_Struct guilds[512];
//extern ZoneDatabase database; //extern ZoneDatabase database;
+1 -3
View File
@@ -38,8 +38,6 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
#include "petitions.h" #include "petitions.h"
#include "worldserver.h" #include "worldserver.h"
PetitionList petition_list;
extern WorldServer worldserver; extern WorldServer worldserver;
void Petition::SendPetitionToPlayer(Client* clientto) { void Petition::SendPetitionToPlayer(Client* clientto) {
@@ -288,7 +286,7 @@ void ZoneDatabase::RefreshPetitionsFromDB()
newpet->SetCheckedOut(true); newpet->SetCheckedOut(true);
else else
newpet->SetCheckedOut(false); newpet->SetCheckedOut(false);
petition_list.AddPetition(newpet); PetitionList::Instance()->AddPetition(newpet);
} }
} }
+6
View File
@@ -112,6 +112,12 @@ public:
bool FindPetitionByAccountName(const char* acctname); bool FindPetitionByAccountName(const char* acctname);
bool DeletePetitionByCharName(const char* charname); bool DeletePetitionByCharName(const char* charname);
static PetitionList* Instance()
{
static PetitionList instance;
return &instance;
}
private: private:
LinkedList<Petition*> list; LinkedList<Petition*> list;
Mutex PList_Mutex; Mutex PList_Mutex;
+3 -4
View File
@@ -81,7 +81,6 @@
#endif #endif
extern bool staticzone; extern bool staticzone;
extern PetitionList petition_list;
extern QuestParserCollection* parse; extern QuestParserCollection* parse;
extern uint32 numclients; extern uint32 numclients;
extern WorldServer worldserver; extern WorldServer worldserver;
@@ -926,7 +925,7 @@ void Zone::Shutdown(bool quiet)
GetInstanceVersion(), GetInstanceVersion(),
GetInstanceID() GetInstanceID()
); );
petition_list.ClearPetitions(); PetitionList::Instance()->ClearPetitions();
SetZoneHasCurrentTime(false); SetZoneHasCurrentTime(false);
if (!quiet) { if (!quiet) {
LogInfo( LogInfo(
@@ -1236,8 +1235,8 @@ bool Zone::Init(bool is_static) {
LoadMercenarySpells(); LoadMercenarySpells();
} }
petition_list.ClearPetitions(); PetitionList::Instance()->ClearPetitions();
petition_list.ReadDatabase(); PetitionList::Instance()->ReadDatabase();
guild_mgr.LoadGuilds(); guild_mgr.LoadGuilds();