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] 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); + + +}