Skip to content

Commit 45fb971

Browse files
committed
bugfix(network): Deny players with invalid names to join game
1 parent dd2bb78 commit 45fb971

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,21 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
289289
}
290290
#endif
291291

292-
// We're the host, so see if he has a duplicate name
292+
// We're the host, so first validate the name
293+
if (wcschr(msg->name, L',') || wcschr(msg->name, L';') || wcschr(msg->name, L':'))
294+
{
295+
// Commas, colons or semicolons should not be in a player name.
296+
// If so, just deny with a duplicate name error (for backwards compatibility with retail)
297+
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
298+
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
299+
reply.GameNotJoined.gameIP = m_localIP;
300+
reply.GameNotJoined.playerIP = senderIP;
301+
canJoin = false;
302+
303+
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
304+
}
305+
306+
// Then see if the player has a duplicate name
293307
for (player = 0; canJoin && player<MAX_SLOTS; ++player)
294308
{
295309
LANGameSlot *slot = m_currentGame->getLANSlot(player);

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,21 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
290290
}
291291
#endif
292292

293-
// We're the host, so see if he has a duplicate name
293+
// We're the host, so first validate the name
294+
if (wcschr(msg->name, L',') || wcschr(msg->name, L';') || wcschr(msg->name, L':'))
295+
{
296+
// Commas, colons or semicolons should not be in a player name.
297+
// If so, just deny with a duplicate name error (for backwards compatibility with retail)
298+
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
299+
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
300+
reply.GameNotJoined.gameIP = m_localIP;
301+
reply.GameNotJoined.playerIP = senderIP;
302+
canJoin = false;
303+
304+
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
305+
}
306+
307+
// Then see if the player has a duplicate name
294308
for (player = 0; canJoin && player<MAX_SLOTS; ++player)
295309
{
296310
LANGameSlot *slot = m_currentGame->getLANSlot(player);

0 commit comments

Comments
 (0)