Optimize playlist transfer
This commit is contained in:
parent
377ba8d4cb
commit
44e6d6acc8
@ -21,17 +21,20 @@ namespace Components
|
|||||||
{
|
{
|
||||||
int numArgs;
|
int numArgs;
|
||||||
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
|
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
|
||||||
|
|
||||||
for (int i = 0; i < numArgs; ++i)
|
if (argv)
|
||||||
{
|
{
|
||||||
std::wstring wFlag(argv[i]);
|
for (int i = 0; i < numArgs; ++i)
|
||||||
if (wFlag[0] == L'-')
|
|
||||||
{
|
{
|
||||||
Flags::EnabledFlags.push_back(std::string(++wFlag.begin(), wFlag.end()));
|
std::wstring wFlag(argv[i]);
|
||||||
|
if (wFlag[0] == L'-')
|
||||||
|
{
|
||||||
|
Flags::EnabledFlags.push_back(std::string(++wFlag.begin(), wFlag.end()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LocalFree(argv);
|
LocalFree(argv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Flags::Flags()
|
Flags::Flags()
|
||||||
|
@ -46,15 +46,12 @@ namespace Components
|
|||||||
Logger::Print("Received playlist request, sending currently stored buffer.\n");
|
Logger::Print("Received playlist request, sending currently stored buffer.\n");
|
||||||
|
|
||||||
std::string compressedList = Utils::Compression::ZLib::Compress(Playlist::CurrentPlaylistBuffer);
|
std::string compressedList = Utils::Compression::ZLib::Compress(Playlist::CurrentPlaylistBuffer);
|
||||||
unsigned int size = compressedList.size();
|
|
||||||
unsigned int hash = Utils::Cryptography::JenkinsOneAtATime::Compute(compressedList.data(), compressedList.size());
|
|
||||||
|
|
||||||
std::string response;
|
Proto::Party::Playlist list;
|
||||||
response.append(reinterpret_cast<char*>(&hash), 4);
|
list.set_hash(Utils::Cryptography::JenkinsOneAtATime::Compute(compressedList.data(), compressedList.size()));
|
||||||
response.append(reinterpret_cast<char*>(&size), 4);
|
list.set_buffer(compressedList);
|
||||||
response.append(compressedList);
|
|
||||||
|
|
||||||
Network::SendCommand(address, "playlistresponse", response);
|
Network::SendCommand(address, "playlistResponse", list.SerializeAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::PlaylistReponse(Network::Address address, std::string data)
|
void Playlist::PlaylistReponse(Network::Address address, std::string data)
|
||||||
@ -63,34 +60,24 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (address == Party::Target())
|
if (address == Party::Target())
|
||||||
{
|
{
|
||||||
if (data.size() <= 8)
|
Proto::Party::Playlist list;
|
||||||
|
|
||||||
|
if (!list.ParseFromString(data))
|
||||||
{
|
{
|
||||||
Party::PlaylistError(Utils::VA("Received playlist response, but it is invalid."));
|
Party::PlaylistError(Utils::VA("Received playlist response from %s, but it is invalid.", address.GetString()));
|
||||||
Playlist::ReceivedPlaylistBuffer.clear();
|
Playlist::ReceivedPlaylistBuffer.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Read hash and length
|
|
||||||
unsigned int hash = *reinterpret_cast<unsigned int*>(const_cast<char*>(data.data()));
|
|
||||||
unsigned int length = *reinterpret_cast<unsigned int*>(const_cast<char*>(data.data() + 4));
|
|
||||||
|
|
||||||
// Verify length
|
|
||||||
if (length > (data.size() - 8))
|
|
||||||
{
|
|
||||||
Party::PlaylistError(Utils::VA("Received playlist response, but it is too short."));
|
|
||||||
Playlist::ReceivedPlaylistBuffer.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate buffer and hash
|
// Generate buffer and hash
|
||||||
std::string compressedData(data.data() + 8, length);
|
std::string compressedData(list.buffer());
|
||||||
unsigned int hash2 = Utils::Cryptography::JenkinsOneAtATime::Compute(compressedData.data(), compressedData.size());
|
unsigned int hash = Utils::Cryptography::JenkinsOneAtATime::Compute(compressedData.data(), compressedData.size());
|
||||||
|
|
||||||
//Validate hashes
|
//Validate hashes
|
||||||
if (hash2 != hash)
|
if (hash != list.hash())
|
||||||
{
|
{
|
||||||
Party::PlaylistError(Utils::VA("Received playlist response, but the checksum did not match (%d != %d).", hash, hash2));
|
Party::PlaylistError(Utils::VA("Received playlist response from %s, but the checksum did not match (%d != %d).", address.GetString(), list.hash(), hash));
|
||||||
Playlist::ReceivedPlaylistBuffer.clear();
|
Playlist::ReceivedPlaylistBuffer.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -150,8 +137,8 @@ namespace Components
|
|||||||
Utils::Hook::Set<BYTE>(0x4D6E60, 0xC3);
|
Utils::Hook::Set<BYTE>(0x4D6E60, 0xC3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Network::Handle("getplaylist", PlaylistRequest);
|
Network::Handle("getPlaylist", PlaylistRequest);
|
||||||
Network::Handle("playlistresponse", PlaylistReponse);
|
Network::Handle("playlistResponse", PlaylistReponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
Playlist::~Playlist()
|
Playlist::~Playlist()
|
||||||
|
9
src/Proto/party.proto
Normal file
9
src/Proto/party.proto
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package Proto.Party;
|
||||||
|
|
||||||
|
message Playlist
|
||||||
|
{
|
||||||
|
uint32 hash = 1;
|
||||||
|
bytes buffer = 2;
|
||||||
|
}
|
@ -70,6 +70,7 @@
|
|||||||
|
|
||||||
// Protobuf
|
// Protobuf
|
||||||
#include "proto/network.pb.h"
|
#include "proto/network.pb.h"
|
||||||
|
#include "proto/party.pb.h"
|
||||||
#include "proto/auth.pb.h"
|
#include "proto/auth.pb.h"
|
||||||
#include "proto/node.pb.h"
|
#include "proto/node.pb.h"
|
||||||
#include "proto/rcon.pb.h"
|
#include "proto/rcon.pb.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user