From aa19a3afb0b94e8b5fe055eeb38b1fb2ee1a67b0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Oct 2014 14:10:18 +0100 Subject: Migrated random generators to std::random --- src/ClientHandle.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f15d845ef..7d0f2de06 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -25,8 +25,6 @@ #include "Root.h" #include "Protocol/Authenticator.h" -#include "MersenneTwister.h" - #include "Protocol/ProtocolRecognizer.h" #include "CompositeChat.h" #include "Items/ItemSword.h" @@ -45,16 +43,6 @@ -#define RECI_RAND_MAX (1.f/RAND_MAX) -inline int fRadRand(MTRand & r1, int a_BlockCoord) -{ - return a_BlockCoord * 32 + (int)(16 * ((float)r1.rand() * RECI_RAND_MAX) * 16 - 8); -} - - - - - int cClientHandle::s_ClientCount = 0; -- cgit v1.2.3 From bde99d684e0bb51adaa053a240abe61cf4af07fb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 18:59:40 +0100 Subject: Migrated cSleep and cTimer to std::chrono --- src/ClientHandle.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 7d0f2de06..3dcbaa6a9 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -16,7 +16,6 @@ #include "Mobs/Monster.h" #include "ChatColor.h" #include "OSSupport/Socket.h" -#include "OSSupport/Timer.h" #include "Items/ItemHandler.h" #include "Blocks/BlockHandler.h" #include "Blocks/BlockSlab.h" @@ -63,8 +62,6 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_TimeSinceLastPacket(0), m_Ping(1000), m_PingID(1), - m_PingStartTime(0), - m_LastPingTime(1000), m_BlockDigAnimStage(-1), m_BlockDigAnimSpeed(0), m_BlockDigAnimX(0), @@ -87,9 +84,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : s_ClientCount++; // Not protected by CS because clients are always constructed from the same thread m_UniqueID = s_ClientCount; - - cTimer t1; - m_LastPingTime = t1.GetNowTime(); + m_LastPingTime = std::chrono::steady_clock::now(); LOGD("New ClientHandle created at %p", this); } @@ -383,8 +378,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Delay the first ping until the client "settles down" // This should fix #889, "BadCast exception, cannot convert bit to fm" error in client - cTimer t1; - m_LastPingTime = t1.GetNowTime() + 3000; // Send the first KeepAlive packet in 3 seconds + m_LastPingTime = std::chrono::steady_clock::now() + std::chrono::seconds(3); // Send the first KeepAlive packet in 3 seconds cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player); } @@ -1694,8 +1688,7 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) { if (a_KeepAliveID == m_PingID) { - cTimer t1; - m_Ping = (short)((t1.GetNowTime() - m_PingStartTime) / 2); + m_Ping = std::chrono::steady_clock::now() - m_PingStartTime; } } @@ -1919,11 +1912,10 @@ void cClientHandle::Tick(float a_Dt) // Send a ping packet: if (m_State == csPlaying) { - cTimer t1; - if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime())) + if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= std::chrono::steady_clock::now())) { m_PingID++; - m_PingStartTime = t1.GetNowTime(); + m_PingStartTime = std::chrono::steady_clock::now(); m_Protocol->SendKeepAlive(m_PingID); m_LastPingTime = m_PingStartTime; } -- cgit v1.2.3 From 987f79afdd8945966d0dfa2d52539e005f771590 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 21:55:07 +0100 Subject: En masse NULL -> nullptr replace --- src/ClientHandle.cpp | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3dcbaa6a9..202a8d02f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -55,7 +55,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_ViewDistance(a_ViewDistance), m_IPString(a_Socket->GetIPString()), m_OutgoingData(64 KiB), - m_Player(NULL), + m_Player(nullptr), m_HasSentDC(false), m_LastStreamedChunkX(0x7fffffff), // bogus chunk coords to force streaming upon login m_LastStreamedChunkZ(0x7fffffff), @@ -105,10 +105,10 @@ cClientHandle::~cClientHandle() m_ChunksToSend.clear(); } - if (m_Player != NULL) + if (m_Player != nullptr) { cWorld * World = m_Player->GetWorld(); - if (World != NULL) + if (World != nullptr) { if (!m_Username.empty()) { @@ -120,7 +120,7 @@ cClientHandle::~cClientHandle() m_Player->Destroy(); } delete m_Player; - m_Player = NULL; + m_Player = nullptr; } if (!m_HasSentDC) @@ -132,7 +132,7 @@ cClientHandle::~cClientHandle() cRoot::Get()->GetServer()->RemoveClient(this); delete m_Protocol; - m_Protocol = NULL; + m_Protocol = nullptr; LOGD("ClientHandle at %p deleted", this); } @@ -156,7 +156,7 @@ void cClientHandle::Destroy(void) // DEBUG: LOGD("%s: client %p, \"%s\"", __FUNCTION__, this, m_Username.c_str()); - if ((m_Player != NULL) && (m_Player->GetWorld() != NULL)) + if ((m_Player != nullptr) && (m_Player->GetWorld() != nullptr)) { RemoveFromAllChunks(); m_Player->GetWorld()->RemoveClientFromChunkSender(this); @@ -297,7 +297,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, return; } - ASSERT(m_Player == NULL); + ASSERT(m_Player == nullptr); m_Username = a_Name; @@ -318,7 +318,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, m_Player = new cPlayer(this, GetUsername()); cWorld * World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName()); - if (World == NULL) + if (World == nullptr) { World = cRoot::Get()->GetDefaultWorld(); } @@ -394,7 +394,7 @@ void cClientHandle::StreamChunks(void) return; } - ASSERT(m_Player != NULL); + ASSERT(m_Player != nullptr); int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width); int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width); @@ -409,7 +409,7 @@ void cClientHandle::StreamChunks(void) LOGD("Streaming chunks centered on [%d, %d], view distance %d", ChunkPosX, ChunkPosZ, m_ViewDistance); cWorld * World = m_Player->GetWorld(); - ASSERT(World != NULL); + ASSERT(World != nullptr); // Remove all loaded chunks that are no longer in range; deferred to out-of-CS: cChunkCoordsList RemoveChunks; @@ -495,7 +495,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) } cWorld * World = m_Player->GetWorld(); - ASSERT(World != NULL); + ASSERT(World != nullptr); if (World->AddChunkClient(a_ChunkX, a_ChunkZ, this)) { @@ -516,7 +516,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) void cClientHandle::RemoveFromAllChunks() { cWorld * World = m_Player->GetWorld(); - if (World != NULL) + if (World != nullptr) { World->RemoveClientFromChunks(this); } @@ -632,7 +632,7 @@ void cClientHandle::HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, float void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround) { - if ((m_Player == NULL) || (m_State != csPlaying)) + if ((m_Player == nullptr) || (m_State != csPlaying)) { // The client hasn't been spawned yet and sends nonsense, we know better return; @@ -766,7 +766,7 @@ void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList void cClientHandle::HandleBeaconSelection(int a_PrimaryEffect, int a_SecondaryEffect) { cWindow * Window = m_Player->GetWindow(); - if ((Window == NULL) || (Window->GetWindowType() != cWindow::wtBeacon)) + if ((Window == nullptr) || (Window->GetWindowType() != cWindow::wtBeacon)) { return; } @@ -842,7 +842,7 @@ void cClientHandle::HandleCommandBlockEntityChange(int a_EntityID, const AString void cClientHandle::HandleAnvilItemName(const AString & a_ItemName) { - if ((m_Player->GetWindow() == NULL) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil)) + if ((m_Player->GetWindow() == nullptr) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil)) { return; } @@ -1479,7 +1479,7 @@ void cClientHandle::HandleChat(const AString & a_Message) void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround) { - if ((m_Player == NULL) || (m_State != csPlaying)) + if ((m_Player == nullptr) || (m_State != csPlaying)) { return; } @@ -1579,7 +1579,7 @@ void cClientHandle::HandleWindowClick(char a_WindowID, short a_SlotNum, eClickAc ); cWindow * Window = m_Player->GetWindow(); - if (Window == NULL) + if (Window == nullptr) { LOGWARNING("Player \"%s\" clicked in a non-existent window. Ignoring", m_Username.c_str()); return; @@ -1671,7 +1671,7 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick) void cClientHandle::HandleRespawn(void) { - if (m_Player == NULL) + if (m_Player == nullptr) { Destroy(); return; @@ -1760,7 +1760,7 @@ void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting) void cClientHandle::HandleUnmount(void) { - if (m_Player == NULL) + if (m_Player == nullptr) { return; } @@ -1865,8 +1865,8 @@ void cClientHandle::RemoveFromWorld(void) bool cClientHandle::CheckBlockInteractionsRate(void) { - ASSERT(m_Player != NULL); - ASSERT(m_Player->GetWorld() != NULL); + ASSERT(m_Player != nullptr); + ASSERT(m_Player->GetWorld() != nullptr); if (m_NumBlockChangeInteractionsThisTick > MAX_BLOCK_CHANGE_INTERACTIONS) { @@ -1897,7 +1897,7 @@ void cClientHandle::Tick(float a_Dt) Destroy(); } - if (m_Player == NULL) + if (m_Player == nullptr) { return; } @@ -2047,10 +2047,10 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { cWorld * World = GetPlayer()->GetWorld(); - if (World == NULL) + if (World == nullptr) { World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); - if (World == NULL) + if (World == nullptr) { World = cRoot::Get()->GetDefaultWorld(); } @@ -2075,7 +2075,7 @@ void cClientHandle::SendChat(const cCompositeChat & a_Message) void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { - ASSERT(m_Player != NULL); + ASSERT(m_Player != nullptr); // Check chunks being sent, erase them from m_ChunksToSend: bool Found = false; @@ -2906,7 +2906,7 @@ void cClientHandle::HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment) } if ( - (m_Player->GetWindow() == NULL) || + (m_Player->GetWindow() == nullptr) || (m_Player->GetWindow()->GetWindowID() != a_WindowID) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtEnchantment) ) -- cgit v1.2.3 From 61e761fdc2bfa5c77002d68bb24e0470def37b48 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 29 Nov 2014 00:36:15 -0800 Subject: issue 1253 - prevent multiple logins with same username --- src/ClientHandle.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a6cbad32a..ae794d7cb 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1798,6 +1798,24 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) return false; } } + if (!(cRoot::Get()->GetServer()->isAllowMultiLogin())) + { + std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); + std::list usernamesWorld = cRoot::Get()->GetDefaultWorld()-> GetUsernames(); + + usernamesServer.sort(); + usernamesWorld.sort(); + usernamesServer.merge(usernamesWorld); + + for (std::list::iterator itr = usernamesServer.begin(); itr != usernamesServer.end(); ++itr) + { + if ((*itr).compare(a_Username) == 0) + { + Kick("User already logged in."); + return false; + } + } + } return true; } -- cgit v1.2.3 From a7bf2725c8bd5f8ec3e03584af87a7055cb15a60 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 29 Nov 2014 11:22:03 -0800 Subject: fixed naming of strings and changed from i to I --- src/ClientHandle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ae794d7cb..3c06f3401 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1798,16 +1798,16 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) return false; } } - if (!(cRoot::Get()->GetServer()->isAllowMultiLogin())) + if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) { - std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); - std::list usernamesWorld = cRoot::Get()->GetDefaultWorld()-> GetUsernames(); + std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); + std::list usernamesWorld = cRoot::Get()->GetDefaultWorld()-> GetUsernames(); usernamesServer.sort(); usernamesWorld.sort(); usernamesServer.merge(usernamesWorld); - for (std::list::iterator itr = usernamesServer.begin(); itr != usernamesServer.end(); ++itr) + for (std::list::iterator itr = usernamesServer.begin(); itr != usernamesServer.end(); ++itr) { if ((*itr).compare(a_Username) == 0) { -- cgit v1.2.3 From 72797b14fe5f83a7a27df17d5b733048d13d5d1b Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 29 Nov 2014 15:44:38 -0800 Subject: Uses callback for players already in World. --- src/ClientHandle.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3c06f3401..f63754aab 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1790,6 +1790,7 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) bool cClientHandle::HandleHandshake(const AString & a_Username) { + if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username)) { if (cRoot::Get()->GetServer()->GetNumPlayers() >= cRoot::Get()->GetServer()->GetMaxPlayers()) @@ -1801,11 +1802,6 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) { std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); - std::list usernamesWorld = cRoot::Get()->GetDefaultWorld()-> GetUsernames(); - - usernamesServer.sort(); - usernamesWorld.sort(); - usernamesServer.merge(usernamesWorld); for (std::list::iterator itr = usernamesServer.begin(); itr != usernamesServer.end(); ++itr) { @@ -1815,6 +1811,17 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) return false; } } + class cCallback : public cPlayerListCallback + { + virtual bool Item(cPlayer * a_Player) override + { + return false; + } + } Callback; + if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) + { + Kick("User already logged in."); + } } return true; } -- cgit v1.2.3 From 9caa3b19c15b257af47a924c68f9b13517447c26 Mon Sep 17 00:00:00 2001 From: vincentleung1 Date: Sat, 29 Nov 2014 15:59:48 -0800 Subject: removed extra space and fixed some formatting in cCallback --- src/ClientHandle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f63754aab..54a39cdc2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1790,7 +1790,6 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) bool cClientHandle::HandleHandshake(const AString & a_Username) { - if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username)) { if (cRoot::Get()->GetServer()->GetNumPlayers() >= cRoot::Get()->GetServer()->GetMaxPlayers()) @@ -1811,11 +1810,12 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) return false; } } - class cCallback : public cPlayerListCallback + class cCallback : + public cPlayerListCallback { virtual bool Item(cPlayer * a_Player) override { - return false; + return true; } } Callback; if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) -- cgit v1.2.3 From 438a9b04cbabcbbab06d9f5bd00ced3342eb97f8 Mon Sep 17 00:00:00 2001 From: vincentleung1 Date: Sat, 29 Nov 2014 16:05:22 -0800 Subject: Changed Kick message --- src/ClientHandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 54a39cdc2..1ffb5f04b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1806,7 +1806,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) { if ((*itr).compare(a_Username) == 0) { - Kick("User already logged in."); + Kick("A player of the username is already logged in"); return false; } } @@ -1820,7 +1820,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) } Callback; if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) { - Kick("User already logged in."); + Kick("A player of the username is already logged in"); } } return true; -- cgit v1.2.3 From e2a04f580a0813206f527a61244cb3382248fd12 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Dec 2014 16:59:11 +0100 Subject: BasicStyle: Added missing braces to control statements. --- src/ClientHandle.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a6cbad32a..366f20170 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -199,9 +199,13 @@ void cClientHandle::GenerateOfflineUUID(void) AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2) { if (ShouldAppendChatPrefixes) + { return Printf("%s[%s] %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str()); + } else + { return Printf("%s", m_Color1.c_str()); + } } -- cgit v1.2.3 From 3c3cb198f33fd55b9cb20188cc42034b21660d21 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 7 Dec 2014 15:46:27 +0100 Subject: Fixed c++11 branch issues. --- src/ClientHandle.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d246f6da2..c4a620565 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -38,6 +38,11 @@ /** Maximum number of block change interactions a player can perform per tick - exceeding this causes a kick */ #define MAX_BLOCK_CHANGE_INTERACTIONS 20 +/** 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); + + @@ -86,7 +91,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : s_ClientCount++; // Not protected by CS because clients are always constructed from the same thread m_UniqueID = s_ClientCount; - m_LastPingTime = std::chrono::steady_clock::now(); + m_PingStartTime = std::chrono::steady_clock::now(); LOGD("New ClientHandle created at %p", this); } @@ -384,7 +389,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Delay the first ping until the client "settles down" // This should fix #889, "BadCast exception, cannot convert bit to fm" error in client - m_LastPingTime = std::chrono::steady_clock::now() + std::chrono::seconds(3); // Send the first KeepAlive packet in 3 seconds + m_PingStartTime = std::chrono::steady_clock::now() + std::chrono::seconds(3); // Send the first KeepAlive packet in 3 seconds cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player); } @@ -1990,12 +1995,11 @@ void cClientHandle::Tick(float a_Dt) // Send a ping packet: if (m_State == csPlaying) { - if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= std::chrono::steady_clock::now())) + if ((m_PingStartTime + PING_TIME_MS <= std::chrono::steady_clock::now())) { m_PingID++; m_PingStartTime = std::chrono::steady_clock::now(); m_Protocol->SendKeepAlive(m_PingID); - m_LastPingTime = m_PingStartTime; } } -- cgit v1.2.3 From 8edfd7829505d43c7d6bf7fcc582e0d7cb29e1d5 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 7 Dec 2014 12:41:42 -0800 Subject: changed from using iterator to auto for server and clienthandle --- src/ClientHandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f63754aab..94126d496 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1803,9 +1803,9 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) { std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); - for (std::list::iterator itr = usernamesServer.begin(); itr != usernamesServer.end(); ++itr) + for (auto item : usernamesServer) { - if ((*itr).compare(a_Username) == 0) + if ((item).compare(a_Username) == 0) { Kick("User already logged in."); return false; -- cgit v1.2.3 From d8d3b9aec5bbb0f6d632d86f1fb7b1e8f58e9063 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 00:12:48 -0800 Subject: Moved the check into a new function and just calls that function and a blank FindAndDoWithPlayer added. --- src/ClientHandle.cpp | 60 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3fca48394..025588485 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1788,6 +1788,41 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) +bool cClientHandle::CheckMultiLogin(void) +{ + std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); + + for (auto item : usernamesServer) + { + if ((item).compare(a_Username) == 0) + { + 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; + + if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) + { + Kick("A player of the username is already logged in"); + return false; + } + + return true; +} + + + + + bool cClientHandle::HandleHandshake(const AString & a_Username) { if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username)) @@ -1798,31 +1833,12 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) return false; } } + if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) { - std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); - - for (auto item : usernamesServer) - { - if ((item).compare(a_Username) == 0) - { - 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; - if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) - { - Kick("A player of the username is already logged in"); - } + return CheckMultiLogin(); } + return true; } -- cgit v1.2.3 From ed09e76023436c9414356921bc761618b3bb9341 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 00:16:09 -0800 Subject: Changed HandleHandshake to return the result of CheckMultiLogin instead of just true since it already returns true if it finds and kicks the current player. --- src/ClientHandle.cpp | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 025588485..e60bb5373 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1790,30 +1790,33 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) bool cClientHandle::CheckMultiLogin(void) { - std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); - - for (auto item : usernamesServer) + if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) { - if ((item).compare(a_Username) == 0) + std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); + + for (auto item : usernamesServer) { - Kick("A player of the username is already logged in"); - return false; + if ((item).compare(a_Username) == 0) + { + Kick("A player of the username is already logged in"); + return false; + } } - } - class cCallback : - public cPlayerListCallback - { - virtual bool Item(cPlayer * a_Player) override + class cCallback : + public cPlayerListCallback { - return true; - } - } Callback; + virtual bool Item(cPlayer * a_Player) override + { + return true; + } + } Callback; - if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) - { - Kick("A player of the username is already logged in"); - return false; + if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) + { + Kick("A player of the username is already logged in"); + return false; + } } return true; @@ -1833,13 +1836,9 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) return false; } } + + return CheckMultiLogin(); - if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) - { - return CheckMultiLogin(); - } - - return true; } -- cgit v1.2.3 From 656964dc385e4460215d2443724f322cd1bc596d Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 00:19:33 -0800 Subject: removed last space in handlehandshake --- src/ClientHandle.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index e60bb5373..4031fa1df 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1838,7 +1838,6 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) } return CheckMultiLogin(); - } -- cgit v1.2.3 From 6de07d4a39096f19c075695824aa87a1907e4edc Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 00:45:29 -0800 Subject: Fixed compile errors --- src/ClientHandle.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 4031fa1df..6f7bd1faf 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1788,19 +1788,14 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) -bool cClientHandle::CheckMultiLogin(void) +bool cClientHandle::CheckMultiLogin(const AString & a_Username) { if (!(cRoot::Get()->GetServer()->IsAllowMultiLogin())) { - std::list usernamesServer = cRoot::Get()->GetServer()->GetUsernames(); - - for (auto item : usernamesServer) + if (cRoot::Get()->GetServer()->IsPlayerInQueue(a_Username)) { - if ((item).compare(a_Username) == 0) - { Kick("A player of the username is already logged in"); return false; - } } class cCallback : @@ -1837,7 +1832,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) } } - return CheckMultiLogin(); + return CheckMultiLogin(a_Username); } -- cgit v1.2.3 From e28cc876c4aa4d71f821fca45b5486b8ef6cca4e Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 00:57:46 -0800 Subject: created callback in Root and changed CheckMultiLogin() to use the DoWithPlayer function at Root instead of World. --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6f7bd1faf..6fe7cbd4a 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1807,7 +1807,7 @@ bool cClientHandle::CheckMultiLogin(const AString & a_Username) } } Callback; - if (cRoot::Get()->GetDefaultWorld()->DoWithPlayer(a_Username, Callback)) + if (cRoot::Get()->DoWithPlayer(a_Username, Callback)) { Kick("A player of the username is already logged in"); return false; -- cgit v1.2.3 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 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/ClientHandle.cpp') 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; } -- cgit v1.2.3 From 4b08ca261bed5ec2fd70f64ee96104ba6bee6927 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 9 Dec 2014 03:06:25 -0800 Subject: Fixed indent problems and added return definitions to CheckMultiLogin(). Changed from IsAllowMultiLogin() to DoesAllowMultiLogin(). Fixed CheckMultiLogin() to not run to the end without returning a value. --- src/ClientHandle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3bc17d1a9..6812c06ac 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1799,8 +1799,8 @@ bool cClientHandle::CheckMultiLogin(const AString & a_Username) // 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; + Kick("A player of the username is already logged in"); + return false; } class cCallback : @@ -1816,8 +1816,8 @@ bool cClientHandle::CheckMultiLogin(const AString & a_Username) if (cRoot::Get()->DoWithPlayer(a_Username, Callback)) { Kick("A player of the username is already logged in"); - return false; } + return false; } -- cgit v1.2.3 From 3a2759fdc1a2c7282bd90a1f545fa1effae2728b Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 9 Dec 2014 14:23:44 -0800 Subject: Fixed return value in CheckMultiLogin() --- src/ClientHandle.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6812c06ac..87dc27f8f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1816,8 +1816,9 @@ bool cClientHandle::CheckMultiLogin(const AString & a_Username) if (cRoot::Get()->DoWithPlayer(a_Username, Callback)) { Kick("A player of the username is already logged in"); + return false; } - return false; + return true; } -- cgit v1.2.3 From 9bba8e4c7d88c0769bb7643a2a8b577a3d12c1af Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 10 Dec 2014 00:45:24 -0800 Subject: Changed method call to DoesAllowMultiLogin() instead of IsAllowMultiLogin() Compiles correctly. --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 87dc27f8f..8a39c3ecb 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1791,7 +1791,7 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) bool cClientHandle::CheckMultiLogin(const AString & a_Username) { // If the multilogin is allowed, skip this check entirely: - if ((cRoot::Get()->GetServer()->IsAllowMultiLogin())) + if ((cRoot::Get()->GetServer()->DoesAllowMultiLogin())) { return true; } -- cgit v1.2.3 From 33c6ff872e72563b6e888476b66c4e9c19f8c840 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 11 Dec 2014 14:34:09 +0100 Subject: Cosmetic touchups. Removed trailing whitespace, added cast to remove warning, added file seeking in case of corrupt files. --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index cc83bcab3..cb9d34c84 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1800,7 +1800,7 @@ bool cClientHandle::CheckMultiLogin(const AString & a_Username) { return true; } - } Callback; + } Callback; // Check if the player is in any World. if (cRoot::Get()->DoWithPlayer(a_Username, Callback)) -- cgit v1.2.3