1
0

cProtocol handles the initial handshake up to player login

git-svn-id: http://mc-server.googlecode.com/svn/trunk@804 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2012-08-30 08:19:19 +00:00
parent 658383edf8
commit fa93c0cf54
6 changed files with 61 additions and 69 deletions

View File

@@ -426,66 +426,21 @@ void cClientHandle::HandlePing(void)
void cClientHandle::HandleHandshake(const AString & a_Username)
{
AStringVector UserData = StringSplit(a_Username, ";"); // "FakeTruth;localhost:25565"
if (UserData.empty())
{
Kick("Did not receive username");
return;
}
m_Username = UserData[0];
LOGD("HANDSHAKE %s", m_Username.c_str());
if (cRoot::Get()->GetDefaultWorld()->GetNumPlayers() >= cRoot::Get()->GetDefaultWorld()->GetMaxPlayers())
{
Kick("The server is currently full :(-- Try again later");
return;
}
cRoot::Get()->GetServer()->BroadcastChat(m_Username + " is connecting.", this);
SendHandshake(cRoot::Get()->GetServer()->GetServerID());
LOGD("User \"%s\" was sent a handshake", m_Username.c_str());
}
void cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Username)
bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Username)
{
LOGD("LOGIN %s", a_Username.c_str());
if (a_ProtocolVersion < m_ProtocolVersion)
{
Kick("Your client is outdated!");
return;
}
else if (a_ProtocolVersion > m_ProtocolVersion)
{
Kick("Your client version is higher than the server!");
return;
}
if (m_Username.compare(a_Username) != 0)
{
LOGWARNING("Login Username (\"%s\") does not match Handshake username (\"%s\") for client @ \"%s\")",
a_Username.c_str(),
m_Username.c_str(),
m_Socket.GetIPString().c_str()
);
Kick("Hacked client"); // Don't tell them why we don't want them
return;
}
m_Username = a_Username;
if (cRoot::Get()->GetPluginManager()->CallHookLogin(this, a_ProtocolVersion, a_Username))
{
Destroy();
return;
return false;
}
// Schedule for authentication; until then, let them wait (but do not block)
m_State = csAuthenticating;
cRoot::Get()->GetAuthenticator().Authenticate(GetUniqueID(), GetUsername(), cRoot::Get()->GetServer()->GetServerID());
return true;
}
@@ -1066,15 +1021,6 @@ void cClientHandle::SendDisconnect(const AString & a_Reason)
void cClientHandle::SendHandshake(const AString & a_ServerName)
{
m_Protocol->SendHandshake(a_ServerName);
}
void cClientHandle::SendInventorySlot(int a_WindowID, short a_SlotNum, const cItem & a_Item)
{
m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item);