mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-14 08:23:52 +00:00
fix(chat): prevent AFK/DND auto-reply whisper spam loop
Auto-reply was sent on every incoming whisper with no dedup, causing infinite loops when both players had auto-reply enabled. Now tracks which senders have been replied to and only sends one auto-reply per sender per AFK/DND session.
This commit is contained in:
parent
19bfaaef97
commit
e4bd380c0d
2 changed files with 10 additions and 2 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace wowee {
|
||||
|
|
@ -67,6 +68,10 @@ private:
|
|||
std::deque<MessageChatData> chatHistory_;
|
||||
size_t maxChatHistory_ = 100;
|
||||
std::vector<std::string> joinedChannels_;
|
||||
|
||||
// Track senders we've already auto-replied to (AFK/DND) this session
|
||||
// to prevent infinite reply loops. Cleared when AFK/DND is toggled off.
|
||||
std::unordered_set<std::string> afkAutoRepliedSenders_;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
|
|
|||
|
|
@ -264,10 +264,11 @@ void ChatHandler::handleMessageChat(network::Packet& packet) {
|
|||
owner_.lastWhisperSender_ = data.senderName;
|
||||
|
||||
if (!data.senderName.empty()) {
|
||||
if (owner_.afkStatus_) {
|
||||
// Only auto-reply once per sender per AFK/DND session to prevent loops
|
||||
if (owner_.afkStatus_ && afkAutoRepliedSenders_.insert(data.senderName).second) {
|
||||
std::string reply = owner_.afkMessage_.empty() ? "Away from Keyboard" : owner_.afkMessage_;
|
||||
sendChatMessage(ChatType::WHISPER, "<AFK> " + reply, data.senderName);
|
||||
} else if (owner_.dndStatus_) {
|
||||
} else if (owner_.dndStatus_ && afkAutoRepliedSenders_.insert(data.senderName).second) {
|
||||
std::string reply = owner_.dndMessage_.empty() ? "Do Not Disturb" : owner_.dndMessage_;
|
||||
sendChatMessage(ChatType::WHISPER, "<DND> " + reply, data.senderName);
|
||||
}
|
||||
|
|
@ -621,6 +622,7 @@ void ChatHandler::toggleAfk(const std::string& message) {
|
|||
} else {
|
||||
addSystemChatMessage("You are no longer AFK.");
|
||||
owner_.afkMessage_.clear();
|
||||
afkAutoRepliedSenders_.clear();
|
||||
}
|
||||
|
||||
LOG_INFO("AFK status: ", owner_.afkStatus_, ", message: ", message);
|
||||
|
|
@ -644,6 +646,7 @@ void ChatHandler::toggleDnd(const std::string& message) {
|
|||
} else {
|
||||
addSystemChatMessage("You are no longer DND.");
|
||||
owner_.dndMessage_.clear();
|
||||
afkAutoRepliedSenders_.clear();
|
||||
}
|
||||
|
||||
LOG_INFO("DND status: ", owner_.dndStatus_, ", message: ", message);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue