[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 WorldServer worldserver;
extern uint32 numclients;
extern PetitionList petition_list;
void UpdateWindowTitle(char* iNewTitle);
@ -2233,7 +2232,7 @@ void Client::UpdateAdmin(bool from_database) {
if (m_pp.gm) {
LogInfo("[{}] - [{}] is a GM", __FUNCTION__ , GetName());
petition_list.UpdateGMQueue();
PetitionList::Instance()->UpdateGMQueue();
}
UpdateWho();

View File

@ -79,7 +79,6 @@ extern QueryServ* QServ;
extern Zone* zone;
extern volatile bool is_zone_loaded;
extern WorldServer worldserver;
extern PetitionList petition_list;
extern EntityList entity_list;
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);
return;
}
if (petition_list.DeletePetitionByCharName((char*)app->pBuffer))
if (PetitionList::Instance()->DeletePetitionByCharName((char*)app->pBuffer))
MessageString(Chat::White, PETITION_DELETED);
else
MessageString(Chat::White, PETITION_NO_DELETE);
@ -11736,7 +11735,7 @@ void Client::Handle_OP_Petition(const EQApplicationPacket *app)
}*/
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.");
return;
@ -11752,10 +11751,10 @@ void Client::Handle_OP_Petition(const EQApplicationPacket *app)
pet->SetPetitionText((char*)app->pBuffer);
pet->SetZone(zone->GetZoneID());
pet->SetUrgency(0);
petition_list.AddPetition(pet);
PetitionList::Instance()->AddPetition(pet);
database.InsertPetitionToDB(pet);
petition_list.UpdateGMQueue();
petition_list.UpdateZoneListQueue();
PetitionList::Instance()->UpdateGMQueue();
PetitionList::Instance()->UpdateZoneListQueue();
worldserver.SendEmoteMessage(
0,
0,
@ -11786,16 +11785,16 @@ void Client::Handle_OP_PetitionCheckIn(const EQApplicationPacket *app)
}
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())
pet->SetUrgency(inpet->urgency);
pet->SetLastGM(GetName());
pet->SetGMText(inpet->gmtext);
pet->SetCheckedOut(false);
petition_list.UpdatePetition(pet);
petition_list.UpdateGMQueue();
petition_list.UpdateZoneListQueue();
PetitionList::Instance()->UpdatePetition(pet);
PetitionList::Instance()->UpdateGMQueue();
PetitionList::Instance()->UpdateZoneListQueue();
return;
}
@ -11809,14 +11808,14 @@ void Client::Handle_OP_PetitionCheckout(const EQApplicationPacket *app)
Message(Chat::Red, "Error: World server disconnected");
else {
uint32 getpetnum = *((uint32*)app->pBuffer);
Petition* getpet = petition_list.GetPetitionByID(getpetnum);
Petition* getpet = PetitionList::Instance()->GetPetitionByID(getpetnum);
if (getpet != 0) {
getpet->AddCheckout();
getpet->SetCheckedOut(true);
getpet->SendPetitionToPlayer(CastToClient());
petition_list.UpdatePetition(getpet);
petition_list.UpdateGMQueue();
petition_list.UpdateZoneListQueue();
PetitionList::Instance()->UpdatePetition(getpet);
PetitionList::Instance()->UpdateGMQueue();
PetitionList::Instance()->UpdateZoneListQueue();
}
}
return;
@ -11836,16 +11835,16 @@ void Client::Handle_OP_PetitionDelete(const EQApplicationPacket *app)
pet->senttime = 0;
strcpy(pet->accountid, "");
strcpy(pet->gmsenttoo, "");
pet->quetotal = petition_list.GetTotalPetitions();
pet->quetotal = PetitionList::Instance()->GetTotalPetitions();
strcpy(pet->charname, "");
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;
petition_list.ClearPetitions();
petition_list.UpdateGMQueue();
petition_list.ReadDatabase();
petition_list.UpdateZoneListQueue();
PetitionList::Instance()->ClearPetitions();
PetitionList::Instance()->UpdateGMQueue();
PetitionList::Instance()->ReadDatabase();
PetitionList::Instance()->UpdateZoneListQueue();
return;
}
@ -11880,12 +11879,12 @@ void Client::Handle_OP_PetitionUnCheckout(const EQApplicationPacket *app)
Message(Chat::Red, "Error: World server disconnected");
else {
uint32 getpetnum = *((uint32*)app->pBuffer);
Petition* getpet = petition_list.GetPetitionByID(getpetnum);
Petition* getpet = PetitionList::Instance()->GetPetitionByID(getpetnum);
if (getpet != 0) {
getpet->SetCheckedOut(false);
petition_list.UpdatePetition(getpet);
petition_list.UpdateGMQueue();
petition_list.UpdateZoneListQueue();
PetitionList::Instance()->UpdatePetition(getpet);
PetitionList::Instance()->UpdateGMQueue();
PetitionList::Instance()->UpdateZoneListQueue();
}
}
return;

