From cf1e1cfc959293444fd29fc54905addcc9bccbd7 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sun, 18 Apr 2021 20:21:17 -0500 Subject: [PATCH] Add /togglemusic - Adds /togglemusic to toggle whether music can be played in an area. CM's can still play music. - Add toggle_music option to area.ini to set the default value in an area. Default value is set to true. - Also fixes a missing period in the documentation for force_immediate. Because I noticed it. --- include/aoclient.h | 10 +++++++++- include/area_data.h | 7 ++++++- src/area_data.cpp | 1 + src/commands/music.cpp | 8 ++++++++ src/packets.cpp | 4 ++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 5156055..9efa57b 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1665,6 +1665,13 @@ class AOClient : public QObject { */ void cmdCurrentMusic(int argc, QStringList argv); + /** + * @brief Toggles music playing in the current area. + * + * @details No arguments. + */ + void cmdToggleMusic(int argc, QStringList argv); + ///@} /** @@ -1936,7 +1943,8 @@ class AOClient : public QObject { {"block_dj", {ACLFlags.value("MUTE"), 1, &AOClient::cmdBlockDj}}, {"unblockdj", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnBlockDj}}, {"unblock_dj", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnBlockDj}}, - {"charselect", {ACLFlags.value("NONE"), 0, &AOClient::cmdCharSelect}} + {"charselect", {ACLFlags.value("NONE"), 0, &AOClient::cmdCharSelect}}, + {"togglemusic", {ACLFlags.value("CM"), 0, &AOClient::cmdToggleMusic}}, }; /** diff --git a/include/area_data.h b/include/area_data.h index 23df38f..8b17e2a 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -346,9 +346,14 @@ class AreaData : public QObject { QString log_type; /** - * @brief Whether or not to force immediate text processing in this area + * @brief Whether or not to force immediate text processing in this area. */ bool force_immediate; + + /** + * @brief Whether or not music is allowed in this area. If false, only CMs can change the music. + */ + bool toggle_music; }; #endif // AREA_DATA_H diff --git a/src/area_data.cpp b/src/area_data.cpp index 0653597..8289dc3 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -40,6 +40,7 @@ AreaData::AreaData(QString p_name, int p_index) : QString configured_evi_mod = areas_ini.value("evidence_mod", "FFA").toString().toLower(); blankposting_allowed = areas_ini.value("blankposting_allowed","true").toBool(); force_immediate = areas_ini.value("force_immediate", "false").toBool(); + toggle_music = areas_ini.value("toggle_music", "true").toBool(); areas_ini.endGroup(); QSettings config_ini("config/config.ini", QSettings::IniFormat); config_ini.beginGroup("Options"); diff --git a/src/commands/music.cpp b/src/commands/music.cpp index 2ae0f71..5500b78 100644 --- a/src/commands/music.cpp +++ b/src/commands/music.cpp @@ -82,3 +82,11 @@ void AOClient::cmdUnBlockDj(int argc, QStringList argv) } target->is_dj_blocked = false; } + +void AOClient::cmdToggleMusic(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + area->toggle_music = !area->toggle_music; + QString state = area->toggle_music ? "allowed." : "disallowed."; + sendServerMessage("Music in this area is now " + state); +} diff --git a/src/packets.cpp b/src/packets.cpp index 5ffede7..c2cea8a 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -225,6 +225,10 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack sendServerMessage("You are blocked from changing the music."); return; } + if (!area->toggle_music && !checkAuth(ACLFlags.value("CM"))) { + sendServerMessage("Music is disabled in this area."); + return; + } QString effects; if (argc >= 4) effects = argv[3];