mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
fix(chat): team, guild and whisper chat go through the chat filter
Team and guild chat use the same filter as zone chat, and whispers the same one as the world's string check (the relaxed list between best friends). A message the filter stops is logged as blocked and goes to nobody. A muted player gets the mute notice zone chat sends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -437,9 +437,28 @@ namespace {
|
||||
LWOOBJID teamId{}; // team chat
|
||||
};
|
||||
|
||||
// The world's chat filter, as zone chat uses it. Whispers to a best friend use the relaxed list, as the world's string check does.
|
||||
bool PassesChatFilter(const PlayerData& sender, const std::string& message, const bool allowList = true) {
|
||||
return !Game::chatFilter || Game::chatFilter->IsSentenceOkay(message, sender.gmLevel, allowList).empty();
|
||||
}
|
||||
|
||||
// What zone chat tells a muted player, sent for the chat this server delivers
|
||||
void SendMuteNotice(const PlayerData& sender) {
|
||||
char buffer[32] = "brought up for review.";
|
||||
if (sender.muteExpire != 1) {
|
||||
const time_t expire = sender.muteExpire;
|
||||
if (const std::tm* ptm = std::localtime(&expire)) std::strftime(buffer, sizeof(buffer), "%a, %d.%m.%Y %H:%M:%S", ptm);
|
||||
}
|
||||
ChatPackets::Client::GeneralChatMessage notice;
|
||||
notice.chatChannel = 4; // system
|
||||
notice.senderName = LUWString("", 33);
|
||||
notice.message = u"You are muted until " + GeneralUtils::ASCIIToUTF16(buffer);
|
||||
ChatPacketHandler::SendRouted(sender.playerID, sender.worldServerSysAddr, notice);
|
||||
}
|
||||
|
||||
// Whispers, team and guild chat, for moderation (log_chat=0 turns chat logging off, log_private_chat=0 just these).
|
||||
// Written as the message is sent, with what the chat filter thinks of it: these are delivered either way.
|
||||
void LogChat(const PlayerData& sender, const std::string& channel, const std::string& message, const ChatScope& scope = {}) {
|
||||
// Written with what the chat filter thought of it: a message the filter stops is logged as blocked and goes to nobody.
|
||||
void LogChat(const PlayerData& sender, const std::string& channel, const std::string& message, const bool passed, const ChatScope& scope = {}) {
|
||||
if (Game::config->GetValue("log_chat") == "0" || Game::config->GetValue("log_private_chat") == "0") return;
|
||||
IChatLog::ChatMessage entry;
|
||||
entry.time = static_cast<int64_t>(std::time(nullptr));
|
||||
@@ -454,7 +473,8 @@ namespace {
|
||||
entry.instanceId = sender.zoneID.GetInstanceID();
|
||||
entry.cloneId = sender.zoneID.GetCloneID();
|
||||
entry.message = message;
|
||||
entry.filtered = Game::chatFilter && !Game::chatFilter->IsSentenceOkay(message, sender.gmLevel).empty();
|
||||
entry.filtered = !passed;
|
||||
entry.blocked = !passed;
|
||||
try {
|
||||
if (const auto info = Database::Get()->GetCharacterInfo(sender.playerID)) entry.accountId = info->accountId;
|
||||
Database::Get()->InsertChatMessage(entry);
|
||||
@@ -468,7 +488,11 @@ void ChatPacketHandler::HandleChatMessage(const ChatPackets::GeneralChatMessage&
|
||||
const LWOOBJID playerID = chatMessage.playerID;
|
||||
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(playerID);
|
||||
if (!sender || sender.GetIsMuted()) return;
|
||||
if (!sender) return;
|
||||
if (sender.GetIsMuted()) {
|
||||
SendMuteNotice(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// Messages longer than MAX_MESSAGE_LENGTH were dropped when read
|
||||
const eChatChannel channel = chatMessage.chatChannel;
|
||||
@@ -480,7 +504,9 @@ void ChatPacketHandler::HandleChatMessage(const ChatPackets::GeneralChatMessage&
|
||||
case eChatChannel::TEAM: {
|
||||
auto* team = TeamContainer::GetTeam(playerID);
|
||||
if (team == nullptr) return;
|
||||
LogChat(sender, "team", message.GetAsString(), { .teamId = team->teamID });
|
||||
const bool passed = PassesChatFilter(sender, message.GetAsString());
|
||||
LogChat(sender, "team", message.GetAsString(), passed, { .teamId = team->teamID });
|
||||
if (!passed) return;
|
||||
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
const auto& otherMember = Game::playerContainer.GetPlayerData(memberId);
|
||||
@@ -494,7 +520,9 @@ void ChatPacketHandler::HandleChatMessage(const ChatPackets::GeneralChatMessage&
|
||||
const auto members = ChatGuilds::Get().OnlineGuildmates(playerID);
|
||||
if (members.empty()) return;
|
||||
const auto guildMember = Database::Get()->GetGuildMember(playerID);
|
||||
LogChat(sender, "guild", message.GetAsString(), { .guildId = guildMember ? guildMember->guildId : 0 });
|
||||
const bool passed = PassesChatFilter(sender, message.GetAsString());
|
||||
LogChat(sender, "guild", message.GetAsString(), passed, { .guildId = guildMember ? guildMember->guildId : 0 });
|
||||
if (!passed) return;
|
||||
for (const auto memberId : members) {
|
||||
const auto& member = Game::playerContainer.GetPlayerData(memberId);
|
||||
if (member) SendPrivateChatMessage(sender, member, member, message, eChatChannel::GUILD, eChatMessageResponseCode::SENT);
|
||||
@@ -513,7 +541,11 @@ void ChatPacketHandler::HandlePrivateChatMessage(const ChatPackets::PrivateChatM
|
||||
const LWOOBJID playerID = chatMessage.playerID;
|
||||
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(playerID);
|
||||
if (!sender || sender.GetIsMuted()) return;
|
||||
if (!sender) return;
|
||||
if (sender.GetIsMuted()) {
|
||||
SendMuteNotice(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
const eChatChannel channel = chatMessage.chatChannel;
|
||||
if (channel != eChatChannel::PRIVATE_CHAT) LOG("WARNING: Received Private chat with the wrong channel!");
|
||||
@@ -540,7 +572,9 @@ void ChatPacketHandler::HandlePrivateChatMessage(const ChatPackets::PrivateChatM
|
||||
// only freinds can whispr each other
|
||||
for (const auto& fr : receiver.friends) {
|
||||
if (fr.friendID == sender.playerID) {
|
||||
LogChat(sender, "whisper", message.GetAsString(), { .recipientId = receiver.playerID, .recipientName = receiver.playerName });
|
||||
const bool passed = PassesChatFilter(sender, message.GetAsString(), !fr.isBestFriend);
|
||||
LogChat(sender, "whisper", message.GetAsString(), passed, { .recipientId = receiver.playerID, .recipientName = receiver.playerName });
|
||||
if (!passed) return;
|
||||
//To the sender:
|
||||
SendPrivateChatMessage(sender, receiver, sender, message, eChatChannel::PRIVATE_CHAT, eChatMessageResponseCode::SENT);
|
||||
//To the receiver:
|
||||
|
||||
Reference in New Issue
Block a user