[Code] UCSConnection Global to Singleton Cleanup (#4937)

Co-authored-by: Chris Miles <akkadius1@gmail.com>
This commit is contained in:
Alex King 2025-06-25 15:25:37 -04:00 committed by GitHub
parent 654764685a
commit 1e6a4dac78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 19 additions and 13 deletions

View File

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

View File

@ -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<EQ::Net::ServertalkServerConnection> 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);
}
}

View File

@ -19,6 +19,12 @@ public:
const std::shared_ptr<EQ::Net::ServertalkServerConnection> &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<EQ::Net::ServertalkServerConnection> connection;

View File

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

View File

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

View File

@ -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();

View File

@ -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: {