Skip to content

Commit

Permalink
Merge branch 'master' into min-ver-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Nov 21, 2024
2 parents deaf986 + af5b696 commit 4fa75f9
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 2 deletions.
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
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,
SERIAL_DUPLICATE
};

struct SEntityDependantStuff
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ void CWorldRPCs::SetSyncIntervals(NetBitStreamInterface& bitStream)
bitStream.Read(g_TickRateSettings.iObjectSync);
bitStream.Read(g_TickRateSettings.iKeySyncRotation);
bitStream.Read(g_TickRateSettings.iKeySyncAnalogMove);
bitStream.Read(g_TickRateSettings.iPedSyncerDistance);
bitStream.Read(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance);
}

void CWorldRPCs::SetMoonSize(NetBitStreamInterface& bitStream)
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.
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
15 changes: 15 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,21 @@ 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
if (pPlayer->CanBitStream(eBitStreamVersion::CheckDuplicateSerials))
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::SERIAL_DUPLICATE);
else
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::KICK);

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;
};
11 changes: 11 additions & 0 deletions Server/mods/deathmatch/logic/CPlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ CPlayer* CPlayerManager::Get(const char* szNick, bool bCaseSensitive)
return NULL;
}

CPlayer* CPlayerManager::GetBySerial(const std::string_view serial) const noexcept
{
for (const 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 std::string_view 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
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10861,6 +10861,8 @@ bool CStaticFunctionDefinitions::SendSyncIntervals(CPlayer* pPlayer)
BitStream.pBitStream->Write(g_TickRateSettings.iObjectSync);
BitStream.pBitStream->Write(g_TickRateSettings.iKeySyncRotation);
BitStream.pBitStream->Write(g_TickRateSettings.iKeySyncAnalogMove);
BitStream.pBitStream->Write(g_TickRateSettings.iPedSyncerDistance);
BitStream.pBitStream->Write(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance);
if (pPlayer)
pPlayer->Send(CLuaPacket(SET_SYNC_INTERVALS, *BitStream.pBitStream));
else
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,
SERIAL_DUPLICATE
};

CPlayerDisconnectedPacket(const char* szReason);
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
4 changes: 4 additions & 0 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ enum class eBitStreamVersion : unsigned short
// 2024-09-04
RespawnObject_Serverside,

// Add check_duplicate_serials
// 2024-09-04
CheckDuplicateSerials,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Next,
Expand Down

0 comments on commit 4fa75f9

Please sign in to comment.