Skip to content

Commit

Permalink
Check one username only
Browse files Browse the repository at this point in the history
  • Loading branch information
kimden committed Jan 22, 2025
1 parent 6c06bd8 commit 02509a2
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,25 +478,13 @@ void ServerLobby::handleChat(Event* event)
core::stringw message;
event->data().decodeString16(&message, 360/*max_len*/);

// Check if the message starts with "(one of profile names): " to prevent
// Check if the message starts with "(the name of main profile): " to prevent
// impersonation, see #5121.
// If the server allows many messages in a row and there are many players
// inside one peer, naive check can become a problem. For most cases,
// it should be completely fine.
bool valid_message = false;
std::string message_utf8 = StringUtils::wideToUtf8(message);
for (auto& profile: event->getPeer()->getPlayerProfiles())
{
std::string prefix = StringUtils::wideToUtf8(
profile->getName()) + ": ";
if (StringUtils::startsWith(message_utf8, prefix))
{
valid_message = true;
break;
}
}

if (!valid_message)
std::string prefix = StringUtils::wideToUtf8(
event->getPeer()->getPlayerProfiles()[0]->getName()) + ": ";

if (!StringUtils::startsWith(message_utf8, prefix))
{
NetworkString* chat = getNetworkString();
chat->setSynchronous(true);
Expand Down

0 comments on commit 02509a2

Please sign in to comment.