Merge pull request #242 from Salanto/feature/music-on-area-join

Send song when client joins the area.
This commit is contained in:
Rosemary Witchaven 2022-03-12 23:27:41 -06:00 committed by GitHub
commit ba09b4d2c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 2 deletions

View File

@ -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:

View File

@ -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<int> AreaData::owners() const

View File

@ -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);
}

View File

@ -104,6 +104,8 @@ void Server::start()
m_areas.insert(i, l_area);
connect(l_area, &AreaData::sendAreaPacket,
this, QOverload<AOPacket,int>::of(&Server::broadcast));
connect(l_area, &AreaData::sendAreaPacketClient,
this, &Server::unicast);
connect(l_area, &AreaData::userJoinedArea,
music_manager, &MusicManager::userJoinedArea);
music_manager->registerArea(i);