diff --git a/core/include/area_data.h b/core/include/area_data.h index a8512ba..24959de 100644 --- a/core/include/area_data.h +++ b/core/include/area_data.h @@ -870,6 +870,25 @@ public slots: */ void sendAreaPacket(AOPacket f_packet, int f_area_index); + /** + * @brief sendAreaPacketClient Sends a packet to the specified client. + * + * @param f_packet The packe to be send. + * + * @param f_user_id The user ID of the client. + */ + void sendAreaPacketClient(AOPacket f_packet, int f_user_id); + + /** + * @brief userJoinedArea Signals that a new client has joined an area. + * + * @details This is mostly a signal for more compelex features where multiple managers need to know of the change. + * + * @param f_area_index Area Index that the client joined in. + * + * + * @param f_user_id The user ID of the client. + */ void userJoinedArea(int f_area_index, int f_user_id); private: diff --git a/core/src/area_data.cpp b/core/src/area_data.cpp index ea0b04b..8fbcf6d 100644 --- a/core/src/area_data.cpp +++ b/core/src/area_data.cpp @@ -95,6 +95,7 @@ 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); } QList AreaData::owners() const diff --git a/core/src/commands/music.cpp b/core/src/commands/music.cpp index 0fdc1f3..629bb63 100644 --- a/core/src/commands/music.cpp +++ b/core/src/commands/music.cpp @@ -29,8 +29,12 @@ void AOClient::cmdPlay(int argc, QStringList argv) } AreaData* l_area = server->m_areas[m_current_area]; QString l_song = argv.join(" "); - l_area->currentMusic() = l_song; - l_area->musicPlayerBy() = m_showname; + if (m_showname.isEmpty()) { + l_area->changeMusic(m_current_char, l_song); + } + else { + l_area->changeMusic(m_showname, l_song); + } AOPacket music_change("MC", {l_song, QString::number(server->getCharID(m_current_char)), m_showname, "1", "0"}); server->broadcast(music_change, m_current_area); } diff --git a/core/src/server.cpp b/core/src/server.cpp index aacaec1..4996b88 100644 --- a/core/src/server.cpp +++ b/core/src/server.cpp @@ -104,6 +104,8 @@ void Server::start() m_areas.insert(i, l_area); connect(l_area, &AreaData::sendAreaPacket, this, QOverload::of(&Server::broadcast)); + connect(l_area, &AreaData::sendAreaPacketClient, + this, &Server::unicast); connect(l_area, &AreaData::userJoinedArea, music_manager, &MusicManager::userJoinedArea); music_manager->registerArea(i);