summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-03-28 16:34:49 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2021-03-28 16:36:10 +0200
commitc24e968f2c2cd4fb1dc131176dbb834819444699 (patch)
tree1f8dcbb9bce899c8a897344c692de47f5703d324 /src
parentMove some redstone implementations into the source file (diff)
downloadcuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.tar
cuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.tar.gz
cuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.tar.bz2
cuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.tar.lz
cuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.tar.xz
cuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.tar.zst
cuberite-c24e968f2c2cd4fb1dc131176dbb834819444699.zip
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp10
1 files 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<void *>(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);
}
}