From f3af458cb3cbc40338a651189a80084c5784e874 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Wed, 9 Apr 2025 20:52:46 -0500 Subject: [PATCH] [Netcode] Fix Stale Client Edge Case (#4853) * [Netcode] Fix Stale Client Edge Case * [Netcode] Make sure we always set m_close_time --- common/net/daybreak_connection.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/common/net/daybreak_connection.cpp b/common/net/daybreak_connection.cpp index f1f871c78..f1495315e 100644 --- a/common/net/daybreak_connection.cpp +++ b/common/net/daybreak_connection.cpp @@ -342,16 +342,16 @@ EQ::Net::DaybreakConnection::~DaybreakConnection() void EQ::Net::DaybreakConnection::Close() { - if (m_status == StatusConnected) { + if (m_status != StatusDisconnected && m_status != StatusDisconnecting) { FlushBuffer(); SendDisconnect(); + } + if (m_status != StatusDisconnecting) { m_close_time = Clock::now(); - ChangeStatus(StatusDisconnecting); - } - else { - ChangeStatus(StatusDisconnecting); } + + ChangeStatus(StatusDisconnecting); } void EQ::Net::DaybreakConnection::QueuePacket(Packet &p) @@ -1117,6 +1117,11 @@ void EQ::Net::DaybreakConnection::ProcessResend(int stream) auto &first_packet = s->sent_packets.begin()->second; auto time_since_first_sent = std::chrono::duration_cast(now - first_packet.first_sent).count(); + if (time_since_first_sent >= m_owner->m_options.resend_timeout) { + Close(); + return; + } + // make sure that the first_packet in the list first_sent time is within the resend_delay and now // if it is not, then we need to resend all packets in the list if (time_since_first_sent <= first_packet.resend_delay && !m_acked_since_last_resend) { @@ -1129,11 +1134,6 @@ void EQ::Net::DaybreakConnection::ProcessResend(int stream) ); return; } - - if (time_since_first_sent >= m_owner->m_options.resend_timeout) { - Close(); - return; - } } if (LogSys.IsLogEnabled(Logs::Detail, Logs::Netcode)) {