Skip to content

Commit 84437e4

Browse files
Validate serial on player join (#3804)
This will help prevent cheaters that use a particular type of spoofer, from connecting. Server owners are recommended to upgrade MTA server to a version with this change included.
1 parent 733683d commit 84437e4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 16 additions & 1 deletion
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
@@ -1783,7 +1784,21 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
17831784

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

0 commit comments

Comments
 (0)