diff --git a/include/aoclient.h b/include/aoclient.h index e198ed5..ffe0dce 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -272,7 +272,7 @@ class AOClient : public QObject { */ QTimer* afk_timer; - QStringList charcurse_list; + QList charcurse_list; /** * @brief Temporary client permission if client is allowed to save a testimony to server storage. diff --git a/include/server.h b/include/server.h index 0017621..caae0e3 100644 --- a/include/server.h +++ b/include/server.h @@ -259,6 +259,8 @@ class Server : public QObject { */ QStringList loadConfigFile(QString filename); + QStringList getCursedCharsTaken(AOClient* client, QStringList chars_taken); + /** * @brief List holding the contents of 8ball.txt, used by /8ball. */ diff --git a/src/aoclient.cpp b/src/aoclient.cpp index df0e26d..5ccfdf6 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -148,7 +148,7 @@ bool AOClient::changeCharacter(int char_id) if(char_id >= server->characters.length()) return false; - if (is_charcursed && !charcurse_list.contains(QString::number(char_id))) { + if (is_charcursed && !charcurse_list.contains(char_id)) { return false; } diff --git a/src/commands/messaging.cpp b/src/commands/messaging.cpp index 71c39d9..4e73ae2 100644 --- a/src/commands/messaging.cpp +++ b/src/commands/messaging.cpp @@ -335,7 +335,7 @@ void AOClient::cmdCharCurse(int argc, QStringList argv) } if (argc == 1) { - target->charcurse_list.append(QString::number(server->getCharID(current_char))); + target->charcurse_list.append(server->getCharID(current_char)); } else { @@ -343,23 +343,23 @@ void AOClient::cmdCharCurse(int argc, QStringList argv) QString names = argv.join(" "); argv = names.split(", "); QString char_name; + target->charcurse_list.clear(); foreach (char_name, argv) { - QString converted_char_id = QString::number(server->getCharID(char_name)); - argv.replaceInStrings(char_name, converted_char_id); + target->charcurse_list.append(server->getCharID(char_name)); } - if (argv.contains("-1")) { + if (target->charcurse_list.contains(-1)) { sendServerMessage("One of these characters was not found."); return; } - target->charcurse_list = argv; } //Kick back to char select screen - if (!target->charcurse_list.contains(QString::number(server->getCharID(current_char)))) { - target->current_char = ""; + if (!target->charcurse_list.contains(server->getCharID(current_char))) { + target->changeCharacter(-1); target->sendPacket("DONE"); } target->is_charcursed = true; + server->updateCharsTaken(server->areas.value(current_area)); target->sendServerMessage("You have been charcursed!"); sendServerMessage("Charcursed player."); } @@ -381,7 +381,8 @@ void AOClient::cmdUnCharCurse(int argc, QStringList argv) } target->is_charcursed = false; target->charcurse_list.clear(); - sendServerMessage("Uncharcursed plater."); + server->updateCharsTaken(server->areas.value(current_area)); + sendServerMessage("Uncharcursed player."); target->sendServerMessage("You were uncharcursed."); } diff --git a/src/server.cpp b/src/server.cpp index 382e5a2..e0c5825 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -151,7 +151,30 @@ void Server::updateCharsTaken(AreaData* area) } AOPacket response_cc("CharsCheck", chars_taken); - broadcast(response_cc, area->index); + + for (AOClient* client : clients) { + if (client->current_area == area->index){ + if (!client->is_charcursed) + client->sendPacket(response_cc); + else { + QStringList chars_taken_cursed = getCursedCharsTaken(client, chars_taken); + AOPacket response_cc_cursed("CharsCheck", chars_taken_cursed); + client->sendPacket(response_cc_cursed); + } + } + } +} + +QStringList Server::getCursedCharsTaken(AOClient* client, QStringList chars_taken) +{ + QStringList chars_taken_cursed; + for (int i = 0; i < chars_taken.length(); i++) { + if (!client->charcurse_list.contains(i)) + chars_taken_cursed.append("-1"); + else + chars_taken_cursed.append(chars_taken.value(i)); + } + return chars_taken_cursed; } void Server::broadcast(AOPacket packet, int area_index)