diff --git a/include/aoclient.h b/include/aoclient.h index 627eebe..ef72d08 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -251,6 +251,16 @@ class AOClient : public QObject { */ bool is_afk = false; + /** + * @brief If true, the client will not recieve PM messages. + */ + bool pm_mute = false; + + /** + * @brief If true, the client will recieve advertisements. + */ + bool advert_enabled = true; + /** * @brief Timer for tracking user interaction. Automatically restarted whenever a user interacts (i.e. sends any packet besides CH) */ @@ -1313,8 +1323,6 @@ class AOClient : public QObject { * * @details No arguments. * - * Can silently "fail" if the character picked is already being used by another client. - * * @iscommand */ void cmdRandomChar(int argc, QStringList argv); @@ -1454,6 +1462,20 @@ class AOClient : public QObject { */ void cmdUnShake(int argc, QStringList argv); + /** + * @brief Toggles whether a client will recieve @ref cmdPM private messages or not. + * + * @details No arguments. + */ + void cmdMutePM(int argc, QStringList argv); + + /** + * @brief Toggles whether a client will recieve @ref cmdNeed "advertisement" messages. + * + * @details No arguments. + */ + void cmdToggleAdverts(int argc, QStringList argv); + /** * @brief Toggles whether this client is considered AFK. * @@ -1897,6 +1919,8 @@ class AOClient : public QObject { {"savetestimony", {ACLFlags.value("NONE"), 1, &AOClient::cmdSaveTestimony}}, {"loadtestimony", {ACLFlags.value("CM"), 1, &AOClient::cmdLoadTestimony}}, {"permitsaving", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdPermitSaving}}, + {"mutepm", {ACLFlags.value("NONE"), 0, &AOClient::cmdMutePM}}, + {"toggleadverts", {ACLFlags.value("NONE"), 0, &AOClient::cmdToggleAdverts}}, {"oocmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdOocMute}}, {"ooc_mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdOocMute}}, {"oocunmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdOocUnMute}}, diff --git a/src/commands/messaging.cpp b/src/commands/messaging.cpp index e8517c2..24e8db5 100644 --- a/src/commands/messaging.cpp +++ b/src/commands/messaging.cpp @@ -77,23 +77,42 @@ void AOClient::cmdNeed(int argc, QStringList argv) { QString sender_area = server->area_names.value(current_area); QString sender_message = argv.join(" "); - sendServerBroadcast({"=== Advert ===\n[" + sender_area + "] needs " + sender_message+ "."}); + for (AOClient* client : server->clients) { + if (client->advert_enabled) { + client->sendServerMessage({"=== Advert ===\n[" + sender_area + "] needs " + sender_message+ "."}); + } + } } void AOClient::cmdSwitch(int argc, QStringList argv) { - int char_id = server->getCharID(argv.join(" ")); - if (char_id == -1) { + int selected_char_id = server->getCharID(argv.join(" ")); + if (selected_char_id == -1) { sendServerMessage("That does not look like a valid character."); return; } - changeCharacter(char_id); + if (changeCharacter(selected_char_id)) { + char_id = selected_char_id; + } + else { + sendServerMessage("The character you picked is either taken or invalid."); + } } void AOClient::cmdRandomChar(int argc, QStringList argv) { - int char_id = genRand(0, server->characters.size() - 1); - changeCharacter(char_id); + AreaData* area = server->areas[current_area]; + int selected_char_id; + bool taken = true; + while (taken) { + selected_char_id = genRand(0, server->characters.size() - 1); + if (!area->characters_taken.contains(selected_char_id)) { + taken = false; + } + } + if (changeCharacter(selected_char_id)) { + char_id = selected_char_id; + } } void AOClient::cmdToggleGlobal(int argc, QStringList argv) @@ -116,6 +135,10 @@ void AOClient::cmdPM(int arc, QStringList argv) sendServerMessage("No client with that ID found."); return; } + if (target_client->pm_mute) { + sendServerMessage("That user is not recieving PMs."); + return; + } QString message = argv.join(" "); //...which means it will not end up as part of the message target_client->sendServerMessage("Message from " + ooc_name + " (" + QString::number(id) + "): " + message); } @@ -275,6 +298,20 @@ void AOClient::cmdUnShake(int argc, QStringList argv) target->is_shaken = false; } +void AOClient::cmdMutePM(int argc, QStringList argv) +{ + pm_mute = !pm_mute; + QString str_en = pm_mute ? "muted" : "unmuted"; + sendServerMessage("PM's are now " + str_en); +} + +void AOClient::cmdToggleAdverts(int argc, QStringList argv) +{ + advert_enabled = !advert_enabled; + QString str_en = advert_enabled ? "on" : "off"; + sendServerMessage("Advertisements turned " + str_en); +} + void AOClient::cmdAfk(int argc, QStringList argv) { is_afk = true;