From c24e968f2c2cd4fb1dc131176dbb834819444699 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 28 Mar 2021 15:34:49 +0100 Subject: [PATCH] Send keep alives slightly less frequently Ref: http://github.com/cuberite/cuberite/issues/4082#issuecomment-348675321 --- src/ClientHandle.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 20b03e190..0b99cd95c 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -49,10 +49,6 @@ /** Maximum number of bytes that a chat message sent by a player may consist of */ #define MAX_CHAT_MSG_LENGTH 1024 -/** The interval for sending pings to clients. -Vanilla sends one ping every 1 second. */ -static const std::chrono::milliseconds PING_TIME_MS = std::chrono::milliseconds(1000); - @@ -100,7 +96,6 @@ cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : { s_ClientCount++; // Not protected by CS because clients are always constructed from the same thread m_UniqueID = s_ClientCount; - m_PingStartTime = std::chrono::steady_clock::now(); LOGD("New ClientHandle created at %p", static_cast(this)); } @@ -2057,10 +2052,11 @@ void cClientHandle::Tick(float a_Dt) // Send a ping packet: if (m_State == csPlaying) { - if ((m_PingStartTime + PING_TIME_MS <= std::chrono::steady_clock::now())) + const auto Now = std::chrono::steady_clock::now(); + if ((m_PingStartTime + std::chrono::seconds(2)) <= Now) // 2 second interval between pings { m_PingID++; - m_PingStartTime = std::chrono::steady_clock::now(); + m_PingStartTime = Now; m_Protocol->SendKeepAlive(m_PingID); } }