From d494048ff6126fadb20f179fe5a5bc8d9968d2ee Mon Sep 17 00:00:00 2001 From: KimLS Date: Tue, 7 Mar 2017 18:13:17 -0800 Subject: [PATCH] Tweaks to make server more lag tolerant and also send less packets. --- common/eq_stream_ident.h | 2 +- common/net/daybreak_connection.cpp | 23 +++++++++++++++-------- common/net/daybreak_connection.h | 4 +++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/eq_stream_ident.h b/common/eq_stream_ident.h index 2a58606b5..483d48372 100644 --- a/common/eq_stream_ident.h +++ b/common/eq_stream_ident.h @@ -7,7 +7,7 @@ #include #include -#define STREAM_IDENT_WAIT_MS 10000 +#define STREAM_IDENT_WAIT_MS 30000 class OpcodeManager; class StructStrategy; diff --git a/common/net/daybreak_connection.cpp b/common/net/daybreak_connection.cpp index cf67fdcae..0b44628ed 100644 --- a/common/net/daybreak_connection.cpp +++ b/common/net/daybreak_connection.cpp @@ -272,7 +272,7 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner m_encode_passes[1] = owner->m_options.encode_passes[1]; m_hold_time = Clock::now(); m_buffered_packets_length = 0; - m_resend_delay = m_owner->m_options.resend_delay_ms + 25; + m_resend_delay = 500; m_rolling_ping = 100; m_combined.reset(new char[512]); m_combined[0] = 0; @@ -295,7 +295,7 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner m_crc_bytes = 0; m_hold_time = Clock::now(); m_buffered_packets_length = 0; - m_resend_delay = m_owner->m_options.resend_delay_ms + 25; + m_resend_delay = 500; m_rolling_ping = 100; m_combined.reset(new char[512]); m_combined[0] = 0; @@ -316,6 +316,8 @@ void EQ::Net::DaybreakConnection::Close() disconnect.connect_code = HostToNetwork(m_connect_code); DynamicPacket out; out.PutSerialize(0, disconnect); + + FlushBuffer(); InternalSend(out); ChangeStatus(StatusDisconnecting); @@ -355,9 +357,9 @@ void EQ::Net::DaybreakConnection::ResetStats() void EQ::Net::DaybreakConnection::Process() { try { - m_resend_delay = (size_t)(m_stats.last_stat_ping * m_owner->m_options.resend_delay_factor) + m_owner->m_options.resend_delay_ms; - if (m_resend_delay > 500) { - m_resend_delay = 500; + m_resend_delay = (size_t)(((m_stats.min_ping + m_stats.max_ping) / 2) * m_owner->m_options.resend_delay_factor) + m_owner->m_options.resend_delay_ms; + if (m_resend_delay > m_owner->m_options.resend_delay_max) { + m_resend_delay = m_owner->m_options.resend_delay_max; } auto now = Clock::now(); @@ -699,6 +701,8 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p) disconnect.connect_code = HostToNetwork(m_connect_code); DynamicPacket out; out.PutSerialize(0, disconnect); + + FlushBuffer(); InternalSend(out); } @@ -1055,7 +1059,7 @@ void EQ::Net::DaybreakConnection::SendAck(int stream_id, uint16_t seq) DynamicPacket p; p.PutSerialize(0, ack); - InternalSend(p); + InternalBufferedSend(p); } void EQ::Net::DaybreakConnection::SendOutOfOrderAck(int stream_id, uint16_t seq) @@ -1068,7 +1072,7 @@ void EQ::Net::DaybreakConnection::SendOutOfOrderAck(int stream_id, uint16_t seq) DynamicPacket p; p.PutSerialize(0, ack); - InternalSend(p); + InternalBufferedSend(p); } void EQ::Net::DaybreakConnection::SendStatSync() @@ -1088,7 +1092,10 @@ void EQ::Net::DaybreakConnection::SendStatSync() request.packets_sent = m_stats.sent_packets + 1; request.packets_recv = m_stats.recv_packets; m_last_session_stats = Clock::now(); - //InternalSend() + + //EQ::Net::DynamicPacket p; + //p.PutSerialize(0, request); + //InternalBufferedSend(p); } void EQ::Net::DaybreakConnection::InternalBufferedSend(Packet &p) diff --git a/common/net/daybreak_connection.h b/common/net/daybreak_connection.h index bc48052b3..53d10f3d6 100644 --- a/common/net/daybreak_connection.h +++ b/common/net/daybreak_connection.h @@ -218,8 +218,9 @@ namespace EQ DaybreakConnectionManagerOptions() { max_connection_count = 0; keepalive_delay_ms = 9000; - resend_delay_ms = 50; + resend_delay_ms = 250; resend_delay_factor = 1.5; + resend_delay_max = 2500; stats_delay_ms = 9000; connect_delay_ms = 250; stale_connection_ms = 60000; @@ -241,6 +242,7 @@ namespace EQ size_t keepalive_delay_ms; double resend_delay_factor; size_t resend_delay_ms; + size_t resend_delay_max; size_t stats_delay_ms; size_t connect_delay_ms; size_t connect_stale_ms;