Skip to content

Commit

Permalink
validate serial on player join (regex)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Oct 16, 2024
1 parent 7e6b4d0 commit 8edaee4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
break;
case ePlayerDisconnectType::SERIAL_VERIFICATION:
strReason = _("Disconnected: Serial verification failed");
strErrorCode = _E("CD44");
strErrorCode = _E("CD50");
break;
case ePlayerDisconnectType::CONNECTION_DESYNC:
strReason = _("Disconnected: Connection desync %s");
Expand Down Expand Up @@ -601,6 +601,10 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
strReason = _("Disconnected: Server shutdown or restarting");
strErrorCode = _E("CD49");
break;
case ePlayerDisconnectType::INVALID_SERIAL:
strReason = _("Disconnected: Invalid serial");
strErrorCode = _E("CD50");
break;
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CPacketHandler
BAN,
KICK,
CUSTOM,
SHUTDOWN
SHUTDOWN,
INVALID_SERIAL,
};

struct SEntityDependantStuff
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 @@ -71,6 +71,7 @@
#include "version.h"
#include "net/SimHeaders.h"
#include <signal.h>
#include <regex>

#define MAX_BULLETSYNC_DISTANCE 400.0f
#define MAX_EXPLOSION_SYNC_DISTANCE 400.0f
Expand Down Expand Up @@ -1781,6 +1782,18 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
}
#endif

// Prevent player from connecting if serial is invalid
std::regex serialRegex("^[A-F0-9]{32}$");
if (!std::regex_match(strSerial, serialRegex))
{
// Tell the console
CLogger::LogPrintf("CONNECT: %s failed to connect (Invalid serial) (%s)\n", szNick, pPlayer->GetSourceIP());

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

SString strIP = pPlayer->GetSourceIP();
SString strIPAndSerial("IP: %s Serial: %s Version: %s", strIP.c_str(), strSerial.c_str(), strPlayerVersion.c_str());
if (!CheckNickProvided(szNick)) // check the nick is valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class CPlayerDisconnectedPacket final : public CPacket
BAN,
KICK,
CUSTOM,
SHUTDOWN
SHUTDOWN,
INVALID_SERIAL
};

CPlayerDisconnectedPacket(const char* szReason);
Expand Down

0 comments on commit 8edaee4

Please sign in to comment.