summaryrefslogtreecommitdiffstats
path: root/source/ClientHandle.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-20 22:27:29 +0200
committermadmaxoft <github@xoft.cz>2013-08-20 22:28:34 +0200
commit69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e (patch)
treeb53758e80128e1cdad3b9b0937e89cc14b5d7bda /source/ClientHandle.cpp
parentMerge pull request #117 from tigerw/master (diff)
downloadcuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.tar
cuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.tar.gz
cuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.tar.bz2
cuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.tar.lz
cuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.tar.xz
cuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.tar.zst
cuberite-69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e.zip
Diffstat (limited to '')
-rw-r--r--source/ClientHandle.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index 319640eea..dda6a6ed2 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -51,6 +51,9 @@ static const int MAX_EXPLOSIONS_PER_TICK = 100;
/// How many explosions in the recent history are allowed
static const int MAX_RUNNING_SUM_EXPLOSIONS = cClientHandle::NUM_CHECK_EXPLOSIONS_TICKS * MAX_EXPLOSIONS_PER_TICK / 8;
+/// How many ticks before the socket is closed after the client is destroyed (#31)
+static const int TICKS_BEFORE_CLOSE = 20;
+
@@ -84,6 +87,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance)
, m_bKeepThreadGoing(true)
, m_Ping(1000)
, m_PingID(1)
+ , m_TicksSinceDestruction(0)
, m_State(csConnected)
, m_LastStreamedChunkX(0x7fffffff) // bogus chunk coords to force streaming upon login
, m_LastStreamedChunkZ(0x7fffffff)
@@ -111,7 +115,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance)
cClientHandle::~cClientHandle()
{
- ASSERT(m_State == csDestroyed); // Has Destroy() been called?
+ ASSERT(m_State >= csDestroyedWaiting); // Has Destroy() been called?
LOGD("Deleting client \"%s\" at %p", GetUsername().c_str(), this);
@@ -189,7 +193,7 @@ void cClientHandle::Destroy(void)
RemoveFromAllChunks();
m_Player->GetWorld()->RemoveClientFromChunkSender(this);
}
- m_State = csDestroyed;
+ m_State = csDestroyedWaiting;
}
@@ -1397,6 +1401,17 @@ bool cClientHandle::CheckBlockInteractionsRate(void)
void cClientHandle::Tick(float a_Dt)
{
+ // Handle clients that are waiting for final close while destroyed:
+ if (m_State == csDestroyedWaiting)
+ {
+ m_TicksSinceDestruction += 1; // This field is misused for the timeout counting
+ if (m_TicksSinceDestruction > TICKS_BEFORE_CLOSE)
+ {
+ m_State = csDestroyed;
+ }
+ return;
+ }
+
// Process received network data:
AString IncomingData;
{