Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
55 changes: 52 additions & 3 deletions Generals/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,20 +619,69 @@ void ConnectionManager::processChat(NetChatCommandMsg *msg)
name = m_connections[playerID]->getUser()->GetName();
//DEBUG_LOG(("connection is non-NULL, using %ls", name.str()));
}
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
// DEBUG_LOG(("ConnectionManager::processChat - got message from player %d (mask %8.8X), message is %ls", playerID, msg->getPlayerMask(), unitext.str()));

AsciiString playerName;
playerName.format("player%d", msg->getPlayerID());
const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );
if (!player)
{
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
TheInGameUI->message(UnicodeString(L"%ls"), unitext.str());
return;
}

// TheSuperHackers @feature TheSuperHackers 31/10/2025 Add team chat prefix to distinguish from global messages
// Global chat has no prefix (default), team messages are prefixed with (TEAM)
Bool isTeamMessage = FALSE;
Bool fromObserver = !player->isPlayerActive();
Bool amIObserver = !ThePlayerList->getLocalPlayer()->isPlayerActive();
const Player *localPlayer = ThePlayerList->getLocalPlayer();

if (player->isPlayerActive())
{
// Count how many active (non-observer) players receive this message
Int activePlayers = 0;
Int alliesCount = 0;

for (Int i = 0; i < MAX_SLOTS; ++i)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is correct. You only need to verify the relationship between receiver and sender. Don't need to loop through all players for this.

{
if ((1 << i) & msg->getPlayerMask())
{
AsciiString checkPlayerName;
checkPlayerName.format("player%d", i);
const Player *checkPlayer = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(checkPlayerName));

if (checkPlayer && checkPlayer->isPlayerActive())
{
activePlayers++;

// Check if this recipient is an ally of the sender
if (player->getRelationship(checkPlayer->getDefaultTeam()) == ALLIES &&
checkPlayer->getRelationship(player->getDefaultTeam()) == ALLIES)
{
alliesCount++;
}
}
}
}

// Team message: sent to allies only (not to all active players)
isTeamMessage = (activePlayers == alliesCount && alliesCount > 0);
}

if (isTeamMessage)
{
// Format: (TEAM) [Player Name] Message
UnicodeString teamPrefix = TheGameText->FETCH_OR_SUBSTITUTE("GUI:Team", L"TEAM");
unitext.format(L"(%ls) [%ls] %ls", teamPrefix.str(), name.str(), msg->getText().str());
}
else
{
// Format: [Player Name] Message (no prefix for global/observer chat)
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
}
// DEBUG_LOG(("ConnectionManager::processChat - got message from player %d (mask %8.8X), message is %ls", playerID, msg->getPlayerMask(), unitext.str()));

Bool amIObserver = !localPlayer->isPlayerActive();
Bool canSeeChat = (amIObserver || !fromObserver) && !TheGameInfo->getConstSlot(playerID)->isMuted();

if ( ((1<<m_localSlot) & msg->getPlayerMask() ) && canSeeChat )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,20 +619,69 @@ void ConnectionManager::processChat(NetChatCommandMsg *msg)
name = m_connections[playerID]->getUser()->GetName();
//DEBUG_LOG(("connection is non-NULL, using %ls", name.str()));
}
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
// DEBUG_LOG(("ConnectionManager::processChat - got message from player %d (mask %8.8X), message is %ls", playerID, msg->getPlayerMask(), unitext.str()));

AsciiString playerName;
playerName.format("player%d", msg->getPlayerID());
const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );
if (!player)
{
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
TheInGameUI->message(UnicodeString(L"%ls"), unitext.str());
return;
}

// TheSuperHackers @feature TheSuperHackers 31/10/2025 Add team chat prefix to distinguish from global messages
// Global chat has no prefix (default), team messages are prefixed with (TEAM)
Bool isTeamMessage = FALSE;
Bool fromObserver = !player->isPlayerActive();
Bool amIObserver = !ThePlayerList->getLocalPlayer()->isPlayerActive();
const Player *localPlayer = ThePlayerList->getLocalPlayer();

if (player->isPlayerActive())
{
// Count how many active (non-observer) players receive this message
Int activePlayers = 0;
Int alliesCount = 0;

for (Int i = 0; i < MAX_SLOTS; ++i)
{
if ((1 << i) & msg->getPlayerMask())
{
AsciiString checkPlayerName;
checkPlayerName.format("player%d", i);
const Player *checkPlayer = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(checkPlayerName));

if (checkPlayer && checkPlayer->isPlayerActive())
{
activePlayers++;

// Check if this recipient is an ally of the sender
if (player->getRelationship(checkPlayer->getDefaultTeam()) == ALLIES &&
checkPlayer->getRelationship(player->getDefaultTeam()) == ALLIES)
{
alliesCount++;
}
}
}
}

// Team message: sent to allies only (not to all active players)
isTeamMessage = (activePlayers == alliesCount && alliesCount > 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a complicated way to determine this is a team message. Can this be simplified?

Also this would be better as a standalone isTeamChat function, not embedded in ConnectionManager::processChat like this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay its no big deal will work on it later still in the process of understanding the code

}

if (isTeamMessage)
{
// Format: (TEAM) [Player Name] Message
UnicodeString teamPrefix = TheGameText->FETCH_OR_SUBSTITUTE("GUI:Team", L"TEAM");
unitext.format(L"(%ls) [%ls] %ls", teamPrefix.str(), name.str(), msg->getText().str());
}
else
{
// Format: [Player Name] Message (no prefix for global/observer chat)
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
}
// DEBUG_LOG(("ConnectionManager::processChat - got message from player %d (mask %8.8X), message is %ls", playerID, msg->getPlayerMask(), unitext.str()));

Bool amIObserver = !localPlayer->isPlayerActive();
Bool canSeeChat = (amIObserver || !fromObserver) && !TheGameInfo->getConstSlot(playerID)->isMuted();

if ( ((1<<m_localSlot) & msg->getPlayerMask() ) && canSeeChat )
Expand Down