From 7bbf3aac1779c516423f3531b1f8492e959ae8c4 Mon Sep 17 00:00:00 2001 From: in1tiate <32779090+in1tiate@users.noreply.github.com> Date: Sat, 6 Apr 2024 08:17:07 -0500 Subject: [PATCH] Check doublepost per client, not per area, take 2 (#345) * Check for doubleposts per client, not per area * Don't count testimony commands as doubleposts * noooo the heckin indenterinos * change func name for clarity * *tiktok voice* Drowning myself in the skibidi toilet! * fix segfault on blankpost (oopsie!) --- core/include/packet/packet_ms.h | 1 + core/src/packet/packet_ms.cpp | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/include/packet/packet_ms.h b/core/include/packet/packet_ms.h index 4086b60a..0411a197 100644 --- a/core/include/packet/packet_ms.h +++ b/core/include/packet/packet_ms.h @@ -13,5 +13,6 @@ class PacketMS : public AOPacket private: AOPacket *validateIcPacket(AOClient &client) const; + QRegularExpressionMatch isTestimonyJumpCommand(QString message) const; }; #endif diff --git a/core/src/packet/packet_ms.cpp b/core/src/packet/packet_ms.cpp index d572c4eb..2d8394da 100644 --- a/core/src/packet/packet_ms.cpp +++ b/core/src/packet/packet_ms.cpp @@ -123,9 +123,14 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const if (l_incoming_args[4].toString().size() > ConfigManager::maxCharacters()) return l_invalid; + // Doublepost prevention. Has to ignore blankposts and testimony commands. QString l_incoming_msg = client.dezalgo(l_incoming_args[4].toString().trimmed()); - if (!area->lastICMessage().isEmpty() && l_incoming_msg == area->lastICMessage()[4] && l_incoming_msg != "") - return l_invalid; + QRegularExpressionMatch match = isTestimonyJumpCommand(client.decodeMessage(l_incoming_msg)); + bool msg_is_testimony_cmd = (match.hasMatch() || l_incoming_msg == ">" || l_incoming_msg == "<"); + if (!client.m_last_message.isEmpty() // If the last message you sent isn't empty, + && l_incoming_msg == client.m_last_message // and it matches the one you're sending, + && !msg_is_testimony_cmd) // and it's not a testimony command, + return l_invalid; // get it the hell outta here! if (l_incoming_msg == "" && area->blankpostingAllowed() == false) { client.sendServerMessage("Blankposting has been forbidden in this area."); @@ -408,10 +413,7 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const client.sendServerMessage("First statement reached."); } } - - QString l_decoded_message = client.decodeMessage(l_args[4]); // Get rid of that pesky encoding first. - QRegularExpression jump("(?>)(?[0,1,2,3,4,5,6,7,8,9]+)"); - QRegularExpressionMatch match = jump.match(l_decoded_message); + QRegularExpressionMatch match = isTestimonyJumpCommand(client.decodeMessage(l_args[4])); // Get rid of that pesky encoding, then do the fun part if (match.hasMatch()) { client.m_pos = "wit"; int jump_idx = match.captured("int").toInt(); @@ -443,6 +445,17 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const return PacketFactory::createPacket("MS", l_args); } +QRegularExpressionMatch PacketMS::isTestimonyJumpCommand(QString message) const +{ + // *sigh* slightly too chunky and needed slightly + // too often to justify not making this a helper + // even if it hurts my heart + // + // and my grey matter + QRegularExpression jump("(?>)(?[0,1,2,3,4,5,6,7,8,9]+)"); + return jump.match(message); +} + bool PacketMS::validatePacket() const { return true;