[Code] PetitionList Global to Singleton Cleanup (#4944)

* [Code] PetitionList Global to Singleton Cleanup

* Update worldserver.cpp

* Update worldserver.cpp
This commit is contained in:
Alex King 2025-06-25 14:15:21 -04:00 committed by GitHub
parent 98eff43346
commit f3aaeff0a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 38 additions and 41 deletions

View File

@ -86,7 +86,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);
@ -2233,7 +2232,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();

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;

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() {

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) {

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;

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);
} }
} }

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;

View File

@ -68,7 +68,6 @@ extern Zone *zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern void Shutdown(); extern void Shutdown();
extern WorldServer worldserver; extern WorldServer worldserver;
extern PetitionList petition_list;
extern uint32 numclients; extern uint32 numclients;
extern volatile bool RunLoops; extern volatile bool RunLoops;
extern QuestParserCollection *parse; extern QuestParserCollection *parse;
@ -911,8 +910,8 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
std::cout << "Got Server Requested Petition List Refresh" << std::endl; std::cout << "Got Server Requested Petition List Refresh" << std::endl;
ServerPetitionUpdate_Struct* sus = (ServerPetitionUpdate_Struct*)pack->pBuffer; ServerPetitionUpdate_Struct* sus = (ServerPetitionUpdate_Struct*)pack->pBuffer;
// this was typoed to = instead of ==, not that it acts any different now though.. // this was typoed to = instead of ==, not that it acts any different now though..
if (sus->status == 0) petition_list.ReadDatabase(); if (sus->status == 0) PetitionList::Instance()->ReadDatabase();
else if (sus->status == 1) petition_list.ReadDatabase(); // Until I fix this to be better.... else if (sus->status == 1) PetitionList::Instance()->ReadDatabase(); // Until I fix this to be better....
break; break;
} }
case ServerOP_RezzPlayer: { case ServerOP_RezzPlayer: {

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;
@ -924,7 +923,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(
@ -1234,8 +1233,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();