From d98eedd6e91c24ea157d183d7c105747454a5fee Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Tue, 6 Apr 2021 00:41:28 -0500 Subject: [PATCH 1/7] Add /judgelog command Adds a judgelog to each area and a helper function to update it. Adds /judgelog to retrieve it. --- include/aoclient.h | 5 +++++ include/area_data.h | 2 ++ src/area_data.cpp | 3 ++- src/commands.cpp | 11 +++++++++++ src/packets.cpp | 20 ++++++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/aoclient.h b/include/aoclient.h index 0c4d7cf..83756da 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1389,6 +1389,8 @@ class AOClient : public QObject { */ void cmd8Ball(int argc, QStringList argv); + void cmdJudgeLog(int argc, QStringList argv); + ///@} /** @@ -1582,6 +1584,7 @@ class AOClient : public QObject { {"notecard_clear", {ACLFlags.value("NONE"), 0, &AOClient::cmdNoteCardClear}}, {"8ball", {ACLFlags.value("NONE"), 1, &AOClient::cmd8Ball}}, {"lm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdLM}}, + {"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}} }; /** @@ -1629,6 +1632,8 @@ class AOClient : public QObject { * @details Used to determine if the incoming message is a duplicate. */ QString last_message; + + void updateJudgeLog(AreaData* area, AOClient* client, QString action); }; #endif // AOCLIENT_H diff --git a/include/area_data.h b/include/area_data.h index fca0248..b506b82 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -272,6 +272,8 @@ class AreaData : public QObject { */ EvidenceMod evi_mod; QMap notecards; + + QStringList judgelog; }; #endif // AREA_DATA_H diff --git a/src/area_data.cpp b/src/area_data.cpp index f30b36d..c2ee6b0 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -24,7 +24,8 @@ AreaData::AreaData(QString p_name, int p_index) : locked(FREE), document("No document."), def_hp(10), - pro_hp(10) + pro_hp(10), + judgelog() { QStringList name_split = p_name.split(":"); name_split.removeFirst(); diff --git a/src/commands.cpp b/src/commands.cpp index 91a492e..5c4b968 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1280,6 +1280,17 @@ void AOClient::cmd8Ball(int argc, QStringList argv) } +void AOClient::cmdJudgeLog(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + if (area->judgelog.isEmpty()) { + sendServerMessage("There have been no judge actions in this area."); + return; + } + QString message = area->judgelog.join("\n"); + sendServerMessage(message); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index 8f501d0..4136e45 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -260,6 +260,7 @@ void AOClient::pktWtCe(AreaData* area, int argc, QStringList argv, AOPacket pack return; last_wtce_time = QDateTime::currentDateTime().toSecsSinceEpoch(); server->broadcast(packet, current_area); + updateJudgeLog(area, this, "WT/CE"); } void AOClient::pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket packet) @@ -276,6 +277,7 @@ void AOClient::pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket pac } server->broadcast(AOPacket("HP", {"1", QString::number(area->def_hp)}), area->index); server->broadcast(AOPacket("HP", {"2", QString::number(area->pro_hp)}), area->index); + updateJudgeLog(area, this, "updated the penalties"); } void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPacket packet) @@ -638,3 +640,21 @@ bool AOClient::checkEvidenceAccess(AreaData *area) return false; } } + +void AOClient::updateJudgeLog(AreaData* area, AOClient* client, QString action) +{ + QString timestamp = QTime::currentTime().toString("hh:mm:ss"); + QString uid = QString::number(client->id); + QString char_name = client->current_char; + QString ipid = client->getIpid(); + QString message = action; + QString logmessage = QString("[%1]: [%2] %3 (%4) %5").arg(timestamp, uid, char_name, ipid, message); + int size = area->judgelog.size(); + if (size == 10) { + area->judgelog.removeFirst(); + area->judgelog.append(logmessage); + } + else area->judgelog.append(logmessage); + + +} From 0aa772ea8975a5de7136bdf2dc0be11c269f1e56 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Tue, 6 Apr 2021 13:49:08 -0500 Subject: [PATCH 2/7] Add documentation for the judgelog, updateJudgeLog(), and the /judgelog command. --- include/aoclient.h | 16 ++++++++++++++++ include/area_data.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/include/aoclient.h b/include/aoclient.h index 83756da..f7eb72d 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1389,6 +1389,13 @@ class AOClient : public QObject { */ void cmd8Ball(int argc, QStringList argv); + /** + * @brief Sends an out-of-character message with the judgelog of an area. + * + * @details No arguments. + * + * @iscommand + */ void cmdJudgeLog(int argc, QStringList argv); ///@} @@ -1633,6 +1640,15 @@ class AOClient : public QObject { */ QString last_message; + /** + * @brief A helper function to add recorded packets to an area's judgelog. + * + * @param area Pointer to the area where the packet was sent. + * + * @param client Pointer to the client that sent the packet. + * + * @param action String containing the info that is being recorded. + */ void updateJudgeLog(AreaData* area, AOClient* client, QString action); }; diff --git a/include/area_data.h b/include/area_data.h index b506b82..d36d743 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -273,6 +273,11 @@ class AreaData : public QObject { EvidenceMod evi_mod; QMap notecards; + /** + * @brief The judgelog of an area. + * + * @details This list contains up to 10 recorded packets of the most recent judge actions (WT/CE or penalty updates) in an area. + */ QStringList judgelog; }; From d73a7292fc47cdea8b4ded5319e38ea740304dfa Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Tue, 6 Apr 2021 13:50:06 -0500 Subject: [PATCH 3/7] Add a check to /judgelog to only send IPIDs to users with appropriate permissions --- src/commands.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/commands.cpp b/src/commands.cpp index 5c4b968..513118d 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1288,7 +1288,14 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv) return; } QString message = area->judgelog.join("\n"); - sendServerMessage(message); + //Judgelog contains an IPID, so we shouldn't send that unless the caller has appropriate permissions + if (((checkAuth(ACLFlags.value("KICK"))) == 1) || (((checkAuth(ACLFlags.value("BAN"))) == 1))) { + sendServerMessage(message); + } + else { + QString filteredmessage = message.remove(QRegularExpression("[(]*[)]")); //Filter out anything between two parentheses. This should only ever be the IPID + sendServerMessage(filteredmessage); + } } QStringList AOClient::buildAreaList(int area_idx) From 735f886d154e33d80bcca59512e3fdb75ad64e97 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:22:36 -0500 Subject: [PATCH 4/7] Fix filtering out IPIDs for CM users --- src/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands.cpp b/src/commands.cpp index 513118d..0702070 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1293,7 +1293,7 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv) sendServerMessage(message); } else { - QString filteredmessage = message.remove(QRegularExpression("[(]*[)]")); //Filter out anything between two parentheses. This should only ever be the IPID + QString filteredmessage = message.remove(QRegularExpression("[(].*[)]")); //Filter out anything between two parentheses. This should only ever be the IPID sendServerMessage(filteredmessage); } } From ea0df75a88d84f44687e31511372c7af62ae0961 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Wed, 7 Apr 2021 00:45:56 -0500 Subject: [PATCH 5/7] Merge branch 'master' into mod-commands --- bin/config_sample/areas.ini | 4 +++- include/aoclient.h | 13 ++++++++++++- include/area_data.h | 10 ++++++++++ src/area_data.cpp | 4 +++- src/commands.cpp | 13 +++++++++++++ src/packets.cpp | 16 ++++++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/bin/config_sample/areas.ini b/bin/config_sample/areas.ini index 5e687da..7dc04e7 100644 --- a/bin/config_sample/areas.ini +++ b/bin/config_sample/areas.ini @@ -3,9 +3,11 @@ background=gs4 protected_area=true iniswap_allowed=false evidence_mod=cm +blankposting_allowed=true [1:Courtroom 1] background=gs4 protected_area=false iniswap_allowed=true -evidence_mod=ffa \ No newline at end of file +evidence_mod=ffa +blankposting_allowed=true \ No newline at end of file diff --git a/include/aoclient.h b/include/aoclient.h index f7eb72d..423d2bb 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1134,6 +1134,16 @@ class AOClient : public QObject { */ void cmdBans(int argc, QStringList argv); + + /** + * @brief Toggle whether or not in-character messages purely consisting of spaces are allowed. + * + * @details Takes no arguments. Against all common sense this also allows you to disable blankposting. + * + * @iscommand + */ + void cmdAllow_Blankposting(int argc, QStringList argv); + ///@} /** @@ -1591,7 +1601,8 @@ class AOClient : public QObject { {"notecard_clear", {ACLFlags.value("NONE"), 0, &AOClient::cmdNoteCardClear}}, {"8ball", {ACLFlags.value("NONE"), 1, &AOClient::cmd8Ball}}, {"lm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdLM}}, - {"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}} + {"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}}, + {"allow_blankposting", {ACLFlags.value("MODCHAT"), 0, &AOClient::cmdAllow_Blankposting}}, }; /** diff --git a/include/area_data.h b/include/area_data.h index d36d743..45246a1 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -187,6 +187,11 @@ class AreaData : public QObject { */ bool iniswap_allowed; + /** + * @brief If true, clients are allowed to send empty IC messages + */ + bool blankposting_allowed; + /** * @brief If true, the background of the area cannot be changed except by a moderator. */ @@ -279,6 +284,11 @@ class AreaData : public QObject { * @details This list contains up to 10 recorded packets of the most recent judge actions (WT/CE or penalty updates) in an area. */ QStringList judgelog; + + /** + * @brief The last IC packet sent in an area. + */ + QStringList last_ic_message; }; #endif // AREA_DATA_H diff --git a/src/area_data.cpp b/src/area_data.cpp index c2ee6b0..6c2fad3 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -25,7 +25,8 @@ AreaData::AreaData(QString p_name, int p_index) : document("No document."), def_hp(10), pro_hp(10), - judgelog() + judgelog(), + last_ic_message() { QStringList name_split = p_name.split(":"); name_split.removeFirst(); @@ -37,6 +38,7 @@ AreaData::AreaData(QString p_name, int p_index) : iniswap_allowed = areas_ini.value("iniswap_allowed", "true").toBool(); bg_locked = areas_ini.value("bg_locked", "false").toBool(); QString configured_evi_mod = areas_ini.value("evidence_mod", "FFA").toString().toLower(); + blankposting_allowed = areas_ini.value("blankposting_allowed","true").toBool(); areas_ini.endGroup(); QSettings config_ini("config/config.ini", QSettings::IniFormat); config_ini.beginGroup("Options"); diff --git a/src/commands.cpp b/src/commands.cpp index 0702070..7bbd543 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1298,6 +1298,19 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv) } } +void AOClient::cmdAllow_Blankposting(int argc, QStringList argv) +{ + QString sender_name = ooc_name; + AreaData* area = server->areas[current_area]; + area->blankposting_allowed = !area->blankposting_allowed; + if (area->blankposting_allowed == false) { + sendServerMessageArea(sender_name + " has set blankposting in the area to forbidden."); + } + else { + sendServerMessageArea(sender_name + " has set blankposting in the area to allowed."); + } +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index 4136e45..b56914b 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -168,6 +168,8 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa area->logger->logIC(this, &validated_packet); server->broadcast(validated_packet, current_area); + area->last_ic_message.clear(); + area->last_ic_message.append(validated_packet.contents); } void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet) @@ -435,6 +437,11 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) if (incoming_msg == last_message) return invalid; + if (incoming_msg == "" && area->blankposting_allowed == false) { + sendServerMessage("Blankposting has been forbidden in this area."); + return invalid; + } + last_message = incoming_msg; args.append(incoming_msg); @@ -603,6 +610,15 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) int additive = incoming_args[24].toInt(); if (additive != 0 && additive != 1) return invalid; + else if (area->last_ic_message.isEmpty()){ + additive = 0; + } + else if (!(char_id == area->last_ic_message[8].toInt())) { + additive = 0; + } + else if (additive == 1) { + args[4].insert(0, " "); + } args.append(QString::number(additive)); // effect From 2d793f4a9985db01bbfd7d28756c683523efa4d1 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Wed, 7 Apr 2021 15:26:14 -0500 Subject: [PATCH 6/7] Add /baninfo command - Adds getBanInfo() to db_manager, which queries bans by banid, hdid, or ipid --- include/aoclient.h | 13 +++++++++++++ include/db_manager.h | 9 +++++++++ src/commands.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/db_manager.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) diff --git a/include/aoclient.h b/include/aoclient.h index 423d2bb..8601207 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1408,6 +1408,18 @@ class AOClient : public QObject { */ void cmdJudgeLog(int argc, QStringList argv); + /** + * @brief Looks up info on a ban. + * + * @details If it is called with **one argument**, that argument is the ban ID to look up. + * + * If it is called with **two arguments**, then the first argument is either a ban ID, an IPID, + * or an HDID, and the the second argument specifies the ID type. + * + * @iscommand + */ + void cmdBanInfo(int argc, QStringList argv); + ///@} /** @@ -1603,6 +1615,7 @@ class AOClient : public QObject { {"lm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdLM}}, {"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}}, {"allow_blankposting", {ACLFlags.value("MODCHAT"), 0, &AOClient::cmdAllow_Blankposting}}, + {"baninfo", {ACLFlags.value("BAN"), 1, &AOClient::cmdBanInfo}}, }; /** diff --git a/include/db_manager.h b/include/db_manager.h index 575df07..b696dfe 100644 --- a/include/db_manager.h +++ b/include/db_manager.h @@ -239,6 +239,15 @@ public: */ QStringList getUsers(); + /** + * @brief Gets information on a ban. + * + * @param lookup_type The type of ID to search + * + * @param id A Ban ID, IPID, or HDID to search for + */ + QList getBanInfo(QString lookup_type, QString id); + private: /** * @brief The name of the database connection driver. diff --git a/src/commands.cpp b/src/commands.cpp index 7bbd543..c336026 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1311,6 +1311,45 @@ void AOClient::cmdAllow_Blankposting(int argc, QStringList argv) } } +void AOClient::cmdBanInfo(int argc, QStringList argv) +{ + QStringList ban_info; + ban_info << ("Ban Info for " + argv[0]); + ban_info << "-----"; + QString lookup_type; + + if (argc == 1) { + lookup_type = "banid"; + } + else if (argc == 2) { + lookup_type = argv[1]; + if (!((lookup_type == "banid") || (lookup_type == "ipid") || (lookup_type == "hdid"))) { + sendServerMessage("Invalid ID type."); + return; + } + } + else { + sendServerMessage("Invalid command."); + return; + } + QString id = argv[0]; + for (DBManager::BanInfo ban : server->db_manager->getBanInfo(lookup_type, id)) { + QString banned_until; + if (ban.duration == -2) + banned_until = "The heat death of the universe"; + else + banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("dd.MM.yyyy, hh:mm"); + ban_info << "Affected IPID: " + ban.ipid; + ban_info << "Affected HDID: " + ban.hdid; + ban_info << "Reason for ban: " + ban.reason; + ban_info << "Date of ban: " + QDateTime::fromSecsSinceEpoch(ban.time).toString("dd.MM.yyyy, hh:mm"); + ban_info << "Ban lasts until: " + banned_until; + ban_info << "-----"; + } + sendServerMessage(ban_info.join("\n")); +} + + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/db_manager.cpp b/src/db_manager.cpp index 217ca25..2aeb12e 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -325,6 +325,47 @@ QStringList DBManager::getUsers() return users; } +QList DBManager::getBanInfo(QString lookup_type, QString id) +{ + QList return_list; + QSqlQuery query; + QList invalid; + if (lookup_type == "banid") { + query.prepare("SELECT * FROM BANS WHERE ID = ?"); + query.addBindValue(id); + query.setForwardOnly(true); + query.exec(); + } + else if (lookup_type == "hdid") { + query.prepare("SELECT * FROM BANS WHERE HDID = ?"); + query.addBindValue(id); + query.setForwardOnly(true); + query.exec(); + } + else if (lookup_type == "ipid") { + query.prepare("SELECT * FROM BANS WHERE IPID = ?"); + query.addBindValue(id); + query.setForwardOnly(true); + query.exec(); + } + else { + qCritical("Invalid ban lookup type!"); + return invalid; + } + while (query.next()) { + BanInfo ban; + ban.ipid = query.value(0).toString(); + ban.hdid = query.value(1).toString(); + ban.ip = QHostAddress(query.value(2).toString()); + ban.time = static_cast(query.value(3).toULongLong()); + ban.reason = query.value(4).toString(); + ban.duration = query.value(5).toLongLong(); + return_list.append(ban); + } + std::reverse(return_list.begin(), return_list.end()); + return return_list; +} + DBManager::~DBManager() { db.close(); From a2013aa32e6df18366096df80bd646131da84206 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sat, 10 Apr 2021 00:43:08 -0500 Subject: [PATCH 7/7] Cleanup getBanInfo and cmdJudgeLog - Removes unneeded parentheses from AOClient::cmdJudgeLog() - Removes duplicate code in DBManager::getBanInfo() --- src/commands.cpp | 2 +- src/db_manager.cpp | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 38bdd2c..0dbf7d8 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1289,7 +1289,7 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv) } QString message = area->judgelog.join("\n"); //Judgelog contains an IPID, so we shouldn't send that unless the caller has appropriate permissions - if (((checkAuth(ACLFlags.value("KICK"))) == 1) || (((checkAuth(ACLFlags.value("BAN"))) == 1))) { + if (checkAuth(ACLFlags.value("KICK")) == 1 || checkAuth(ACLFlags.value("BAN")) == 1) { sendServerMessage(message); } else { diff --git a/src/db_manager.cpp b/src/db_manager.cpp index 2aeb12e..861ec1a 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -332,26 +332,21 @@ QList DBManager::getBanInfo(QString lookup_type, QString id) QList invalid; if (lookup_type == "banid") { query.prepare("SELECT * FROM BANS WHERE ID = ?"); - query.addBindValue(id); - query.setForwardOnly(true); - query.exec(); } else if (lookup_type == "hdid") { query.prepare("SELECT * FROM BANS WHERE HDID = ?"); - query.addBindValue(id); - query.setForwardOnly(true); - query.exec(); } else if (lookup_type == "ipid") { query.prepare("SELECT * FROM BANS WHERE IPID = ?"); - query.addBindValue(id); - query.setForwardOnly(true); - query.exec(); } else { qCritical("Invalid ban lookup type!"); return invalid; } + query.addBindValue(id); + query.setForwardOnly(true); + query.exec(); + while (query.next()) { BanInfo ban; ban.ipid = query.value(0).toString();