From e53fd2a02ec1ad71a72367d75e384fe1238a367e Mon Sep 17 00:00:00 2001 From: scatterflower Date: Tue, 6 Oct 2020 13:00:39 -0500 Subject: [PATCH] add evidence --- include/aoclient.h | 10 ++++++-- include/area_data.h | 7 ++++++ src/aoclient.cpp | 2 +- src/packets.cpp | 61 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index fa61788..bb71986 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -105,12 +105,15 @@ class AOClient : public QObject { void pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket packet); void pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPacket packet); void pktModCall(AreaData* area, int argc, QStringList argv, AOPacket packet); + void pktAddEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet); + void pktRemoveEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet); + void pktEditEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet); // Packet helper functions + void sendEvidenceList(AreaData* area); AOPacket validateIcPacket(AOPacket packet); // Packet helper global variables - bool last_msg_blankpost = false; int char_id = -1; int pairing_with = -1; QString emote = ""; @@ -139,7 +142,10 @@ class AOClient : public QObject { {"RT", {ACLFlags.value("NONE"), 1, &AOClient::pktWtCe}}, {"HP", {ACLFlags.value("NONE"), 2, &AOClient::pktHpBar}}, {"WSIP", {ACLFlags.value("NONE"), 1, &AOClient::pktWebSocketIp}}, - {"ZZ", {ACLFlags.value("NONE"), 0, &AOClient::pktModCall}} + {"ZZ", {ACLFlags.value("NONE"), 0, &AOClient::pktModCall}}, + {"PE", {ACLFlags.value("NONE"), 3, &AOClient::pktAddEvidence}}, + {"DE", {ACLFlags.value("NONE"), 1, &AOClient::pktRemoveEvidence}}, + {"EE", {ACLFlags.value("NONE"), 4, &AOClient::pktEditEvidence}} }; // Commands diff --git a/include/area_data.h b/include/area_data.h index df71983..175b595 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -30,9 +30,16 @@ class AreaData { public: AreaData(QStringList p_characters, QString p_name, int p_index); + struct Evidence { + QString name; + QString description; + QString image; + }; + QString name; int index; QMap characters_taken; + QList evidence; int player_count; QString status; QString current_cm; diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 5d2f87d..d9f9bf3 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -107,7 +107,7 @@ void AOClient::changeArea(int new_area) server->areas[current_area]->player_count--; current_area = new_area; arup(ARUPType::PLAYER_COUNT, true); - // send le + sendEvidenceList(server->areas[new_area]); sendPacket("HP", {"1", QString::number(server->areas[new_area]->def_hp)}); sendPacket("HP", {"2", QString::number(server->areas[new_area]->pro_hp)}); sendPacket("BN", {server->areas[new_area]->background}); diff --git a/src/packets.cpp b/src/packets.cpp index 867c96e..0304902 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -91,6 +91,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack server->updateCharsTaken(area); fullArup(); // Give client all the area data arup(ARUPType::PLAYER_COUNT, true); // Tell everyone there is a new player + sendEvidenceList(area); sendPacket("HP", {"1", QString::number(area->def_hp)}); sendPacket("HP", {"2", QString::number(area->pro_hp)}); @@ -236,7 +237,7 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack } } -void AOClient::pktModCall(AreaData *area, int argc, QStringList argv, AOPacket packet) +void AOClient::pktModCall(AreaData* area, int argc, QStringList argv, AOPacket packet) { for (AOClient* client : server->clients) { if (client->authenticated) @@ -245,6 +246,49 @@ void AOClient::pktModCall(AreaData *area, int argc, QStringList argv, AOPacket p area->logger->flush(); } +void AOClient::pktAddEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet) +{ + AreaData::Evidence evi = {argv[0], argv[1], argv[2]}; + area->evidence.append(evi); + sendEvidenceList(area); +} + +void AOClient::pktRemoveEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet) +{ + bool is_int = false; + int idx = argv[0].toInt(&is_int); + if (is_int) { + area->evidence.removeAt(idx); + } + sendEvidenceList(area); +} + +void AOClient::pktEditEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet) +{ + bool is_int = false; + int idx = argv[0].toInt(&is_int); + AreaData::Evidence evi = {argv[1], argv[2], argv[3]}; + if (is_int) { + area->evidence.replace(idx, evi); + } + sendEvidenceList(area); +} + +void AOClient::sendEvidenceList(AreaData* area) +{ + QStringList evidence_list; + QString evidence_format("%1&%2&%3"); + + for (AreaData::Evidence evidence : area->evidence) { + evidence_list.append(evidence_format + .arg(evidence.name) + .arg(evidence.description) + .arg(evidence.image)); + } + + server->broadcast(AOPacket("LE", evidence_list), current_area); +} + AOPacket AOClient::validateIcPacket(AOPacket packet) { // Welcome to the super cursed server-side IC chat validation hell @@ -296,14 +340,6 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) // message text QString incoming_msg = incoming_args[4].toString().trimmed(); - if (incoming_msg == "") { - if (last_msg_blankpost) - return invalid; - last_msg_blankpost = true; - } - else - last_msg_blankpost = false; - if (incoming_msg == last_message) return invalid; @@ -354,8 +390,11 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) } // evidence - // TODO: add to this once evidence is implemented - args.append(incoming_args[11].toString()); + int evi_idx = incoming_args[11].toInt(); + AreaData* area = server->areas[current_area]; + if (evi_idx > area->evidence.length()) + return invalid; + args.append(QString::number(evi_idx)); // flipping int flip = incoming_args[12].toInt();