Merge pull request #3859 from Aestek/feature/netplay-md5

Netplay: add md5 testing
This commit is contained in:
Anthony Serna 2016-07-18 09:20:37 -05:00 committed by GitHub
commit 1a81735527
22 changed files with 538 additions and 45 deletions

View file

@ -4,10 +4,15 @@
#include "Core/NetPlayClient.h"
#include <algorithm>
#include <fstream>
#include <mbedtls/md5.h>
#include <memory>
#include <thread>
#include "Common/Common.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/ENetUtil.h"
#include "Common/MD5.h"
#include "Common/MsgHandler.h"
#include "Common/Timer.h"
#include "Core/ConfigManager.h"
@ -19,6 +24,8 @@
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h"
#include "Core/Movie.h"
#include "Core/Movie.h"
#include "Core/NetPlayClient.h"
#include "InputCommon/GCAdapter.h"
static std::mutex crit_netplay_client;
@ -500,6 +507,55 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
}
break;
case NP_MSG_COMPUTE_MD5:
{
std::string file_identifier;
packet >> file_identifier;
ComputeMD5(file_identifier);
}
break;
case NP_MSG_MD5_PROGRESS:
{
PlayerId pid;
int progress;
packet >> pid;
packet >> progress;
m_dialog->SetMD5Progress(pid, progress);
}
break;
case NP_MSG_MD5_RESULT:
{
PlayerId pid;
std::string result;
packet >> pid;
packet >> result;
m_dialog->SetMD5Result(pid, result);
}
break;
case NP_MSG_MD5_ERROR:
{
PlayerId pid;
std::string error;
packet >> pid;
packet >> error;
m_dialog->SetMD5Result(pid, error);
}
break;
case NP_MSG_MD5_ABORT:
{
m_should_compute_MD5 = false;
m_dialog->AbortMD5();
}
break;
default:
PanicAlertT("Unknown message received with id : %d", mid);
break;
@ -1142,6 +1198,47 @@ bool NetPlayClient::DoAllPlayersHaveGame()
[](auto entry) { return entry.second.game_status == PlayerGameStatus::Ok; });
}
void NetPlayClient::ComputeMD5(const std::string& file_identifier)
{
if (m_should_compute_MD5)
return;
m_dialog->ShowMD5Dialog(file_identifier);
m_should_compute_MD5 = true;
std::string file;
if (file_identifier == WII_SDCARD)
file = File::GetUserPath(F_WIISDCARD_IDX);
else
file = m_dialog->FindGame(file_identifier);
if (file.empty() || !File::Exists(file))
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_ERROR);
spac << "file not found";
Send(spac);
return;
}
m_MD5_thread = std::thread([this, file]() {
std::string sum = MD5::MD5Sum(file, [&](int progress) {
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_PROGRESS);
spac << progress;
Send(spac);
return m_should_compute_MD5;
});
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_RESULT);
spac << sum;
Send(spac);
});
m_MD5_thread.detach();
}
// stuff hacked into dolphin
// called from ---CPU--- thread