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 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 a621ae6113334954b1aeb4a6d50cca5db9b36fd8 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Fri, 9 Apr 2021 03:05:15 -0500 Subject: [PATCH 07/12] alter antispam to function more like tsu3 --- include/aoclient.h | 2 +- src/packets.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index e99d417..95e9b77 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -53,7 +53,7 @@ class AOClient : public QObject { AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0) : QObject(parent), id(user_id), remote_ip(p_socket->peerAddress()), password(""), joined(false), current_area(0), current_char(""), socket(p_socket), server(p_server), - is_partial(false), last_wtce_time(0), last_message("") {}; + is_partial(false), last_wtce_time(0) {}; /** * @brief Destructor for the AOClient instance. diff --git a/src/packets.cpp b/src/packets.cpp index dd4d225..03c858d 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -433,15 +433,15 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) // message text QString incoming_msg = dezalgo(incoming_args[4].toString().trimmed()); - if (incoming_msg == last_message) + if (!area->last_ic_message.isEmpty() + && incoming_msg == area->last_ic_message[4] + && incoming_msg != "") 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); // side From 2a2171dc42863a24c3e518bdb6625b1dfc795019 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Fri, 9 Apr 2021 15:32:17 -0500 Subject: [PATCH 08/12] clean up timer command, fix crash --- include/aoclient.h | 4 ++-- src/commands.cpp | 49 ++++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index e99d417..f0a580d 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1414,12 +1414,12 @@ class AOClient : public QObject { * @brief Returns a textual representation of the time left in an area's Timer. * * @param area_idx The ID of the area whose timer to grab. - * @param timer The pointer to the area's timer. + * @param timer_idx The ID of the timer to grab * * @return A textual representation of the time left over on the Timer, * or `"Timer is inactive"` if the timer wasn't started. */ - QString getAreaTimer(int area_idx, QTimer* timer); + QString getAreaTimer(int area_idx, int timer_idx); /** * @brief Generates a tsuserver3-style area list to be displayed to the user in the out-of-character chat. diff --git a/src/commands.cpp b/src/commands.cpp index 0947746..35a75b2 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -664,20 +664,19 @@ void AOClient::cmdTimer(int argc, QStringList argv) { AreaData* area = server->areas[current_area]; + // Called without arguments + // Shows a brief of all timers if (argc == 0) { QStringList timers; timers.append("Currently active timers:"); - QTimer* global_timer = server->timer; - if (global_timer->isActive()) { - QTime current_time = QTime(0,0).addMSecs(global_timer->remainingTime()); - timers.append("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); - } - for (QTimer* timer : area->timers) { - timers.append(getAreaTimer(area->index, timer)); + for (int i = 0; i <= 4; i++) { + timers.append(getAreaTimer(area->index, i)); } sendServerMessage(timers.join("\n")); return; } + + // Called with more than one argument bool ok; int timer_id = argv[0].toInt(&ok); if (!ok || timer_id < 0 || timer_id > 4) { @@ -685,22 +684,15 @@ void AOClient::cmdTimer(int argc, QStringList argv) return; } + // Called with one argument + // Shows the status of one timer if (argc == 1) { - if (timer_id == 0) { - QTimer* global_timer = server->timer; - if (global_timer->isActive()) { - QTime current_time = QTime(0, 0, 0, global_timer->remainingTime()); - sendServerMessage("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); - return; - } - } - else { - QTimer* timer = area->timers[timer_id - 1]; - sendServerMessage(getAreaTimer(area->index, timer)); - return; - } + sendServerMessage(getAreaTimer(area->index, timer_id)); + return; } + // Called with more than one argument + // Updates the state of a timer QTimer* requested_timer; if (timer_id == 0) { if (!checkAuth(ACLFlags.value("GLOBAL_TIMER"))) { @@ -1397,15 +1389,26 @@ void AOClient::diceThrower(int argc, QStringList argv, RollType type) } } -QString AOClient::getAreaTimer(int area_idx, QTimer* timer) +QString AOClient::getAreaTimer(int area_idx, int timer_idx) { AreaData* area = server->areas[area_idx]; + QTimer* timer; + QString timer_name = (timer_idx == 0) ? "Global timer" : "Timer " + QString::number(timer_idx); + + if (timer_idx == 0) + timer = server->timer; + else if (timer_idx > 0 && timer_idx <= 4) + timer = area->timers[timer_idx - 1]; + else + return "Invalid timer ID."; + if (timer->isActive()) { QTime current_time = QTime(0,0).addMSecs(timer->remainingTime()); - return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is at " + current_time.toString("hh:mm:ss.zzz"); + + return timer_name + " is at " + current_time.toString("hh:mm:ss.zzz"); } else { - return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is inactive."; + return timer_name + " is inactive."; } } From 8a5be8bc2c67d41fba3d74263aa1a69b03080fd2 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Fri, 9 Apr 2021 22:51:00 -0500 Subject: [PATCH 09/12] fix timer --- src/commands.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 35a75b2..9aaff9f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -693,6 +693,9 @@ void AOClient::cmdTimer(int argc, QStringList argv) // Called with more than one argument // Updates the state of a timer + + // Select the proper timer + // Check against permissions if global timer is selected QTimer* requested_timer; if (timer_id == 0) { if (!checkAuth(ACLFlags.value("GLOBAL_TIMER"))) { @@ -703,33 +706,45 @@ void AOClient::cmdTimer(int argc, QStringList argv) } else requested_timer = area->timers[timer_id - 1]; + + AOPacket show_timer("TI", {QString::number(timer_id), "2"}); + AOPacket hide_timer("TI", {QString::number(timer_id), "3"}); + bool is_global = timer_id == 0; + + // Set the timer's time remaining if the second + // argument is a valid time QTime requested_time = QTime::fromString(argv[1], "hh:mm:ss"); if (requested_time.isValid()) { requested_timer->setInterval(QTime(0,0).msecsTo(requested_time)); requested_timer->start(); sendServerMessage("Set timer " + QString::number(timer_id) + " to " + argv[1] + "."); - sendPacket("TI", {QString::number(timer_id), "2"}); // Show the timer - sendPacket("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(requested_time))}); + AOPacket update_timer("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(requested_time))}); + is_global ? server->broadcast(show_timer) : server->broadcast(show_timer, current_area); // Show the timer + is_global ? server->broadcast(update_timer) : server->broadcast(update_timer, current_area); return; } + // Otherwise, update the state of the timer else { if (argv[1] == "start") { requested_timer->start(); sendServerMessage("Started timer " + QString::number(timer_id) + "."); - sendPacket("TI", {QString::number(timer_id), "2"}); // Show the timer - sendPacket("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->remainingTime())))}); + AOPacket update_timer("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->remainingTime())))}); + is_global ? server->broadcast(show_timer) : server->broadcast(show_timer, current_area); + is_global ? server->broadcast(update_timer) : server->broadcast(update_timer, current_area); } else if (argv[1] == "pause" || argv[1] == "stop") { requested_timer->setInterval(requested_timer->remainingTime()); requested_timer->stop(); sendServerMessage("Stopped timer " + QString::number(timer_id) + "."); - sendPacket("TI", {QString::number(timer_id), "1", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->interval())))}); + AOPacket update_timer("TI", {QString::number(timer_id), "1", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->interval())))}); + is_global ? server->broadcast(update_timer) : server->broadcast(update_timer, current_area); } else if (argv[1] == "hide" || argv[1] == "unset") { requested_timer->setInterval(0); requested_timer->stop(); sendServerMessage("Hid timer " + QString::number(timer_id) + "."); - sendPacket("TI", {QString::number(timer_id), "3"}); // Hide the timer + // Hide the timer + is_global ? server->broadcast(hide_timer) : server->broadcast(hide_timer, current_area); } } } From 08a8e63d86d58f5c2dd74123702e904d7ec5ea95 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sat, 10 Apr 2021 00:42:06 -0500 Subject: [PATCH 10/12] fix stupid crash --- src/packets.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/packets.cpp b/src/packets.cpp index 03c858d..b5e944a 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -185,6 +185,8 @@ void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket p return; QString message = dezalgo(argv[1]); + if (message.length() == 0) + return; AOPacket final_packet("CT", {ooc_name, message, "0"}); if(message.at(0) == '/') { QStringList cmd_argv = message.split(" ", QString::SplitBehavior::SkipEmptyParts); 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 11/12] 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(); From 4de962b18def0f61007d7cc8dd40fd933c4f0548 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sat, 10 Apr 2021 01:14:26 -0500 Subject: [PATCH 12/12] return to perfect formatting --- include/aoclient.h | 142 ++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 05ec8c6..b435bbc 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1544,78 +1544,78 @@ class AOClient : public QObject { * See @ref CommandInfo "the type's documentation" for more details. */ const QMap commands { - {"login", {ACLFlags.value("NONE"), 1, &AOClient::cmdLogin}}, - {"getareas", {ACLFlags.value("NONE"), 0, &AOClient::cmdGetAreas}}, - {"getarea", {ACLFlags.value("NONE"), 0, &AOClient::cmdGetArea}}, - {"ban", {ACLFlags.value("BAN"), 2, &AOClient::cmdBan}}, - {"kick", {ACLFlags.value("KICK"), 2, &AOClient::cmdKick}}, - {"changeauth", {ACLFlags.value("SUPER"), 0, &AOClient::cmdChangeAuth}}, - {"rootpass", {ACLFlags.value("SUPER"), 1, &AOClient::cmdSetRootPass}}, - {"background", {ACLFlags.value("NONE"), 1, &AOClient::cmdSetBackground}}, - {"bg", {ACLFlags.value("NONE"), 1, &AOClient::cmdSetBackground}}, - {"bglock", {ACLFlags.value("BGLOCK"), 0, &AOClient::cmdBgLock}}, - {"bgunlock", {ACLFlags.value("BGLOCK"), 0, &AOClient::cmdBgUnlock}}, - {"adduser", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdAddUser}}, - {"listperms", {ACLFlags.value("NONE"), 0, &AOClient::cmdListPerms}}, - {"addperm", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdAddPerms}}, - {"removeperm", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdRemovePerms}}, - {"listusers", {ACLFlags.value("MODIFY_USERS"), 0, &AOClient::cmdListUsers}}, - {"logout", {ACLFlags.value("NONE"), 0, &AOClient::cmdLogout}}, - {"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}}, - {"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}}, - {"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}}, - {"coinflip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}}, - {"roll", {ACLFlags.value("NONE"), 0, &AOClient::cmdRoll}}, - {"rollp", {ACLFlags.value("NONE"), 0, &AOClient::cmdRollP}}, - {"doc", {ACLFlags.value("NONE"), 0, &AOClient::cmdDoc}}, - {"cleardoc", {ACLFlags.value("NONE"), 0, &AOClient::cmdClearDoc}}, - {"cm", {ACLFlags.value("NONE"), 0, &AOClient::cmdCM}}, - {"uncm", {ACLFlags.value("CM"), 0, &AOClient::cmdUnCM}}, - {"invite", {ACLFlags.value("CM"), 1, &AOClient::cmdInvite}}, - {"uninvite", {ACLFlags.value("CM"), 1, &AOClient::cmdUnInvite}}, - {"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}}, - {"area_lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}}, - {"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}}, - {"area_spectate", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}}, - {"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, - {"area_unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, - {"timer", {ACLFlags.value("CM"), 0, &AOClient::cmdTimer}}, - {"area", {ACLFlags.value("NONE"), 1, &AOClient::cmdArea}}, - {"play", {ACLFlags.value("CM"), 1, &AOClient::cmdPlay}}, - {"areakick", {ACLFlags.value("CM"), 1, &AOClient::cmdAreaKick}}, - {"area_kick", {ACLFlags.value("CM"), 1, &AOClient::cmdAreaKick}}, - {"randomchar", {ACLFlags.value("NONE"), 0, &AOClient::cmdRandomChar}}, - {"switch", {ACLFlags.value("NONE"), 1, &AOClient::cmdSwitch}}, - {"toggleglobal", {ACLFlags.value("NONE"), 0, &AOClient::cmdToggleGlobal}}, - {"mods", {ACLFlags.value("NONE"), 0, &AOClient::cmdMods}}, - {"help", {ACLFlags.value("NONE"), 0, &AOClient::cmdHelp}}, - {"status", {ACLFlags.value("NONE"), 1, &AOClient::cmdStatus}}, - {"forcepos", {ACLFlags.value("CM"), 2, &AOClient::cmdForcePos}}, - {"currentmusic", {ACLFlags.value("NONE"), 0, &AOClient::cmdCurrentMusic}}, - {"pm", {ACLFlags.value("NONE"), 2, &AOClient::cmdPM}}, - {"evidence_mod", {ACLFlags.value("EVI_MOD"), 1, &AOClient::cmdEvidenceMod}}, - {"motd", {ACLFlags.value("NONE"), 0, &AOClient::cmdMOTD}}, - {"announce", {ACLFlags.value("ANNOUNCE"), 1, &AOClient::cmdAnnounce}}, - {"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}}, - {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}}, - {"mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdMute}}, - {"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnMute}}, - {"bans", {ACLFlags.value("BAN"), 0, &AOClient::cmdBans}}, - {"unban", {ACLFlags.value("BAN"), 1, &AOClient::cmdUnBan}}, - {"removeuser", {ACLFlags.value("MODIFY_USERS"), 1, &AOClient::cmdRemoveUser}}, - {"subtheme", {ACLFlags.value("CM"), 1, &AOClient::cmdSubTheme}}, - {"about", {ACLFlags.value("NONE"), 0, &AOClient::cmdAbout}}, - {"evidence_swap", {ACLFlags.value("CM"), 2, &AOClient::cmdEvidence_Swap}}, - {"notecard", {ACLFlags.value("NONE"), 1, &AOClient::cmdNoteCard}}, - {"notecardreveal", {ACLFlags.value("CM"), 0, &AOClient::cmdNoteCardReveal}}, - {"notecard_reveal", {ACLFlags.value("CM"), 0, &AOClient::cmdNoteCardReveal}}, - {"notecardclear", {ACLFlags.value("NONE"), 0, &AOClient::cmdNoteCardClear}}, - {"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}}, + {"login", {ACLFlags.value("NONE"), 1, &AOClient::cmdLogin}}, + {"getareas", {ACLFlags.value("NONE"), 0, &AOClient::cmdGetAreas}}, + {"getarea", {ACLFlags.value("NONE"), 0, &AOClient::cmdGetArea}}, + {"ban", {ACLFlags.value("BAN"), 2, &AOClient::cmdBan}}, + {"kick", {ACLFlags.value("KICK"), 2, &AOClient::cmdKick}}, + {"changeauth", {ACLFlags.value("SUPER"), 0, &AOClient::cmdChangeAuth}}, + {"rootpass", {ACLFlags.value("SUPER"), 1, &AOClient::cmdSetRootPass}}, + {"background", {ACLFlags.value("NONE"), 1, &AOClient::cmdSetBackground}}, + {"bg", {ACLFlags.value("NONE"), 1, &AOClient::cmdSetBackground}}, + {"bglock", {ACLFlags.value("BGLOCK"), 0, &AOClient::cmdBgLock}}, + {"bgunlock", {ACLFlags.value("BGLOCK"), 0, &AOClient::cmdBgUnlock}}, + {"adduser", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdAddUser}}, + {"listperms", {ACLFlags.value("NONE"), 0, &AOClient::cmdListPerms}}, + {"addperm", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdAddPerms}}, + {"removeperm", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdRemovePerms}}, + {"listusers", {ACLFlags.value("MODIFY_USERS"), 0, &AOClient::cmdListUsers}}, + {"logout", {ACLFlags.value("NONE"), 0, &AOClient::cmdLogout}}, + {"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}}, + {"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}}, + {"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}}, + {"coinflip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}}, + {"roll", {ACLFlags.value("NONE"), 0, &AOClient::cmdRoll}}, + {"rollp", {ACLFlags.value("NONE"), 0, &AOClient::cmdRollP}}, + {"doc", {ACLFlags.value("NONE"), 0, &AOClient::cmdDoc}}, + {"cleardoc", {ACLFlags.value("NONE"), 0, &AOClient::cmdClearDoc}}, + {"cm", {ACLFlags.value("NONE"), 0, &AOClient::cmdCM}}, + {"uncm", {ACLFlags.value("CM"), 0, &AOClient::cmdUnCM}}, + {"invite", {ACLFlags.value("CM"), 1, &AOClient::cmdInvite}}, + {"uninvite", {ACLFlags.value("CM"), 1, &AOClient::cmdUnInvite}}, + {"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}}, + {"area_lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}}, + {"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}}, + {"area_spectate", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}}, + {"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, + {"area_unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, + {"timer", {ACLFlags.value("CM"), 0, &AOClient::cmdTimer}}, + {"area", {ACLFlags.value("NONE"), 1, &AOClient::cmdArea}}, + {"play", {ACLFlags.value("CM"), 1, &AOClient::cmdPlay}}, + {"areakick", {ACLFlags.value("CM"), 1, &AOClient::cmdAreaKick}}, + {"area_kick", {ACLFlags.value("CM"), 1, &AOClient::cmdAreaKick}}, + {"randomchar", {ACLFlags.value("NONE"), 0, &AOClient::cmdRandomChar}}, + {"switch", {ACLFlags.value("NONE"), 1, &AOClient::cmdSwitch}}, + {"toggleglobal", {ACLFlags.value("NONE"), 0, &AOClient::cmdToggleGlobal}}, + {"mods", {ACLFlags.value("NONE"), 0, &AOClient::cmdMods}}, + {"help", {ACLFlags.value("NONE"), 0, &AOClient::cmdHelp}}, + {"status", {ACLFlags.value("NONE"), 1, &AOClient::cmdStatus}}, + {"forcepos", {ACLFlags.value("CM"), 2, &AOClient::cmdForcePos}}, + {"currentmusic", {ACLFlags.value("NONE"), 0, &AOClient::cmdCurrentMusic}}, + {"pm", {ACLFlags.value("NONE"), 2, &AOClient::cmdPM}}, + {"evidence_mod", {ACLFlags.value("EVI_MOD"), 1, &AOClient::cmdEvidenceMod}}, + {"motd", {ACLFlags.value("NONE"), 0, &AOClient::cmdMOTD}}, + {"announce", {ACLFlags.value("ANNOUNCE"), 1, &AOClient::cmdAnnounce}}, + {"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}}, + {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}}, + {"mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdMute}}, + {"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnMute}}, + {"bans", {ACLFlags.value("BAN"), 0, &AOClient::cmdBans}}, + {"unban", {ACLFlags.value("BAN"), 1, &AOClient::cmdUnBan}}, + {"removeuser", {ACLFlags.value("MODIFY_USERS"), 1, &AOClient::cmdRemoveUser}}, + {"subtheme", {ACLFlags.value("CM"), 1, &AOClient::cmdSubTheme}}, + {"about", {ACLFlags.value("NONE"), 0, &AOClient::cmdAbout}}, + {"evidence_swap", {ACLFlags.value("CM"), 2, &AOClient::cmdEvidence_Swap}}, + {"notecard", {ACLFlags.value("NONE"), 1, &AOClient::cmdNoteCard}}, + {"notecardreveal", {ACLFlags.value("CM"), 0, &AOClient::cmdNoteCardReveal}}, + {"notecard_reveal", {ACLFlags.value("CM"), 0, &AOClient::cmdNoteCardReveal}}, + {"notecardclear", {ACLFlags.value("NONE"), 0, &AOClient::cmdNoteCardClear}}, + {"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}}, {"allow_blankposting", {ACLFlags.value("MODCHAT"), 0, &AOClient::cmdAllow_Blankposting}}, - {"baninfo", {ACLFlags.value("BAN"), 1, &AOClient::cmdBanInfo}}, + {"baninfo", {ACLFlags.value("BAN"), 1, &AOClient::cmdBanInfo}}, }; /**