From 12c012fa01e719c7c103e36ae0407294a0d11bfb Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 14:33:59 -0800 Subject: Changed CheckMultiLogin() to not have main body wrapped in an if statement. Added in indent to cPlayerListCallBack in cCallback class inside CheckMultiLogin(). Added doxy-comment for DoWithPlayer(). Changed comments on IsPlayerInQueue() and IsAllowMultiLogin() to doxy-comments. --- src/ClientHandle.cpp | 41 ++++++++++++++++++++++------------------- src/ClientHandle.h | 1 + src/Root.h | 1 + src/Server.h | 6 ++++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6fe7cbd4a..3bc17d1a9 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1790,31 +1790,34 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) bool cClientHandle::CheckMultiLogin(const AString & a_Username) { - if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) + // If the multilogin is allowed, skip this check entirely: + if ((cRoot::Get()->GetServer()->IsAllowMultiLogin())) { - if (cRoot::Get()->GetServer()->IsPlayerInQueue(a_Username)) - { - Kick("A player of the username is already logged in"); - return false; - } - - class cCallback : - public cPlayerListCallback - { - virtual bool Item(cPlayer * a_Player) override - { - return true; - } - } Callback; + return true; + } - if (cRoot::Get()->DoWithPlayer(a_Username, Callback)) - { + // Check if the player is waiting to be transferred to the World. + if (cRoot::Get()->GetServer()->IsPlayerInQueue(a_Username)) + { Kick("A player of the username is already logged in"); return false; + } + + class cCallback : + public cPlayerListCallback + { + virtual bool Item(cPlayer * a_Player) override + { + return true; } + } Callback; + + // Check if the player is in any World. + if (cRoot::Get()->DoWithPlayer(a_Username, Callback)) + { + Kick("A player of the username is already logged in"); + return false; } - - return true; } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index add004bd5..cd63aa308 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -282,6 +282,7 @@ public: /** Kicks the current player if the same username is already logged in. */ bool CheckMultiLogin(const AString & a_Username); + /** Called when the protocol handshake has been received (for protocol versions that support it; otherwise the first instant when a username is received). Returns true if the player is to be let in, false if they were disconnected diff --git a/src/Root.h b/src/Root.h index b3cde8748..af5a2b47b 100644 --- a/src/Root.h +++ b/src/Root.h @@ -129,6 +129,7 @@ public: /** Finds the player over his uuid and calls the callback */ bool DoWithPlayerByUUID(const AString & a_PlayerUUID, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << + /** Finds the player using it's complete username and calls the callback */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // tolua_begin diff --git a/src/Server.h b/src/Server.h index e329b5c65..a93e8df75 100644 --- a/src/Server.h +++ b/src/Server.h @@ -67,10 +67,12 @@ public: // tolua_export int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } - // Check if the player is queued to be transferred to a World. + /** Check if the player is queued to be transferred to a World. + Returns true is Player is found in queue. */ bool IsPlayerInQueue(AString a_Username); - // Can login more than once with same username. + /** Can login more than once with same username. + Returns false if it is not allowed, true otherwise. */ bool IsAllowMultiLogin(void) { return m_bAllowMultiLogin; } // Hardcore mode or not: -- cgit v1.2.3