Ensure unique client GUIDs. Patch by sbirmi, fixes #3949.

Two clients chosing the same GUID is highly unlikely, yet possible.
A malicious client chosing an existing GUID would have resulted in
unassigning the player with that GUID.

This was SVN commit r19225.
This commit is contained in:
elexis
2017-02-14 16:54:34 +00:00
parent e436af56ce
commit e0f7578fbe
4 changed files with 15 additions and 1 deletions
+11
View File
@@ -903,6 +903,7 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event)
CAuthenticateMessage* message = (CAuthenticateMessage*)event->GetParamRef();
CStrW username = SanitisePlayerName(message->m_Name);
CStr guid = message->m_GUID;
// Either deduplicate or prohibit join if name is in use
bool duplicatePlayernames = false;
@@ -919,6 +920,16 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event)
return true;
}
// Disconnect user if the provided GUID is already in use
if (std::find_if(
server.m_Sessions.begin(), server.m_Sessions.end(),
[&guid] (const CNetServerSession* session)
{ return session->GetGUID() == guid; }) != server.m_Sessions.end())
{
session->Disconnect(NDR_PLAYERGUID_IN_USE);
return true;
}
// Disconnect banned usernames
if (std::find(server.m_BannedPlayers.begin(), server.m_BannedPlayers.end(), username) != server.m_BannedPlayers.end())
{