diff --git a/include/aoclient.h b/include/aoclient.h index be39612..df8d3e1 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -222,6 +222,12 @@ class AOClient : public QObject { {"SUPER", ~0ULL }, }; + + /** + * @brief A list of 5 casing preferences (def, pro, judge, jury, steno) + */ + QList casing_preferences = {false, false, false, false, false}; + /** * @brief If true, the client's in-character messages will have their word order randomised. */ @@ -493,6 +499,12 @@ class AOClient : public QObject { /// Implements [editing evidence](https://github.com/AttorneyOnline/docs/blob/master/docs/development/network.md#edit). void pktEditEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet); + /// Implements [updating casing preferences](https://github.com/AttorneyOnline/docs/blob/master/docs/development/network.md#case-preferences-update). + void pktSetCase(AreaData* area, int argc, QStringList argv, AOPacket packet); + + /// Implements [announcing a case](https://github.com/AttorneyOnline/docs/blob/master/docs/development/network.md#case-alert). + void pktAnnounceCase(AreaData* area, int argc, QStringList argv, AOPacket packet); + ///@} /** @@ -643,6 +655,8 @@ class AOClient : public QObject { {"PE", {ACLFlags.value("NONE"), 3, &AOClient::pktAddEvidence }}, {"DE", {ACLFlags.value("NONE"), 1, &AOClient::pktRemoveEvidence }}, {"EE", {ACLFlags.value("NONE"), 4, &AOClient::pktEditEvidence }}, + {"SETCASE", {ACLFlags.value("NONE"), 7, &AOClient::pktSetCase }}, + {"CASEA", {ACLFlags.value("NONE"), 6, &AOClient::pktAnnounceCase }}, }; /** diff --git a/src/aoclient.cpp b/src/aoclient.cpp index b425683..6e8dfbd 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -318,6 +318,7 @@ bool AOClient::checkAuth(unsigned long long acl_mask) return true; } + QString AOClient::getIpid() { return ipid; } Server* AOClient::getServer() { return server; } diff --git a/src/packets.cpp b/src/packets.cpp index 51b32c3..6ddce8a 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -344,6 +344,59 @@ void AOClient::pktEditEvidence(AreaData* area, int argc, QStringList argv, AOPac sendEvidenceList(area); } +void AOClient::pktSetCase(AreaData* area, int argc, QStringList argv, AOPacket packet) +{ + QList prefs_list; + for (int i = 2; i <=6; i++) { + bool is_int = false; + bool pref = argv[i].toInt(&is_int); + if (!is_int) + return; + prefs_list.append(pref); + } + casing_preferences = prefs_list; +} + +void AOClient::pktAnnounceCase(AreaData* area, int argc, QStringList argv, AOPacket packet) +{ + QString case_title = argv[0]; + QStringList needed_roles; + QList needs_list; + for (int i = 1; i <=5; i++) { + bool is_int = false; + bool need = argv[i].toInt(&is_int); + if (!is_int) + return; + needs_list.append(need); + } + QStringList roles = {"defense attorney", "prosecutor", "judge", "jurors", "stenographer"}; + for (int i = 0; i < 5; i++) { + if (needs_list[i]) + needed_roles.append(roles[i]); + } + if (needed_roles.isEmpty()) + return; + + QString message = "=== Case Announcement ===\r\n" + (ooc_name == "" ? current_char : ooc_name) + " needs " + needed_roles.join(", ") + " for " + (case_title == "" ? "a case" : case_title) + "!"; + + QList clients_to_alert; + // here lies morton, RIP + QSet needs_set = needs_list.toSet(); + for (AOClient* client : server->clients) { + QSet matches = client->casing_preferences.toSet().intersect(needs_set); + if (!matches.isEmpty() && !clients_to_alert.contains(client)) + clients_to_alert.append(client); + } + + for (AOClient* client : clients_to_alert) { + client->sendPacket(AOPacket("CASEA", {message, argv[1], argv[2], argv[3], argv[4], argv[5], "1"})); + // you may be thinking, "hey wait a minute the network protocol documentation doesn't mention that last argument!" + // if you are in fact thinking that, you are correct! it is not in the documentation! + // however for some inscrutable reason Attorney Online 2 will outright reject a CASEA packet that does not have + // at least 7 arguments despite only using the first 6. Cera, i kneel. you have truly broken me. + } +} + void AOClient::sendEvidenceList(AreaData* area) { for (AOClient* client : server->clients) { @@ -719,6 +772,4 @@ void AOClient::updateJudgeLog(AreaData* area, AOClient* client, QString action) area->judgelog.append(logmessage); } else area->judgelog.append(logmessage); - - } diff --git a/src/server.cpp b/src/server.cpp index 10dbd66..382e5a2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -53,9 +53,7 @@ void Server::start() loadServerConfig(); loadCommandConfig(); - - maximum_statements = config.value("maximum_statements", 50).toInt(); - + proxy = new WSProxy(port, ws_port, this); if(ws_port != -1) proxy->start(); @@ -235,6 +233,10 @@ void Server::loadServerConfig() zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success); if (!zalgo_tolerance_conversion_success) zalgo_tolerance = 3; + bool maximum_statements_conversion_success; + maximum_statements = config.value("maximum_statements", "10").toInt(&maximum_statements_conversion_success); + if (!maximum_statements_conversion_success) + maximum_statements = 10; bool afk_timeout_conversion_success; afk_timeout = config.value("afk_timeout", "300").toInt(&afk_timeout_conversion_success); if (!afk_timeout_conversion_success)