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
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
CONNECTION_DESYNC,
BAN,
KICK,
Expand Down
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/editor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<resource_client_file_checks>1</resource_client_file_checks>

<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
Note that this may break compatibility with virtual machines.
Not guarantees that the player cannot manipulate their serial.
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<check_duplicate_serials>1</check_duplicate_serials>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand Down
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/local.conf
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@
Values: 0 - Off, 1 - Enabled. Default - 0 -->
<elementdata_whitelisted>0</elementdata_whitelisted>

<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
Note that this may break compatibility with virtual machines.
Not guarantees that the player cannot manipulate their serial.
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<check_duplicate_serials>1</check_duplicate_serials>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand Down
11 changes: 11 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,17 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
return;
}

// Check if another player is using the same serial
if (m_pMainConfig->IsCheckDuplicateSerialsEnabled() && m_pPlayerManager->GetBySerial(strSerial))
{
// 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);
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

// Check the nick is valid
if (!CheckNickProvided(szNick))
{
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ CMainConfig::CMainConfig(CConsole* pConsole) : CXMLConfig(NULL)
m_iBackupAmount = 5;
m_bSyncMapElementData = true;
m_elementDataWhitelisted = false;
m_checkDuplicateSerials = true;
}

bool CMainConfig::Load()
Expand Down Expand Up @@ -528,6 +529,7 @@ bool CMainConfig::Load()
}

GetBoolean(m_pRootNode, "elementdata_whitelisted", m_elementDataWhitelisted);
GetBoolean(m_pRootNode, "check_duplicate_serials", m_checkDuplicateSerials);

ApplyNetOptions();

Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CMainConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class CMainConfig : public CXMLConfig
bool IsDatabaseCredentialsProtectionEnabled() const { return m_bDatabaseCredentialsProtectionEnabled != 0; }
bool IsFakeLagCommandEnabled() const { return m_bFakeLagCommandEnabled != 0; }
bool IsElementDataWhitelisted() const { return m_elementDataWhitelisted; }
bool IsCheckDuplicateSerialsEnabled() const noexcept { return m_checkDuplicateSerials; }
bool IsCheckResourceClientFilesEnabled() const noexcept { return m_checkResourceClientFiles != 0; }

SString GetSetting(const SString& configSetting);
Expand Down Expand Up @@ -230,5 +231,6 @@ class CMainConfig : public CXMLConfig
int m_iPlayerTriggeredEventIntervalMs;
int m_iMaxPlayerTriggeredEventsPerInterval;
bool m_elementDataWhitelisted;
bool m_checkDuplicateSerials;
int m_checkResourceClientFiles;
};
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;
}

const CPlayer* CPlayerManager::GetBySerial(const std::string serial) const noexcept
{
for (const auto& player : m_Players)
{
if (player->GetSerial() == serial)
{
return player;
}
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
}

return nullptr;
}

void CPlayerManager::DeleteAll()
{
// Delete all the items in the list
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CPlayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CPlayerManager;
#include "packets/CPacket.h"
#include "CPlayer.h"
#include "../Config.h"
#include <string>
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved

class CPlayerManager
{
Expand All @@ -40,6 +41,7 @@ class CPlayerManager

CPlayer* Get(const NetServerPlayerID& PlayerSocket);
CPlayer* Get(const char* szNick, bool bCaseSensitive = false);
const CPlayer* GetBySerial(const std::string serial) const noexcept;
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved

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,
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
CONNECTION_DESYNC,
BAN,
KICK,
Expand Down
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/mtaserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@
Values: 0 - Off, 1 - Enabled. Default - 0 -->
<elementdata_whitelisted>0</elementdata_whitelisted>

<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
Note that this may break compatibility with virtual machines.
Not guarantees that the player cannot manipulate their serial.
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<check_duplicate_serials>1</check_duplicate_serials>

<!-- These parameters specify the maximum amount of events that can be triggered by the client (via triggerServerEvent) within the given interval.
Note: The interval is given in milliseconds
Interval range: 50 to 5000. Default: 1000
Expand Down
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/mtaserver.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@
Values: 0 - Off, 1 - Enabled. Default - 0 -->
<elementdata_whitelisted>0</elementdata_whitelisted>

<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
Note that this may break compatibility with virtual machines.
Not guarantees that the player cannot manipulate their serial.
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<check_duplicate_serials>1</check_duplicate_serials>

<!-- These parameters specify the maximum amount of events that can be triggered by the client (via triggerServerEvent) within the given interval.
Note: The interval is given in milliseconds
Interval range: 50 to 5000. Default: 1000
Expand Down
Loading