diff --git a/world/eqemu_api_world_data_service.cpp b/world/eqemu_api_world_data_service.cpp index 96b410d04..ee25f4463 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 8c5c66ee2..c1ec78a46 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -97,7 +97,6 @@ ClientList client_list; GroupLFPList LFPGroupList; ZSList zoneserver_list; LoginServerList loginserverlist; -UCSConnection UCSLink; QueryServConnection QSLink; LauncherList launcher_list; AdventureManager adventure_manager; @@ -303,7 +302,7 @@ int main(int argc, char **argv) connection->GetUUID() ); - UCSLink.SetConnection(connection); + UCSConnection::Instance()->SetConnection(connection); zoneserver_list.UpdateUCSServerAvailable(); } @@ -313,11 +312,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 3ae9816f5..64b49bd59 100644 --- a/world/world_boot.cpp +++ b/world/world_boot.cpp @@ -628,14 +628,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 9f24c021b..28d1c7f9a 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) { LogSys.LoadLogDatabaseSettings(); player_event_logs.ReloadSettings(); - UCSLink.SendPacket(&pack); + UCSConnection::Instance()->SendPacket(&pack); } else if (type == ServerReload::Type::Tasks) { shared_task_manager.LoadTaskData(); } else if (type == ServerReload::Type::DzTemplates) { diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 93500ecf6..e2fbb41ff 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -59,7 +59,6 @@ extern LoginServerList loginserverlist; extern volatile bool RunLoops; extern volatile bool UCSServerAvailable_; extern AdventureManager adventure_manager; -extern UCSConnection UCSLink; extern QueryServConnection QSLink; extern SharedTaskManager shared_task_manager; @@ -381,7 +380,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; @@ -435,7 +434,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; } @@ -1344,7 +1343,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: {