From c85471d2cdc14375ba809ba6bfbe5ef72bf1e9a5 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Tue, 15 Mar 2022 00:24:47 +0100 Subject: [PATCH] Fix #234 / Exclude stop track from alias lookup. (#245) * Exclude ~stop.mp3 from alias lookup * Fix auto-looping for on-join songs. --- core/src/area_data.cpp | 4 +++- core/src/packets.cpp | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/src/area_data.cpp b/core/src/area_data.cpp index 8fbcf6d..c95f9d9 100644 --- a/core/src/area_data.cpp +++ b/core/src/area_data.cpp @@ -95,7 +95,9 @@ void AreaData::clientJoinedArea(int f_charId, int f_userId) } m_joined_ids.append(f_userId); emit userJoinedArea(m_index, f_userId); - emit sendAreaPacketClient(AOPacket("MC",{m_currentMusic, 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(AOPacket("MC",{m_currentMusic, QString::number(-1), ConfigManager::serverName(), QString::number(1)}), f_userId); } QList AreaData::owners() const diff --git a/core/src/packets.cpp b/core/src/packets.cpp index 3e962ca..4d2a51c 100644 --- a/core/src/packets.cpp +++ b/core/src/packets.cpp @@ -313,6 +313,8 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack else l_effects = "0"; QString l_final_song; + + //As categories can be used to stop music we need to check if it has a dot for the extension. If not, we assume its a category. if (!l_argument.contains(".")) l_final_song = "~stop.mp3"; else @@ -325,12 +327,21 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack return; } - QPair l_song = m_music_manager->songInformation(l_final_song, m_current_area); - QString l_real_name = l_song.first; - AOPacket l_music_change("MC", {l_real_name, argv[1], m_showname, "1", "0", l_effects}); - area->setCurrentMusic(l_final_song); - area->setMusicPlayedBy(m_showname); + if (l_final_song != "~stop.mp3") { + //We might have an aliased song. We check for its real songname and send it to the clients. + QPair l_song = m_music_manager->songInformation(l_final_song, m_current_area); + l_final_song = l_song.first; + } + AOPacket l_music_change("MC", {l_final_song, argv[1], m_showname, "1", "0", l_effects}); server->broadcast(l_music_change, m_current_area); + + //Since we can't ensure a user has their showname set, we check if its empty to prevent + //"played by ." in /currentmusic. + if (m_showname.isEmpty()) { + area->changeMusic(m_current_char,l_final_song); + return; + } + area->changeMusic(m_showname,l_final_song); return; }