Send data to clients only if they are authenticated.

This commit is contained in:
Andreas 2013-03-23 16:59:24 +01:00
parent 8251b53411
commit 53813ae04c
2 changed files with 18 additions and 12 deletions

View File

@ -125,6 +125,10 @@ void OutgoingDataCreator::SendAllPlaylists() {
} }
void OutgoingDataCreator::ActiveChanged(Playlist* playlist) { 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; pb::remote::Message msg;
msg.set_type(pb::remote::ACTIVE_PLAYLIST_CHANGED); msg.set_type(pb::remote::ACTIVE_PLAYLIST_CHANGED);
msg.mutable_response_active_changed()->set_id(playlist->id()); msg.mutable_response_active_changed()->set_id(playlist->id());

View File

@ -131,20 +131,22 @@ void RemoteClient::DisconnectClient(pb::remote::ReasonDisconnect reason) {
} }
void RemoteClient::SendData(pb::remote::Message *msg) { void RemoteClient::SendData(pb::remote::Message *msg) {
// Serialize the message if (authenticated_) {
std::string data = msg->SerializeAsString(); // Serialize the message
std::string data = msg->SerializeAsString();
// Check if we are still connected // Check if we are still connected
if (client_->state() == QTcpSocket::ConnectedState) { if (client_->state() == QTcpSocket::ConnectedState) {
// write the length of the data first // write the length of the data first
QDataStream s(client_); QDataStream s(client_);
s << qint32(data.length()); s << qint32(data.length());
s.writeRawData(data.data(), data.length()); s.writeRawData(data.data(), data.length());
// Do NOT flush data here! If the client is already disconnected, it // Do NOT flush data here! If the client is already disconnected, it
// causes a SIGPIPE termination!!! // causes a SIGPIPE termination!!!
} else { } else {
client_->close(); client_->close();
}
} }
} }