Core/Chat: Fix chat filter to not block certain non-ASCII characters

This commit is contained in:
Treeston
2018-09-18 16:55:58 +02:00
parent fcb45c416a
commit b4258ca4d9

View File

@@ -43,13 +43,11 @@
#include "WorldPacket.h"
#include <algorithm>
inline bool isNasty(char c)
inline bool isNasty(uint8 c)
{
if (c < 32) // all of these are control characters
return true;
if (c == 127) // ascii delete
return true;
if (c == 255) // non-breaking whitespace
if (c == '\t')
return false;
if (c <= '\037') // ASCII control block
return true;
return false;
}
@@ -244,12 +242,19 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
// do message validity checks
if (lang != LANG_ADDON)
{
// cut at the first newline or carriage return
std::string::size_type pos = msg.find_first_of("\n\r");
if (pos == 0)
return;
else if (pos != std::string::npos)
msg.erase(pos);
// abort on any sort of nasty character
for (char c : msg)
for (uint8 c : msg)
if (isNasty(c))
{
TC_LOG_ERROR("network", "Player %s (GUID: %u) sent a message containing control character %u - blocked", GetPlayer()->GetName().c_str(),
GetPlayer()->GetGUID().GetCounter(), uint32(c));
TC_LOG_ERROR("network", "Player %s (GUID: %u) sent a message containing invalid character %u - blocked", GetPlayer()->GetName().c_str(),
GetPlayer()->GetGUID().GetCounter(), uint8(c));
return;
}