View File

@ -57,7 +57,6 @@ extern QueryServ* QServ;
extern Zone* zone;
extern volatile bool is_zone_loaded;
extern WorldServer worldserver;
extern PetitionList petition_list;
extern EntityList entity_list;
bool Client::Process() {

View File

@ -55,7 +55,6 @@ extern Zone *zone;
extern volatile bool is_zone_loaded;
extern WorldServer worldserver;
extern uint32 numclients;
extern PetitionList petition_list;
extern char errorname[32];
@ -3447,7 +3446,7 @@ void EntityList::SendPetitionToAdmins(Petition *pet)
strcpy(pcus->accountid, pet->GetAccountName());
strcpy(pcus->charname, pet->GetCharName());
}
pcus->quetotal = petition_list.GetTotalPetitions();
pcus->quetotal = PetitionList::Instance()->GetTotalPetitions();
auto it = client_list.begin();
while (it != client_list.end()) {
if (it->second->CastToClient()->Admin() >= AccountStatus::QuestTroupe) {
@ -3472,7 +3471,7 @@ void EntityList::ClearClientPetitionQueue()
strcpy(pet->accountid, "");
strcpy(pet->gmsenttoo, "");
strcpy(pet->charname, "");
pet->quetotal = petition_list.GetTotalPetitions();
pet->quetotal = PetitionList::Instance()->GetTotalPetitions();
auto it = client_list.begin();
while (it != client_list.end()) {
if (it->second->CastToClient()->Admin() >= AccountStatus::GMAdmin) {

View File

@ -9,7 +9,6 @@
#include "../common/repositories/guild_bank_repository.h"
#include "../zone/petitions.h"
extern PetitionList petition_list;
//extern GuildRanks_Struct guilds[512];
//extern ZoneDatabase database;

View File

@ -38,8 +38,6 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
#include "petitions.h"
#include "worldserver.h"
PetitionList petition_list;
extern WorldServer worldserver;
void Petition::SendPetitionToPlayer(Client* clientto) {
@ -288,7 +286,7 @@ void ZoneDatabase::RefreshPetitionsFromDB()
newpet->SetCheckedOut(true);
else
newpet->SetCheckedOut(false);
petition_list.AddPetition(newpet);
PetitionList::Instance()->AddPetition(newpet);
}
}

View File

@ -112,6 +112,12 @@ public:
bool FindPetitionByAccountName(const char* acctname);
bool DeletePetitionByCharName(const char* charname);
static PetitionList* Instance()
{
static PetitionList instance;
return &instance;
}
private:
LinkedList<Petition*> list;
Mutex PList_Mutex;

View File

@ -68,7 +68,6 @@ extern Zone *zone;
extern volatile bool is_zone_loaded;
extern void Shutdown();
extern WorldServer worldserver;
extern PetitionList petition_list;
extern uint32 numclients;
extern volatile bool RunLoops;
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;
ServerPetitionUpdate_Struct* sus = (ServerPetitionUpdate_Struct*)pack->pBuffer;
// this was typoed to = instead of ==, not that it acts any different now though..
if (sus->status == 0) petition_list.ReadDatabase();
else if (sus->status == 1) petition_list.ReadDatabase(); // Until I fix this to be better....
if (sus->status == 0) PetitionList::Instance()->ReadDatabase();
else if (sus->status == 1) PetitionList::Instance()->ReadDatabase(); // Until I fix this to be better....
break;
}
case ServerOP_RezzPlayer: {

View File

@ -81,7 +81,6 @@
#endif
extern bool staticzone;
extern PetitionList petition_list;
extern QuestParserCollection* parse;
extern uint32 numclients;
extern WorldServer worldserver;
@ -924,7 +923,7 @@ void Zone::Shutdown(bool quiet)
GetInstanceVersion(),
GetInstanceID()
);
petition_list.ClearPetitions();
PetitionList::Instance()->ClearPetitions();
SetZoneHasCurrentTime(false);
if (!quiet) {
LogInfo(
@ -1234,8 +1233,8 @@ bool Zone::Init(bool is_static) {
LoadMercenarySpells();
}
petition_list.ClearPetitions();
petition_list.ReadDatabase();
PetitionList::Instance()->ClearPetitions();
PetitionList::Instance()->ReadDatabase();
guild_mgr.LoadGuilds();