Skip to content

Commit a30a173

Browse files
Synchronize changes from 1.6 master branch [ci skip]
e094942 Check if another player has the same serial (#3854) 4723153 Visual Studio Update
2 parents 2debb54 + e094942 commit a30a173

File tree

13 files changed

+67
-2
lines changed

13 files changed

+67
-2
lines changed

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
572572
strReason = _("Disconnected: Serial verification failed");
573573
strErrorCode = _E("CD44");
574574
break;
575+
case ePlayerDisconnectType::SERIAL_DUPLICATE:
576+
strReason = _("Disconnected: Serial already in use");
577+
strErrorCode = _E("CD50");
578+
break;
575579
case ePlayerDisconnectType::CONNECTION_DESYNC:
576580
strReason = _("Disconnected: Connection desync %s");
577581
strErrorCode = _E("CD45");

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+
SERIAL_DUPLICATE
4647
};
4748

4849
struct SEntityDependantStuff

Server/mods/deathmatch/editor.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@
268268
Values: 0 - Off, 1 - Enabled. Default - 1 -->
269269
<resource_client_file_checks>1</resource_client_file_checks>
270270

271+
<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
272+
Note that this may break compatibility with virtual machines.
273+
Not guarantees that the player cannot manipulate their serial.
274+
Values: 0 - Off, 1 - Enabled. Default - 1 -->
275+
<check_duplicate_serials>1</check_duplicate_serials>
276+
271277
<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
272278
parameter(s). Optional parameter. -->
273279
<!-- <module src="sample_win32.dll"/> -->

Server/mods/deathmatch/local.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@
274274
Values: 0 - Off, 1 - Enabled. Default - 0 -->
275275
<elementdata_whitelisted>0</elementdata_whitelisted>
276276

277+
<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
278+
Note that this may break compatibility with virtual machines.
279+
Not guarantees that the player cannot manipulate their serial.
280+
Values: 0 - Off, 1 - Enabled. Default - 1 -->
281+
<check_duplicate_serials>1</check_duplicate_serials>
282+
277283
<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
278284
parameter(s). Optional parameter. -->
279285
<!-- <module src="sample_win32.dll"/> -->

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,21 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
17981798
return;
17991799
}
18001800

1801+
// Check if another player is using the same serial
1802+
if (m_pMainConfig->IsCheckDuplicateSerialsEnabled() && m_pPlayerManager->GetBySerial(strSerial))
1803+
{
1804+
// Tell the console
1805+
CLogger::LogPrintf("CONNECT: %s failed to connect (Serial already in use) (%s)\n", szNick, strIPAndSerial.c_str());
1806+
1807+
// Tell the player the problem
1808+
if (pPlayer->CanBitStream(eBitStreamVersion::CheckDuplicateSerials))
1809+
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::SERIAL_DUPLICATE);
1810+
else
1811+
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::KICK);
1812+
1813+
return;
1814+
}
1815+
18011816
// Check the nick is valid
18021817
if (!CheckNickProvided(szNick))
18031818
{

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ CMainConfig::CMainConfig(CConsole* pConsole) : CXMLConfig(NULL)
8080
m_iBackupAmount = 5;
8181
m_bSyncMapElementData = true;
8282
m_elementDataWhitelisted = false;
83+
m_checkDuplicateSerials = true;
8384
}
8485

8586
bool CMainConfig::Load()
@@ -528,6 +529,7 @@ bool CMainConfig::Load()
528529
}
529530

530531
GetBoolean(m_pRootNode, "elementdata_whitelisted", m_elementDataWhitelisted);
532+
GetBoolean(m_pRootNode, "check_duplicate_serials", m_checkDuplicateSerials);
531533

532534
ApplyNetOptions();
533535

Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class CMainConfig : public CXMLConfig
127127
bool IsDatabaseCredentialsProtectionEnabled() const { return m_bDatabaseCredentialsProtectionEnabled != 0; }
128128
bool IsFakeLagCommandEnabled() const { return m_bFakeLagCommandEnabled != 0; }
129129
bool IsElementDataWhitelisted() const { return m_elementDataWhitelisted; }
130+
bool IsCheckDuplicateSerialsEnabled() const noexcept { return m_checkDuplicateSerials; }
130131
bool IsCheckResourceClientFilesEnabled() const noexcept { return m_checkResourceClientFiles != 0; }
131132

132133
SString GetSetting(const SString& configSetting);
@@ -230,5 +231,6 @@ class CMainConfig : public CXMLConfig
230231
int m_iPlayerTriggeredEventIntervalMs;
231232
int m_iMaxPlayerTriggeredEventsPerInterval;
232233
bool m_elementDataWhitelisted;
234+
bool m_checkDuplicateSerials;
233235
int m_checkResourceClientFiles;
234236
};

Server/mods/deathmatch/logic/CPlayerManager.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ CPlayer* CPlayerManager::Get(const char* szNick, bool bCaseSensitive)
138138
return NULL;
139139
}
140140

141+
CPlayer* CPlayerManager::GetBySerial(const std::string_view serial) const noexcept
142+
{
143+
for (const auto& player : m_Players)
144+
{
145+
if (player->GetSerial() == serial)
146+
return player;
147+
}
148+
149+
return nullptr;
150+
}
151+
141152
void CPlayerManager::DeleteAll()
142153
{
143154
// Delete all the items in the list

Server/mods/deathmatch/logic/CPlayerManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CPlayerManager
4040

4141
CPlayer* Get(const NetServerPlayerID& PlayerSocket);
4242
CPlayer* Get(const char* szNick, bool bCaseSensitive = false);
43+
CPlayer* GetBySerial(const std::string_view serial) const noexcept;
4344

4445
std::list<CPlayer*>::const_iterator IterBegin() { return m_Players.begin(); };
4546
std::list<CPlayer*>::const_iterator IterEnd() { return m_Players.end(); };

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+
SERIAL_DUPLICATE
4344
};
4445

4546
CPlayerDisconnectedPacket(const char* szReason);

0 commit comments

Comments
 (0)