From e3d5da24091bad6043d7eef00f8f297bf1203ab5 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 4 Sep 2012 19:05:35 +0000 Subject: Fixed a possible race condition in cClientHandle's packet sending code; prepared for moving cSocket out of cClientHandle's ownership. git-svn-id: http://mc-server.googlecode.com/svn/trunk@832 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Protocol125.cpp | 2 +- source/cClientHandle.cpp | 7 +++++-- source/cClientHandle.h | 4 ++-- source/cPlayer.cpp | 2 +- source/cServer.cpp | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/source/Protocol125.cpp b/source/Protocol125.cpp index 41a64f24b..4f162dab6 100644 --- a/source/Protocol125.cpp +++ b/source/Protocol125.cpp @@ -1028,7 +1028,7 @@ int cProtocol125::ParseLogin(void) LOGWARNING("Login Username (\"%s\") does not match Handshake username (\"%s\") for client @ \"%s\", kicking", Username.c_str(), m_Username.c_str(), - m_Client->GetSocket().GetIPString().c_str() + m_Client->GetIPString().c_str() ); m_Client->Kick("Hacked client"); // Don't tell them why we don't want them return PARSE_OK; diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index f4f5125c2..06325785e 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -1546,8 +1546,11 @@ void cClientHandle::DataReceived(const char * a_Data, int a_Size) void cClientHandle::GetOutgoingData(AString & a_Data) { // Data can be sent to client - m_OutgoingData.ReadAll(a_Data); - m_OutgoingData.CommitRead(); + { + cCSLock Lock(m_CSOutgoingData); + m_OutgoingData.ReadAll(a_Data); + m_OutgoingData.CommitRead(); + } // Disconnect player after all packets have been sent if (m_bKicking && a_Data.empty()) diff --git a/source/cClientHandle.h b/source/cClientHandle.h index ba9cde7f5..ab4e3e64c 100644 --- a/source/cClientHandle.h +++ b/source/cClientHandle.h @@ -60,8 +60,8 @@ public: cClientHandle(const cSocket & a_Socket, int a_ViewDistance); ~cClientHandle(); - const cSocket & GetSocket(void) const {return m_Socket; } - cSocket & GetSocket(void) {return m_Socket; } + cSocket & GetSocket (void) { return m_Socket; } + const AString & GetIPString(void) const { return m_Socket.GetIPString(); } cPlayer* GetPlayer() { return m_Player; } // tolua_export diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 4605049b3..4095c633a 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -57,7 +57,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_FoodTickTimer(0) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", - a_PlayerName.c_str(), a_Client->GetSocket().GetIPString().c_str(), + a_PlayerName.c_str(), a_Client->GetIPString().c_str(), this, GetUniqueID() ); m_EntityType = eEntityType_Player; diff --git a/source/cServer.cpp b/source/cServer.cpp index b294842b7..988594943 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -510,7 +510,7 @@ void cServer::ServerCommand(const AString & a_Cmd) { virtual bool Item(cPlayer * a_Player) override { - LOG("\t%s @ %s", a_Player->GetName().c_str(), a_Player->GetClientHandle()->GetSocket().GetIPString().c_str()); + LOG("\t%s @ %s", a_Player->GetName().c_str(), a_Player->GetClientHandle()->GetIPString().c_str()); return false; } } Logger; -- cgit v1.2.3