1
0

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
This commit is contained in:
madmaxoft@gmail.com 2012-09-04 19:05:35 +00:00
parent b379f35f4f
commit e3d5da2409
5 changed files with 10 additions and 7 deletions

View File

@ -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;

View File

@ -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())

View File

@ -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

View File

@ -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;

View File

@ -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;