From 1e6a4dac78ca5f9abc4dda55c7df2f8a411e6be6 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 25 Jun 2025 15:25:37 -0400 Subject: [PATCH] [Code] UCSConnection Global to Singleton Cleanup (#4937) Co-authored-by: Chris Miles --- world/eqemu_api_world_data_service.cpp | 1 - world/main.cpp | 10 +++++++--- world/ucs.h | 6 ++++++ world/world_boot.cpp | 4 ++-- world/world_boot.h | 2 -- world/zonelist.cpp | 2 +- world/zoneserver.cpp | 7 +++---- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/world/eqemu_api_world_data_service.cpp b/world/eqemu_api_world_data_service.cpp index 9ec4ebc48..e3a75d052 100644 --- a/world/eqemu_api_world_data_service.cpp +++ b/world/eqemu_api_world_data_service.cpp @@ -16,7 +16,6 @@ extern ZSList zoneserver_list; extern ClientList client_list; extern WorldGuildManager guild_mgr; -extern UCSConnection UCSLink; extern QueryServConnection QSLink; void callGetZoneList(Json::Value &response) diff --git a/world/main.cpp b/world/main.cpp index b79021416..666a01a45 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -94,7 +94,11 @@ ClientList client_list; GroupLFPList LFPGroupList; ZSList zoneserver_list; +<<<<<<< kinglykrab/ucsconnection-global-to-singleton +LoginServerList loginserverlist; +======= UCSConnection UCSLink; +>>>>>>> master QueryServConnection QSLink; LauncherList launcher_list; AdventureManager adventure_manager; @@ -296,7 +300,7 @@ int main(int argc, char **argv) connection->GetUUID() ); - UCSLink.SetConnection(connection); + UCSConnection::Instance()->SetConnection(connection); zoneserver_list.UpdateUCSServerAvailable(); } @@ -306,11 +310,11 @@ int main(int argc, char **argv) "UCS", [](std::shared_ptr connection) { LogInfo("Connection lost from UCS Server [{}]", connection->GetUUID()); - auto ucs_connection = UCSLink.GetConnection(); + auto ucs_connection = UCSConnection::Instance()->GetConnection(); if (ucs_connection->GetUUID() == connection->GetUUID()) { LogInfo("Removing currently active UCS connection"); - UCSLink.SetConnection(nullptr); + UCSConnection::Instance()->SetConnection(nullptr); zoneserver_list.UpdateUCSServerAvailable(false); } } diff --git a/world/ucs.h b/world/ucs.h index 04ec17471..a324d91fc 100644 --- a/world/ucs.h +++ b/world/ucs.h @@ -19,6 +19,12 @@ public: const std::shared_ptr &GetConnection() const; inline bool IsConnected() const { return connection->Handle() ? connection->Handle()->IsConnected() : false; } + static UCSConnection* Instance() + { + static UCSConnection instance; + return &instance; + } + private: inline std::string GetIP() const { return (connection && connection->Handle()) ? connection->Handle()->RemoteIP() : 0; } std::shared_ptr connection; diff --git a/world/world_boot.cpp b/world/world_boot.cpp index cbe2513cb..6ec44e2c0 100644 --- a/world/world_boot.cpp +++ b/world/world_boot.cpp @@ -625,14 +625,14 @@ void WorldBoot::Shutdown() void WorldBoot::SendDiscordMessage(int webhook_id, const std::string &message) { - if (UCSLink.IsConnected()) { + if (UCSConnection::Instance()->IsConnected()) { auto pack = new ServerPacket(ServerOP_DiscordWebhookMessage, sizeof(DiscordWebhookMessage_Struct) + 1); auto *q = (DiscordWebhookMessage_Struct *) pack->pBuffer; strn0cpy(q->message, message.c_str(), 2000); q->webhook_id = webhook_id; - UCSLink.SendPacket(pack); + UCSConnection::Instance()->SendPacket(pack); safe_delete(pack); } diff --git a/world/world_boot.h b/world/world_boot.h index 2149a6ea5..e58b900c5 100644 --- a/world/world_boot.h +++ b/world/world_boot.h @@ -6,8 +6,6 @@ #include "../common/discord/discord.h" #include "ucs.h" -extern UCSConnection UCSLink; - class WorldBoot { public: static void GMSayHookCallBackProcessWorld(uint16 log_category, const char *func, std::string message); diff --git a/world/zonelist.cpp b/world/zonelist.cpp index 0f1b6b445..265747fbc 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -984,7 +984,7 @@ void ZSList::SendServerReload(ServerReload::Type type, uchar *packet) } else if (type == ServerReload::Type::Logs) { EQEmuLogSys::Instance()->LoadLogDatabaseSettings(); player_event_logs.ReloadSettings(); - UCSLink.SendPacket(&pack); + UCSConnection::Instance()->SendPacket(&pack); QSLink.SendPacket(&pack); } else if (type == ServerReload::Type::Tasks) { SharedTaskManager::Instance()->LoadTaskData(); diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 7f2afb232..83a6bfdd0 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -58,7 +58,6 @@ extern ZSList zoneserver_list; extern volatile bool RunLoops; extern volatile bool UCSServerAvailable_; extern AdventureManager adventure_manager; -extern UCSConnection UCSLink; extern QueryServConnection QSLink; void CatchSignal(int sig_num); @@ -379,7 +378,7 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { // if discord enabled for event, ship to UCS to process if (player_event_logs.IsEventDiscordEnabled(n.player_event_log.event_type_id)) { - UCSLink.SendPacket(pack); + UCSConnection::Instance()->SendPacket(pack); } break; @@ -433,7 +432,7 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { auto scm = (ServerChannelMessage_Struct*) pack->pBuffer; if (scm->chan_num == ChatChannel_UCSRelay) { - UCSLink.SendMessage(scm->from, scm->message); + UCSConnection::Instance()->SendMessage(scm->from, scm->message); break; } @@ -1342,7 +1341,7 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { } case ServerOP_DiscordWebhookMessage: case ServerOP_UCSMailMessage: { - UCSLink.SendPacket(pack); + UCSConnection::Instance()->SendPacket(pack); break; } case ServerOP_UCSServerStatusRequest: {