Improve error handling and messaging to user

This commit is contained in:
Salanto 2021-09-13 18:13:48 +02:00
parent 3f212aeb35
commit df237bbe3a
3 changed files with 16 additions and 13 deletions

View File

@ -814,7 +814,7 @@ class AreaData : public QObject {
/**
* @brief Adds a song to the Jukeboxs queue.
*/
bool addJukeboxSong(QString f_song);
QString addJukeboxSong(QString f_song);
public slots:

View File

@ -533,20 +533,24 @@ void AreaData::toggleJukebox()
}
}
bool AreaData::addJukeboxSong(QString f_song)
QString AreaData::addJukeboxSong(QString f_song)
{
if(!m_jukebox_queue.contains(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");
int l_song_duration = ConfigManager::songInformation(f_song);
if (l_song_duration >= 0) {
emit playJukeboxSong(AOPacket("MC",{f_song,QString::number(-1)}), index());
m_jukebox_timer->start(l_song_duration * 1000);
setCurrentMusic(f_song);
setMusicPlayedBy("Jukebox");
m_jukebox_queue.append(f_song);
return "Song added to Jukebox.";
}
}
m_jukebox_queue.append(f_song);
return true;
return "Unable to add song. Duration shorther than 1.";
}
else {
return false;
return "Unable to add song. Song already in Jukebox.";
}
}

View File

@ -322,13 +322,12 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack
//Jukebox intercepts the direct playing of messages.
if (area->isjukeboxEnabled()) {
if (area->addJukeboxSong(l_final_song))
sendServerMessage("Song added to jukebox.");
else
sendServerMessage("Unable to add. Song already in jukebox.");
QString l_jukebox_reply = area->addJukeboxSong(l_final_song);
sendServerMessage(l_jukebox_reply);
return;
}
AOPacket l_music_change("MC", {l_final_song, argv[1], m_showname, "1", "0", l_effects});
area->setCurrentMusic(l_final_song);
area->setMusicPlayedBy(m_showname);