From c0d424829dc359032ecec99b8a1befee7d5dcdd0 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 14 Dec 2024 22:04:12 -0600 Subject: [PATCH] [Network] Prune / disconnect TCP connections gracefully --- common/net/tcp_connection.cpp | 2 ++ loginserver/world_server.cpp | 12 ------------ loginserver/world_server.h | 7 ------- world/login_server.cpp | 10 ---------- world/login_server.h | 1 - world/queryserv.cpp | 6 ------ world/queryserv.h | 1 - world/ucs.cpp | 12 ------------ world/ucs.h | 5 ----- world/zonelist.cpp | 8 -------- world/zonelist.h | 1 - zone/worldserver.cpp | 8 -------- zone/worldserver.h | 2 -- 13 files changed, 2 insertions(+), 73 deletions(-) diff --git a/common/net/tcp_connection.cpp b/common/net/tcp_connection.cpp index 0c2512dccd..ae1f14badc 100644 --- a/common/net/tcp_connection.cpp +++ b/common/net/tcp_connection.cpp @@ -80,6 +80,8 @@ void EQ::Net::TCPConnection::Start() { } } else if (nread == UV_EOF) { + connection->Disconnect(); + if (buf->base) { delete[] buf->base; } diff --git a/loginserver/world_server.cpp b/loginserver/world_server.cpp index b43651fd75..e4b7ac358c 100644 --- a/loginserver/world_server.cpp +++ b/loginserver/world_server.cpp @@ -51,12 +51,6 @@ WorldServer::WorldServer(std::shared_ptr wo ServerOP_LSAccountUpdate, std::bind(&WorldServer::ProcessLSAccountUpdate, this, std::placeholders::_1, std::placeholders::_2) ); - - m_keepalive = std::make_unique( - 1000, - true, - std::bind(&WorldServer::OnKeepAlive, this, std::placeholders::_1) - ); } WorldServer::~WorldServer() = default; @@ -1307,12 +1301,6 @@ const std::string &WorldServer::GetVersion() const return m_version; } -void WorldServer::OnKeepAlive(EQ::Timer *t) -{ - ServerPacket pack(ServerOP_KeepAlive, 0); - m_connection->SendPacket(&pack); -} - void WorldServer::FormatWorldServerName(char *name, int8 server_list_type) { std::string server_long_name = name; diff --git a/loginserver/world_server.h b/loginserver/world_server.h index df5324240b..45cecfebd6 100644 --- a/loginserver/world_server.h +++ b/loginserver/world_server.h @@ -187,13 +187,6 @@ class WorldServer { bool m_is_server_logged_in; bool m_is_server_trusted; - /** - * Keepalive - * @param t - */ - void OnKeepAlive(EQ::Timer *t); - std::unique_ptr m_keepalive; - static void FormatWorldServerName(char *name, int8 server_list_type); }; diff --git a/world/login_server.cpp b/world/login_server.cpp index b2017f094b..b647aedf08 100644 --- a/world/login_server.cpp +++ b/world/login_server.cpp @@ -595,11 +595,6 @@ bool LoginServer::Connect() ); } - m_keepalive = std::make_unique( - 1000, - true, - std::bind(&LoginServer::OnKeepAlive, this, std::placeholders::_1)); - return true; } @@ -716,8 +711,3 @@ void LoginServer::SendAccountUpdate(ServerPacket *pack) } } -void LoginServer::OnKeepAlive(EQ::Timer *t) -{ - ServerPacket pack(ServerOP_KeepAlive, 0); - SendPacket(&pack); -} diff --git a/world/login_server.h b/world/login_server.h index 21e25870fb..0a5e6a107a 100644 --- a/world/login_server.h +++ b/world/login_server.h @@ -50,7 +50,6 @@ class LoginServer{ void ProcessLSRemoteAddr(uint16_t opcode, EQ::Net::Packet &p); void ProcessLSAccountUpdate(uint16_t opcode, EQ::Net::Packet &p); - void OnKeepAlive(EQ::Timer *t); std::unique_ptr m_keepalive; std::unique_ptr m_client; diff --git a/world/queryserv.cpp b/world/queryserv.cpp index 0611e7d503..847cb90e04 100644 --- a/world/queryserv.cpp +++ b/world/queryserv.cpp @@ -22,7 +22,6 @@ void QueryServConnection::AddConnection(std::shared_ptrOnMessage(ServerOP_QueryServGeneric, std::bind(&QueryServConnection::HandleGenericMessage, this, std::placeholders::_1, std::placeholders::_2)); connection->OnMessage(ServerOP_LFGuildUpdate, std::bind(&QueryServConnection::HandleLFGuildUpdateMessage, this, std::placeholders::_1, std::placeholders::_2)); m_streams.emplace(std::make_pair(connection->GetUUID(), connection)); - m_keepalive = std::make_unique(1000, true, std::bind(&QueryServConnection::OnKeepAlive, this, std::placeholders::_1)); } void QueryServConnection::RemoveConnection(std::shared_ptr connection) @@ -54,8 +53,3 @@ bool QueryServConnection::SendPacket(ServerPacket* pack) return true; } -void QueryServConnection::OnKeepAlive(EQ::Timer *t) -{ - ServerPacket pack(ServerOP_KeepAlive, 0); - SendPacket(&pack); -} diff --git a/world/queryserv.h b/world/queryserv.h index a02aab647a..028fdcbbda 100644 --- a/world/queryserv.h +++ b/world/queryserv.h @@ -15,7 +15,6 @@ class QueryServConnection void HandleGenericMessage(uint16_t opcode, EQ::Net::Packet &p); void HandleLFGuildUpdateMessage(uint16_t opcode, EQ::Net::Packet &p); bool SendPacket(ServerPacket* pack); - void OnKeepAlive(EQ::Timer *t); private: std::map> m_streams; std::unique_ptr m_keepalive; diff --git a/world/ucs.cpp b/world/ucs.cpp index 0af363051b..0cc70a0ea3 100644 --- a/world/ucs.cpp +++ b/world/ucs.cpp @@ -31,8 +31,6 @@ void UCSConnection::SetConnection(std::shared_ptr(1000, true, std::bind(&UCSConnection::OnKeepAlive, this, std::placeholders::_1)); } const std::shared_ptr &UCSConnection::GetConnection() const @@ -92,13 +90,3 @@ void UCSConnection::SendMessage(const char *From, const char *Message) SendPacket(pack); safe_delete(pack); } - -void UCSConnection::OnKeepAlive(EQ::Timer *t) -{ - if (!connection) { - return; - } - - ServerPacket pack(ServerOP_KeepAlive, 0); - connection->SendPacket(&pack); -} diff --git a/world/ucs.h b/world/ucs.h index d226e4dc94..04ec17471e 100644 --- a/world/ucs.h +++ b/world/ucs.h @@ -23,11 +23,6 @@ class UCSConnection inline std::string GetIP() const { return (connection && connection->Handle()) ? connection->Handle()->RemoteIP() : 0; } std::shared_ptr connection; - /** - * Keepalive - */ - std::unique_ptr m_keepalive; - void OnKeepAlive(EQ::Timer *t); }; #endif /*UCS_H_*/ diff --git a/world/zonelist.cpp b/world/zonelist.cpp index 31427552a3..c2e572a68d 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -42,7 +42,6 @@ ZSList::ZSList() memset(pLockedZones, 0, sizeof(pLockedZones)); m_tick = std::make_unique(5000, true, std::bind(&ZSList::OnTick, this, std::placeholders::_1)); - m_keepalive = std::make_unique(1000, true, std::bind(&ZSList::OnKeepAlive, this, std::placeholders::_1)); } ZSList::~ZSList() { @@ -846,13 +845,6 @@ void ZSList::OnTick(EQ::Timer *t) web_interface.SendEvent(out); } -void ZSList::OnKeepAlive(EQ::Timer *t) -{ - for (auto &zone : zone_server_list) { - zone->SendKeepAlive(); - } -} - const std::list> &ZSList::getZoneServerList() const { return zone_server_list; diff --git a/world/zonelist.h b/world/zonelist.h index 71d364c9bf..e096f03638 100644 --- a/world/zonelist.h +++ b/world/zonelist.h @@ -72,7 +72,6 @@ class ZSList private: void OnTick(EQ::Timer *t); - void OnKeepAlive(EQ::Timer *t); uint32 NextID; uint16 pLockedZones[MaxLockedZones]; uint32 CurGroupID; diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index 143b690a34..768fe4a4fc 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -91,8 +91,6 @@ void WorldServer::Connect() }); m_connection->OnMessage(std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2)); - - m_keepalive = std::make_unique(1000, true, std::bind(&WorldServer::OnKeepAlive, this, std::placeholders::_1)); } bool WorldServer::SendPacket(ServerPacket *pack) @@ -4690,12 +4688,6 @@ void WorldServer::RequestTellQueue(const char *who) return; } -void WorldServer::OnKeepAlive(EQ::Timer *t) -{ - ServerPacket pack(ServerOP_KeepAlive, 0); - SendPacket(&pack); -} - ZoneEventScheduler *WorldServer::GetScheduler() const { return m_zone_scheduler; diff --git a/zone/worldserver.h b/zone/worldserver.h index 49b1514008..de3ac5e971 100644 --- a/zone/worldserver.h +++ b/zone/worldserver.h @@ -73,8 +73,6 @@ class WorldServer { uint32 cur_groupid; uint32 last_groupid; - void OnKeepAlive(EQ::Timer *t); - std::unique_ptr m_connection; std::unique_ptr m_keepalive;