Ensure that no stale songs are in the jukebox queue when its disabled

Housekeeping and fix /currentmusic not returning a song
This commit is contained in:
Salanto 2021-09-12 23:20:09 +02:00
parent f9dcaa2aa5
commit 8bdfe1e045
4 changed files with 42 additions and 7 deletions

View File

@ -577,6 +577,15 @@ class AreaData : public QObject {
*/
QString currentMusic() const;
/**
* @brief Sets the music currently being played in the area.
*
* @param Name of the song being played.
*
* @see #m_currentMusic
*/
void setCurrentMusic(QString f_current_song);
/**
* @brief Returns the showname of the client who played the music in the area.
*
@ -586,6 +595,15 @@ class AreaData : public QObject {
*/
QString musicPlayerBy() const;
/**
* @brief Sets the showname of the client who played the music in the area.
*
* @param Showname of the client.
*
* @see #m_musicPlayedBy
*/
void setMusicPlayedBy(const QString& f_music_player);
/**
* @brief Changes the music being played in the area.
*

View File

@ -429,6 +429,11 @@ QString AreaData::musicPlayerBy() const
return m_musicPlayedBy;
}
void AreaData::setMusicPlayedBy(const QString& f_music_player)
{
m_musicPlayedBy = f_music_player;
}
void AreaData::changeMusic(const QString &f_source_r, const QString &f_newSong_r)
{
m_currentMusic = f_newSong_r;
@ -440,6 +445,11 @@ QString AreaData::currentMusic() const
return m_currentMusic;
}
void AreaData::setCurrentMusic(QString f_current_song)
{
m_currentMusic = f_current_song;
}
int AreaData::proHP() const
{
return m_proHP;
@ -517,6 +527,10 @@ void AreaData::toggleIgnoreBgList()
void AreaData::toggleJukebox()
{
m_jukebox = !m_jukebox;
if (!m_jukebox) {
m_jukebox_queue.clear();
m_jukebox_timer->stop();
}
}
bool AreaData::addJukeboxSong(QString f_song)
@ -525,6 +539,8 @@ bool AreaData::addJukeboxSong(QString f_song)
if (m_jukebox_queue.size() == 0) {
emit playJukeboxSong(AOPacket("MC",{f_song,QString::number(-1)}), index());
m_jukebox_timer->start(ConfigManager::songInformation(f_song) * 1000);
setCurrentMusic(f_song);
setMusicPlayedBy("Jukebox");
}
m_jukebox_queue.append(f_song);
return true;
@ -550,6 +566,6 @@ void AreaData::switchJukeboxSong()
m_jukebox_queue.remove(l_random_index);
m_jukebox_queue.squeeze();
}
currentMusic() = l_song_name;
musicPlayerBy() = "Jukebox";
setCurrentMusic(l_song_name);
setMusicPlayedBy("Jukebox");
}

View File

@ -41,7 +41,7 @@ void AOClient::cmdCurrentMusic(int argc, QStringList argv)
Q_UNUSED(argv);
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->currentMusic() != "" && l_area->currentMusic() != "~stop.mp3") // dummy track for stopping music
if (!l_area->currentMusic().isEmpty() && !l_area->currentMusic().contains("~stop.mp3")) // dummy track for stopping music
sendServerMessage("The current song is " + l_area->currentMusic() + " played by " + l_area->musicPlayerBy());
else
sendServerMessage("There is no music playing.");

View File

@ -320,17 +320,18 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack
else
l_final_song = l_argument;
//Jukebox intercepts the direct playing of messages.
if (area->isjukeboxEnabled()) {
if (area->addJukeboxSong(l_final_song))
sendServerMessage("Your song has been added to the Jukebox queue.");
sendServerMessage("Song added to jukebox.");
else
sendServerMessage("Your song could not be added to the jukebox queue. It already exists");
sendServerMessage("Unable to add. Song already in jukebox.");
return;
}
AOPacket l_music_change("MC", {l_final_song, argv[1], m_showname, "1", "0", l_effects});
area->currentMusic() = l_final_song;
area->musicPlayerBy() = m_showname;
area->setCurrentMusic(l_final_song);
area->setMusicPlayedBy(m_showname);
server->broadcast(l_music_change, m_current_area);
return;
}