From 3f2aae602e6ded0c1f06eb8724ff2bc7bdcf320c Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 23 Mar 2013 16:59:24 +0100 Subject: [PATCH] - Send data to clients only if they are authenticated. - Send songs of the active playlist if the active playlist changes. --- src/networkremote/outgoingdatacreator.cpp | 4 ++++ src/networkremote/remoteclient.cpp | 26 ++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/networkremote/outgoingdatacreator.cpp b/src/networkremote/outgoingdatacreator.cpp index d6d8ab845..f7450291f 100644 --- a/src/networkremote/outgoingdatacreator.cpp +++ b/src/networkremote/outgoingdatacreator.cpp @@ -125,6 +125,10 @@ void OutgoingDataCreator::SendAllPlaylists() { } void OutgoingDataCreator::ActiveChanged(Playlist* playlist) { + // Send the tracks of the active playlist + SendPlaylistSongs(playlist->id()); + + // Send the changed message after sending the playlist songs pb::remote::Message msg; msg.set_type(pb::remote::ACTIVE_PLAYLIST_CHANGED); msg.mutable_response_active_changed()->set_id(playlist->id()); diff --git a/src/networkremote/remoteclient.cpp b/src/networkremote/remoteclient.cpp index 69111d628..5a9d373c8 100644 --- a/src/networkremote/remoteclient.cpp +++ b/src/networkremote/remoteclient.cpp @@ -131,20 +131,22 @@ void RemoteClient::DisconnectClient(pb::remote::ReasonDisconnect reason) { } void RemoteClient::SendData(pb::remote::Message *msg) { - // Serialize the message - std::string data = msg->SerializeAsString(); + if (authenticated_) { + // Serialize the message + std::string data = msg->SerializeAsString(); - // Check if we are still connected - if (client_->state() == QTcpSocket::ConnectedState) { - // write the length of the data first - QDataStream s(client_); - s << qint32(data.length()); - s.writeRawData(data.data(), data.length()); + // Check if we are still connected + if (client_->state() == QTcpSocket::ConnectedState) { + // write the length of the data first + QDataStream s(client_); + s << qint32(data.length()); + s.writeRawData(data.data(), data.length()); - // Do NOT flush data here! If the client is already disconnected, it - // causes a SIGPIPE termination!!! - } else { - client_->close(); + // Do NOT flush data here! If the client is already disconnected, it + // causes a SIGPIPE termination!!! + } else { + client_->close(); + } } }