Skip to content

Commit 8edaee4

Browse files
validate serial on player join (regex)
1 parent 7e6b4d0 commit 8edaee4

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
570570
break;
571571
case ePlayerDisconnectType::SERIAL_VERIFICATION:
572572
strReason = _("Disconnected: Serial verification failed");
573-
strErrorCode = _E("CD44");
573+
strErrorCode = _E("CD50");
574574
break;
575575
case ePlayerDisconnectType::CONNECTION_DESYNC:
576576
strReason = _("Disconnected: Connection desync %s");
@@ -601,6 +601,10 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
601601
strReason = _("Disconnected: Server shutdown or restarting");
602602
strErrorCode = _E("CD49");
603603
break;
604+
case ePlayerDisconnectType::INVALID_SERIAL:
605+
strReason = _("Disconnected: Invalid serial");
606+
strErrorCode = _E("CD50");
607+
break;
604608
default:
605609
break;
606610
}

Client/mods/deathmatch/logic/CPacketHandler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class CPacketHandler
4242
BAN,
4343
KICK,
4444
CUSTOM,
45-
SHUTDOWN
45+
SHUTDOWN,
46+
INVALID_SERIAL,
4647
};
4748

4849
struct SEntityDependantStuff

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "version.h"
7272
#include "net/SimHeaders.h"
7373
#include <signal.h>
74+
#include <regex>
7475

7576
#define MAX_BULLETSYNC_DISTANCE 400.0f
7677
#define MAX_EXPLOSION_SYNC_DISTANCE 400.0f
@@ -1781,6 +1782,18 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
17811782
}
17821783
#endif
17831784

1785+
// Prevent player from connecting if serial is invalid
1786+
std::regex serialRegex("^[A-F0-9]{32}$");
1787+
if (!std::regex_match(strSerial, serialRegex))
1788+
{
1789+
// Tell the console
1790+
CLogger::LogPrintf("CONNECT: %s failed to connect (Invalid serial) (%s)\n", szNick, pPlayer->GetSourceIP());
1791+
1792+
// Tell the player the problem
1793+
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::INVALID_SERIAL);
1794+
return;
1795+
}
1796+
17841797
SString strIP = pPlayer->GetSourceIP();
17851798
SString strIPAndSerial("IP: %s Serial: %s Version: %s", strIP.c_str(), strSerial.c_str(), strPlayerVersion.c_str());
17861799
if (!CheckNickProvided(szNick)) // check the nick is valid

Server/mods/deathmatch/logic/packets/CPlayerDisconnectedPacket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class CPlayerDisconnectedPacket final : public CPacket
3939
BAN,
4040
KICK,
4141
CUSTOM,
42-
SHUTDOWN
42+
SHUTDOWN,
43+
INVALID_SERIAL
4344
};
4445

4546
CPlayerDisconnectedPacket(const char* szReason);

0 commit comments

Comments
 (0)