Fully fix playlist downloading.
This commit is contained in:
parent
8343ce5f13
commit
df2a542377
@ -45,24 +45,6 @@ namespace Components
|
||||
{
|
||||
Logger::Print("Received playlist request, sending currently stored buffer.\n");
|
||||
|
||||
// // Split playlist data
|
||||
// unsigned int maxPacketSize = 1000;
|
||||
// unsigned int maxBytes = Playlist::CurrentPlaylistBuffer.size();
|
||||
//
|
||||
// for (unsigned int i = 0; i < maxBytes; i += maxPacketSize)
|
||||
// {
|
||||
// unsigned int sendBytes = min(maxPacketSize, maxBytes - i);
|
||||
// unsigned int sentBytes = i + sendBytes;
|
||||
//
|
||||
// std::string data;
|
||||
// data.append(reinterpret_cast<char*>(&sentBytes), 4); // Sent bytes
|
||||
// data.append(reinterpret_cast<char*>(&maxBytes), 4); // Max bytes
|
||||
//
|
||||
// data.append(Playlist::CurrentPlaylistBuffer.data() + i, sendBytes);
|
||||
//
|
||||
// Network::SendRaw(address, std::string("playlistresponse\n") + data);
|
||||
// }
|
||||
|
||||
std::string compressedList = Utils::Compression::ZLib::Compress(Playlist::CurrentPlaylistBuffer);
|
||||
unsigned int size = compressedList.size();
|
||||
unsigned int hash = Utils::OneAtATime(compressedList.data(), compressedList.size());
|
||||
@ -89,38 +71,11 @@ namespace Components
|
||||
}
|
||||
else
|
||||
{
|
||||
// unsigned int sentBytes = *(unsigned int*)(data.data() + 0);
|
||||
// unsigned int maxBytes = *(unsigned int*)(data.data() + 4);
|
||||
//
|
||||
// // Clear current buffer, if we receive a new packet
|
||||
// if (data.size() - 8 == sentBytes) Playlist::ReceivedPlaylistBuffer.clear();
|
||||
//
|
||||
// // Append received data
|
||||
// Playlist::ReceivedPlaylistBuffer.append(data.data() + 8, data.size() - 8);
|
||||
//
|
||||
// if (Playlist::ReceivedPlaylistBuffer.size() != sentBytes)
|
||||
// {
|
||||
// Party::PlaylistError(Utils::VA("Received playlist data, but it seems invalid: %d != %d", sentBytes, Playlist::ReceivedPlaylistBuffer.size()));
|
||||
// Playlist::ReceivedPlaylistBuffer.clear();
|
||||
// return;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Logger::Print("Received playlist data: %d/%d (%d%%)\n", sentBytes, maxBytes, ((100 * sentBytes) / maxBytes));
|
||||
// }
|
||||
//
|
||||
// if (Playlist::ReceivedPlaylistBuffer.size() == maxBytes)
|
||||
// {
|
||||
// Logger::Print("Received playlist, loading and continuing connection...\n");
|
||||
// Game::Live_ParsePlaylists(Playlist::ReceivedPlaylistBuffer.data());
|
||||
// Party::PlaylistContinue();
|
||||
//
|
||||
// Playlist::ReceivedPlaylistBuffer.clear();
|
||||
// }
|
||||
|
||||
// Read hash and length
|
||||
unsigned int hash = *(unsigned int*)data.data();
|
||||
unsigned int length = *(unsigned int*)(data.data() + 4);
|
||||
|
||||
// Verify length
|
||||
if (length > (data.size() - 8))
|
||||
{
|
||||
Party::PlaylistError(Utils::VA("Received playlist response, but it is too short."));
|
||||
@ -128,10 +83,11 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int hash2 = Utils::OneAtATime(data.data() + 8, length);
|
||||
// Generate buffer and hash
|
||||
std::string compressedData(data.data() + 8, length);
|
||||
Playlist::ReceivedPlaylistBuffer = Utils::Compression::ZLib::Decompress(compressedData);
|
||||
unsigned int hash2 = Utils::OneAtATime(compressedData.data(), compressedData.size());
|
||||
|
||||
//Validate hashes
|
||||
if (hash2 != hash)
|
||||
{
|
||||
Party::PlaylistError(Utils::VA("Received playlist response, but the checksum did not match (%d != %d).", hash, hash2));
|
||||
@ -139,9 +95,13 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::Print("Received playlist, loading and continuing connection...\n");
|
||||
Game::Live_ParsePlaylists(Playlist::ReceivedPlaylistBuffer.data());
|
||||
Party::PlaylistContinue();
|
||||
// Decompress buffer
|
||||
Playlist::ReceivedPlaylistBuffer = Utils::Compression::ZLib::Decompress(compressedData);
|
||||
|
||||
// Load and continue connection
|
||||
Logger::Print("Received playlist, loading and continuing connection...\n");
|
||||
Game::Live_ParsePlaylists(Playlist::ReceivedPlaylistBuffer.data());
|
||||
Party::PlaylistContinue();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user