Add support for background ambience (#353)
* add support for background ambience * add sample ambience config file * Send ambience BEFORE music when possible
This commit is contained in:
		
							parent
							
								
									7e9227f70a
								
							
						
					
					
						commit
						67eb25a988
					
				
							
								
								
									
										2
									
								
								bin/config_sample/ambience.ini
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								bin/config_sample/ambience.ini
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| [CourtGreatWitchVS] | ||||
| ambience = ambient/greatwitchtrial.opus | ||||
| @ -86,4 +86,7 @@ aliases = toggleshouts | ||||
| aliases = kickother | ||||
| 
 | ||||
| [jukebox_skip] | ||||
| aliases = jukeboxskip | ||||
| aliases = jukeboxskip | ||||
| 
 | ||||
| [play_ambience] | ||||
| aliases = playambience playa | ||||
| @ -872,5 +872,12 @@ | ||||
|       ], | ||||
|       "usage":"/jukebox_skip", | ||||
|       "text":"Skips the current song in the Jukebox and plays the next available one." | ||||
|    }, | ||||
|    { | ||||
|       "names": [ | ||||
|          "play_ambience" | ||||
|       ], | ||||
|       "usage":"/play_ambience", | ||||
|       "text":"Plays the requested track in the ambience channel." | ||||
|    } | ||||
| ] | ||||
|  | ||||
| @ -1843,6 +1843,19 @@ class AOClient : public QObject | ||||
|      */ | ||||
|     void cmdPlay(int argc, QStringList argv); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Plays ambience in the area. | ||||
|      * | ||||
|      * @details The arguments are **the song's filepath** originating from `base/sounds/music/`, | ||||
|      * or **the song's URL** if it's a stream. | ||||
|      * | ||||
|      * As described above, this command can be used to play ambience by URL (for clients at and above version 2.9), | ||||
|      * but it can also be used to play ambience locally available for the clients. | ||||
|      * | ||||
|      * @iscommand | ||||
|      */ | ||||
|     void cmdPlayAmbience(int argc, QStringList argv); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief DJ-blocks a client. | ||||
|      * | ||||
|  | ||||
| @ -638,6 +638,15 @@ class AreaData : public QObject | ||||
|      */ | ||||
|     QString currentMusic() const; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Returns the ambient audio currently being played in the area. | ||||
|      * | ||||
|      * @return See short description. | ||||
|      * | ||||
|      * @see #m_currentAmbience | ||||
|      */ | ||||
|     QString currentAmbience() const; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Sets the music currently being played in the area. | ||||
|      * | ||||
| @ -673,6 +682,13 @@ class AreaData : public QObject | ||||
|      */ | ||||
|     void changeMusic(const QString &f_source_r, const QString &f_newSong_r); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Changes the ambience audio being played in the area. | ||||
|      * | ||||
|      * @param f_newSong_r The name of the new audio that is going to be played in the area. | ||||
|      */ | ||||
|     void changeAmbience(const QString &f_newSong_r); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Returns the evidence mod in the area. | ||||
|      * | ||||
| @ -1097,6 +1113,14 @@ class AreaData : public QObject | ||||
|      */ | ||||
|     QString m_currentMusic; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief See m_currentMusic, but for ambience. | ||||
|      * | ||||
|      * @details Title is a path to the music file, with the starting point on | ||||
|      * `base/sounds/music/` clientside, with file extension. | ||||
|      */ | ||||
|     QString m_currentAmbience; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief The name of the client (or client's character) that started the currently playing music. | ||||
|      */ | ||||
|  | ||||
| @ -101,6 +101,13 @@ class ConfigManager | ||||
|      */ | ||||
|     static QSettings *areaData(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Returns a pointer to the QSettings object which contains the ambience configuration. | ||||
|      * | ||||
|      * @return See short description. | ||||
|      */ | ||||
|     static QSettings *ambience(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Returns a sanitized QStringList of the areas. | ||||
|      * | ||||
| @ -552,6 +559,11 @@ class ConfigManager | ||||
|      */ | ||||
|     static QSettings *m_logtext; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Stores all adjustable logstrings. | ||||
|      */ | ||||
|     static QSettings *m_ambience; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Pointer to QElapsedTimer to track the uptime of the server. | ||||
|      */ | ||||
|  | ||||
| @ -147,7 +147,8 @@ const QMap<QString, AOClient::CommandInfo> AOClient::COMMANDS{ | ||||
|     {"toggle_wtce", {{ACLRole::CM}, 0, &AOClient::cmdToggleWtce}}, | ||||
|     {"toggle_shouts", {{ACLRole::CM}, 0, &AOClient::cmdToggleShouts}}, | ||||
|     {"kick_other", {{ACLRole::NONE}, 0, &AOClient::cmdKickOther}}, | ||||
|     {"jukebox_skip", {{ACLRole::CM}, 0, &AOClient::cmdJukeboxSkip}}}; | ||||
|     {"jukebox_skip", {{ACLRole::CM}, 0, &AOClient::cmdJukeboxSkip}}, | ||||
|     {"play_ambience", {{ACLRole::NONE}, 1, &AOClient::cmdPlayAmbience}}}; | ||||
| 
 | ||||
| void AOClient::clientDisconnected() | ||||
| { | ||||
|  | ||||
| @ -108,6 +108,8 @@ void AreaData::clientJoinedArea(int f_charId, int f_userId) | ||||
|     } | ||||
|     m_joined_ids.append(f_userId); | ||||
|     emit userJoinedArea(m_index, f_userId); | ||||
|     // Send out ambience as well. Use channel 1 for that
 | ||||
|     emit sendAreaPacketClient(PacketFactory::createPacket("MC", {m_currentAmbience, QString::number(-1), ConfigManager::serverName(), QString::number(1), QString::number(1)}), f_userId); | ||||
|     // The name will never be shown as we are using a spectator ID. Still nice for people who network sniff.
 | ||||
|     // We auto-loop this so you'll never sit in silence unless wanted.
 | ||||
|     emit sendAreaPacketClient(PacketFactory::createPacket("MC", {m_currentMusic, QString::number(-1), ConfigManager::serverName(), QString::number(1)}), f_userId); | ||||
| @ -494,11 +496,21 @@ void AreaData::changeMusic(const QString &f_source_r, const QString &f_newSong_r | ||||
|     m_musicPlayedBy = f_source_r; | ||||
| } | ||||
| 
 | ||||
| void AreaData::changeAmbience(const QString &f_newSong_r) | ||||
| { | ||||
|     m_currentAmbience = f_newSong_r; | ||||
| } | ||||
| 
 | ||||
| QString AreaData::currentMusic() const | ||||
| { | ||||
|     return m_currentMusic; | ||||
| } | ||||
| 
 | ||||
| QString AreaData::currentAmbience() const | ||||
| { | ||||
|     return m_currentAmbience; | ||||
| } | ||||
| 
 | ||||
| void AreaData::setCurrentMusic(QString f_current_song) | ||||
| { | ||||
|     m_currentMusic = f_current_song; | ||||
| @ -587,6 +599,14 @@ QString AreaData::background() const | ||||
| void AreaData::setBackground(const QString f_background) | ||||
| { | ||||
|     m_background = f_background; | ||||
|     QSettings *ambience_data = ConfigManager::ambience(); | ||||
|     QString new_ambience = ambience_data->value(f_background + "/ambience").toString(); | ||||
|     if (new_ambience != "") { | ||||
|         changeAmbience(new_ambience); | ||||
|     } | ||||
|     else { | ||||
|         changeAmbience(""); // DON'T use ~stop.mp3 it overrides some code we don't want overridden
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool AreaData::ignoreBgList() | ||||
|  | ||||
| @ -299,6 +299,13 @@ void AOClient::cmdSetBackground(int argc, QStringList argv) | ||||
|         if (server->getBackgrounds().contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) { | ||||
|             area->setBackground(f_background); | ||||
|             server->broadcast(PacketFactory::createPacket("BN", {f_background}), m_current_area); | ||||
|             QString ambience_name = ConfigManager::ambience()->value(f_background + "/ambience").toString(); | ||||
|             if (ambience_name != "") { | ||||
|                 server->broadcast(PacketFactory::createPacket("MC", {ambience_name, "-1", m_showname, "1", "1"}), m_current_area); | ||||
|             } | ||||
|             else { | ||||
|                 server->broadcast(PacketFactory::createPacket("MC", {"~stop.mp3", "-1", m_showname, "1", "1"}), m_current_area); | ||||
|             } | ||||
|             sendServerMessageArea(m_current_char + " changed the background to " + f_background); | ||||
|         } | ||||
|         else { | ||||
|  | ||||
| @ -49,6 +49,25 @@ void AOClient::cmdPlay(int argc, QStringList argv) | ||||
|     server->broadcast(music_change, m_current_area); | ||||
| } | ||||
| 
 | ||||
| void AOClient::cmdPlayAmbience(int argc, QStringList argv) | ||||
| { | ||||
|     Q_UNUSED(argc); | ||||
| 
 | ||||
|     if (m_is_dj_blocked) { | ||||
|         sendServerMessage("You are blocked from changing the ambience."); | ||||
|         return; | ||||
|     } | ||||
|     AreaData *l_area = server->getAreaById(m_current_area); | ||||
|     if (!l_area->owners().contains(m_id) && !l_area->isPlayEnabled()) { // Make sure we have permission to play music
 | ||||
|         sendServerMessage("Free ambience play is disabled in this area."); | ||||
|         return; | ||||
|     } | ||||
|     QString l_song = argv.join(" "); | ||||
|     l_area->changeAmbience(l_song); | ||||
|     AOPacket *music_change = PacketFactory::createPacket("MC", {l_song, "-1", m_showname, "1", "1"}); | ||||
|     server->broadcast(music_change, m_current_area); | ||||
| } | ||||
| 
 | ||||
| void AOClient::cmdCurrentMusic(int argc, QStringList argv) | ||||
| { | ||||
|     Q_UNUSED(argc); | ||||
|  | ||||
| @ -23,6 +23,7 @@ QSettings *ConfigManager::m_settings = new QSettings("config/config.ini", QSetti | ||||
| QSettings *ConfigManager::m_discord = new QSettings("config/discord.ini", QSettings::IniFormat); | ||||
| QSettings *ConfigManager::m_areas = new QSettings("config/areas.ini", QSettings::IniFormat); | ||||
| QSettings *ConfigManager::m_logtext = new QSettings("config/text/logtext.ini", QSettings::IniFormat); | ||||
| QSettings *ConfigManager::m_ambience = new QSettings("config/ambience.ini", QSettings::IniFormat); | ||||
| ConfigManager::CommandSettings *ConfigManager::m_commands = new CommandSettings(); | ||||
| QElapsedTimer *ConfigManager::m_uptimeTimer = new QElapsedTimer; | ||||
| MusicList *ConfigManager::m_musicList = new MusicList; | ||||
| @ -231,6 +232,11 @@ QSettings *ConfigManager::areaData() | ||||
|     return m_areas; | ||||
| } | ||||
| 
 | ||||
| QSettings *ConfigManager::ambience() | ||||
| { | ||||
|     return m_ambience; | ||||
| } | ||||
| 
 | ||||
| QStringList ConfigManager::sanitizedAreaNames() | ||||
| { | ||||
|     QStringList l_area_names = m_areas->childGroups(); // invisibly does a lexicographical sort, because Qt is great like that
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 in1tiate
						in1tiate