From eb4432bb6260eaadb41495149739244308e9e125 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 28 Jul 2017 17:54:40 +0100 Subject: Tentative fix for player-limit race condition (#3862) * Attempts to fix #2257 Derived from d233e9843148313c71fbaba96ccff660e47b07b1 * Changed player count type to int * Clarified certain actions --- src/ClientHandle.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 1b63153d2..3270cc37f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -179,6 +179,9 @@ void cClientHandle::Destroy(void) if (player != nullptr) { + // Atomically decrement player count (in world or server thread) + cRoot::Get()->GetServer()->PlayerDestroyed(); + auto world = player->GetWorld(); if (world != nullptr) { @@ -322,6 +325,9 @@ void cClientHandle::Kick(const AString & a_Reason) void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { + // Atomically increment player count (in server thread) + cRoot::Get()->GetServer()->PlayerCreated(); + cWorld * World; { cCSLock lock(m_CSState); @@ -662,11 +668,14 @@ void cClientHandle::HandleNPCTrade(int a_SlotNum) void cClientHandle::HandlePing(void) { + /* TODO: unused function, handles Legacy Server List Ping + http://wiki.vg/Protocol#Legacy_Server_List_Ping suggests that servers SHOULD handle this packet */ + // Somebody tries to retrieve information about the server AString Reply; const cServer & Server = *cRoot::Get()->GetServer(); - Printf(Reply, "%s%s%i%s%i", + Printf(Reply, "%s%s" SIZE_T_FMT "%s" SIZE_T_FMT, Server.GetDescription().c_str(), cChatColor::Delimiter, Server.GetNumPlayers(), @@ -1860,17 +1869,14 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) { if (a_Username.length() > 16) { - Kick("Your username is too long(>16 characters)"); + Kick("Your username is too long (>16 characters)"); return false; } - if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username)) + if (cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username)) { - if (cRoot::Get()->GetServer()->GetNumPlayers() >= cRoot::Get()->GetServer()->GetMaxPlayers()) - { - Kick("The server is currently full :(-- Try again later"); - return false; - } + Kick("Entry denied by plugin"); + return false; } return CheckMultiLogin(a_Username); -- cgit v1.2.3