Skip to content

Commit 27d8827

Browse files
committed
Refactor for better readability
1 parent a7866d6 commit 27d8827

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,22 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
292292
// TheSuperHackers @bugfix slurmlord 18/09/2025 need to validate the name of the connecting player before
293293
// allowing them to join to prevent messing up the format of game state string. Commas, colons, semicolons etc.
294294
// should not be in a player name. It should also not consist of only space characters.
295-
constexpr WideChar IllegalNameChars[] = L",:;|\f\n\r\t\v";
296-
if (canJoin && (wcscspn(msg->name, IllegalNameChars) || wcsspn(msg->name, L" ") == wcslen(msg->name)))
295+
if (canJoin)
297296
{
298-
// Just deny with a duplicate name reason, for backwards compatibility with retail
299-
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
300-
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
301-
reply.GameNotJoined.gameIP = m_localIP;
302-
reply.GameNotJoined.playerIP = senderIP;
303-
canJoin = false;
297+
constexpr WideChar IllegalNameChars[] = L",:;|\f\n\r\t\v";
298+
const Bool containsIllegalChars = wcscspn(msg->name, IllegalNameChars);
299+
const Bool isEffectivelyEmpty = wcsspn(msg->name, L" ") == wcslen(msg->name);
300+
if (containsIllegalChars || isEffectivelyEmpty)
301+
{
302+
// Just deny with a duplicate name reason, for backwards compatibility with retail
303+
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
304+
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
305+
reply.GameNotJoined.gameIP = m_localIP;
306+
reply.GameNotJoined.playerIP = senderIP;
307+
canJoin = false;
304308

305-
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
309+
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
310+
}
306311
}
307312

308313
// Then see if the player has a duplicate name

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,22 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
293293
// TheSuperHackers @bugfix slurmlord 18/09/2025 need to validate the name of the connecting player before
294294
// allowing them to join to prevent messing up the format of game state string. Commas, colons, semicolons etc.
295295
// should not be in a player name. It should also not consist of only space characters.
296-
constexpr WideChar IllegalNameChars[] = L",:;|\f\n\r\t\v";
297-
if (canJoin && (wcscspn(msg->name, IllegalNameChars) || wcsspn(msg->name, L" ") == wcslen(msg->name)))
296+
if (canJoin)
298297
{
299-
// Just deny with a duplicate name reason, for backwards compatibility with retail
300-
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
301-
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
302-
reply.GameNotJoined.gameIP = m_localIP;
303-
reply.GameNotJoined.playerIP = senderIP;
304-
canJoin = false;
298+
constexpr WideChar IllegalNameChars[] = L",:;|\f\n\r\t\v";
299+
const Bool containsIllegalChars = wcscspn(msg->name, IllegalNameChars);
300+
const Bool isEffectivelyEmpty = wcsspn(msg->name, L" ") == wcslen(msg->name);
301+
if (containsIllegalChars || isEffectivelyEmpty)
302+
{
303+
// Just deny with a duplicate name reason, for backwards compatibility with retail
304+
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;
305+
reply.GameNotJoined.reason = LANAPIInterface::RET_DUPLICATE_NAME;
306+
reply.GameNotJoined.gameIP = m_localIP;
307+
reply.GameNotJoined.playerIP = senderIP;
308+
canJoin = false;
305309

306-
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
310+
DEBUG_LOG(("LANAPI::handleRequestJoin - join denied because of illegal characters in the player name."));
311+
}
307312
}
308313

309314
// Then see if the player has a duplicate name

0 commit comments

Comments
 (0)