Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if another player has the same serial #3854

Merged
merged 11 commits into from
Nov 21, 2024
4 changes: 4 additions & 0 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
strReason = _("Disconnected: Serial verification failed");
strErrorCode = _E("CD44");
break;
case ePlayerDisconnectType::SERIAL_DUPLICATE:
strReason = _("Disconnected: Serial already in use");
strErrorCode = _E("CD50");
break;
case ePlayerDisconnectType::CONNECTION_DESYNC:
strReason = _("Disconnected: Connection desync %s");
strErrorCode = _E("CD45");
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CPacketHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CPacketHandler
ELEMENT_FAILURE,
GENERAL_REFUSED,
SERIAL_VERIFICATION,
SERIAL_DUPLICATE,
CONNECTION_DESYNC,
BAN,
KICK,
Expand Down
13 changes: 13 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,19 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
return;
}

// Check if another player is using the same serial
CPlayer* playerExisting = m_pPlayerManager->GetBySerial(strSerial);

if (playerExisting)
{
// Tell the console
CLogger::LogPrintf("CONNECT: %s failed to connect (Serial already in use) (%s)\n", szNick, strIPAndSerial.c_str());

// Tell the player the problem
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::SERIAL_DUPLICATE);
return;
}

// Check the nick is valid
if (!CheckNickProvided(szNick))
{
Expand Down
13 changes: 13 additions & 0 deletions Server/mods/deathmatch/logic/CPlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ CPlayer* CPlayerManager::Get(const char* szNick, bool bCaseSensitive)
return NULL;
}

CPlayer* CPlayerManager::GetBySerial(const SString& serial) const noexcept
{
for (auto& player : m_Players)
{
if (player->GetSerial() == serial)
{
return player;
}
}

return nullptr;
}

void CPlayerManager::DeleteAll()
{
// Delete all the items in the list
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPlayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CPlayerManager

CPlayer* Get(const NetServerPlayerID& PlayerSocket);
CPlayer* Get(const char* szNick, bool bCaseSensitive = false);
CPlayer* GetBySerial(const SString& serial) const noexcept;

std::list<CPlayer*>::const_iterator IterBegin() { return m_Players.begin(); };
std::list<CPlayer*>::const_iterator IterEnd() { return m_Players.end(); };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CPlayerDisconnectedPacket final : public CPacket
ELEMENT_FAILURE,
GENERAL_REFUSED,
SERIAL_VERIFICATION,
SERIAL_DUPLICATE,
CONNECTION_DESYNC,
BAN,
KICK,
Expand Down
Loading