Skip to content

Commit

Permalink
Check for doubleposts per client, not per area (#338)
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
in1tiate authored Mar 8, 2024
1 parent 738ecf6 commit 5de07f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/include/packet/packet_ms.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class PacketMS : public AOPacket

private:
AOPacket *validateIcPacket(AOClient &client) const;
QRegularExpressionMatch isTestimonyJumpCommand(QString message) const;
};
#endif
25 changes: 19 additions & 6 deletions core/src/packet/packet_ms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_args[4]));
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.");
Expand Down Expand Up @@ -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("(?<arrow>>)(?<int>[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();
Expand Down Expand Up @@ -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("(?<arrow>>)(?<int>[0,1,2,3,4,5,6,7,8,9]+)");
return jump.match(message);
}

bool PacketMS::validatePacket() const
{
return true;
Expand Down

0 comments on commit 5de07f2

Please sign in to comment.