feat(Core/Chat): new argument parsing and unify chat hyperlink parsing (#6243)

This commit is contained in:
Kargatum
2021-10-23 15:15:42 +07:00
committed by GitHub
parent 1101f9dd2a
commit bc9473482e
90 changed files with 4280 additions and 2508 deletions

View File

@@ -27,6 +27,7 @@
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
#include "Hyperlinks.h"
#include "Log.h"
#include "MapMgr.h"
#include "ObjectAccessor.h"
@@ -389,6 +390,26 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
break;
}
}
catch (WorldPackets::InvalidHyperlinkException const& ihe)
{
LOG_ERROR("network", "%s sent %s with an invalid link:\n%s", GetPlayerInfo().c_str(),
GetOpcodeNameForLogging(static_cast<OpcodeClient>(packet->GetOpcode())).c_str(), ihe.GetInvalidValue().c_str());
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
{
KickPlayer("WorldSession::Update Invalid chat link");
}
}
catch (WorldPackets::IllegalHyperlinkException const& ihe)
{
LOG_ERROR("network", "%s sent %s which illegally contained a hyperlink:\n%s", GetPlayerInfo().c_str(),
GetOpcodeNameForLogging(static_cast<OpcodeClient>(packet->GetOpcode())).c_str(), ihe.GetInvalidValue().c_str());
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
{
KickPlayer("WorldSession::Update Illegal chat link");
}
}
catch (WorldPackets::PacketArrayMaxCapacityException const& pamce)
{
LOG_ERROR("network", "PacketArrayMaxCapacityException: %s while parsing %s from %s.",
@@ -698,6 +719,34 @@ void WorldSession::KickPlayer(std::string const& reason, bool setKicked)
SetKicked(true); // pussywizard: the session won't be left ingame for 60 seconds and to also kick offline session
}
bool WorldSession::ValidateHyperlinksAndMaybeKick(std::string_view str)
{
if (Acore::Hyperlinks::CheckAllLinks(str))
return true;
LOG_ERROR("network", "Player %s%s sent a message with an invalid link:\n%.*s", GetPlayer()->GetName().c_str(),
GetPlayer()->GetGUID().ToString().c_str(), STRING_VIEW_FMT_ARG(str));
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
KickPlayer("WorldSession::ValidateHyperlinksAndMaybeKick Invalid chat link");
return false;
}
bool WorldSession::DisallowHyperlinksAndMaybeKick(std::string_view str)
{
if (str.find('|') == std::string_view::npos)
return true;
LOG_ERROR("network", "Player %s %s sent a message which illegally contained a hyperlink:\n%.*s", GetPlayer()->GetName().c_str(),
GetPlayer()->GetGUID().ToString().c_str(), STRING_VIEW_FMT_ARG(str));
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
KickPlayer("WorldSession::DisallowHyperlinksAndMaybeKick Illegal chat link");
return false;
}
void WorldSession::SendNotification(const char* format, ...)
{
if (format)