summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2020-09-06 17:14:08 -0400
committerGitHub <noreply@github.com>2020-09-06 17:14:08 -0400
commite7e51756068a450b6e920c7783c81d7df4d2d133 (patch)
tree94f0bfe833986f8d35f0d2a40842807601f53b9f /Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
parent344fdabf23c048b81b8e87008a7a16837d180f55 (diff)
parentfc6c1931fa09513388f35507b724bc378a0758e1 (diff)
Merge pull request #8861 from JosJuice/netplay-hash
Make netplay's "same game" check more robust
Diffstat (limited to 'Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp')
-rw-r--r--Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp100
1 files changed, 57 insertions, 43 deletions
diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
index 77ceb45523..dd3be6cc65 100644
--- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
+++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
@@ -21,6 +21,7 @@
#include <QTableWidget>
#include <QTextBrowser>
+#include <algorithm>
#include <sstream>
#include "Common/CommonPaths.h"
@@ -37,6 +38,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/NetPlayServer.h"
+#include "Core/SyncIdentifier.h"
#include "DolphinQt/GameList/GameListModel.h"
#include "DolphinQt/NetPlay/ChunkedProgressDialog.h"
@@ -153,17 +155,19 @@ void NetPlayDialog::CreateMainLayout()
m_md5_menu = m_menu_bar->addMenu(tr("Checksum"));
m_md5_menu->addAction(tr("Current game"), this, [this] {
- Settings::Instance().GetNetPlayServer()->ComputeMD5(m_current_game);
+ Settings::Instance().GetNetPlayServer()->ComputeMD5(m_current_game_identifier);
});
m_md5_menu->addAction(tr("Other game..."), this, [this] {
GameListDialog gld(this);
if (gld.exec() != QDialog::Accepted)
return;
- Settings::Instance().GetNetPlayServer()->ComputeMD5(gld.GetSelectedUniqueID().toStdString());
+ Settings::Instance().GetNetPlayServer()->ComputeMD5(gld.GetSelectedGame().GetSyncIdentifier());
+ });
+ m_md5_menu->addAction(tr("SD Card"), this, [] {
+ Settings::Instance().GetNetPlayServer()->ComputeMD5(
+ NetPlay::NetPlayClient::GetSDCardIdentifier());
});
- m_md5_menu->addAction(tr("SD Card"), this,
- [] { Settings::Instance().GetNetPlayServer()->ComputeMD5(WII_SDCARD); });
m_other_menu = m_menu_bar->addMenu(tr("Other"));
m_record_input_action = m_other_menu->addAction(tr("Record Inputs"));
@@ -321,9 +325,14 @@ void NetPlayDialog::ConnectWidgets()
GameListDialog gld(this);
if (gld.exec() == QDialog::Accepted)
{
- auto unique_id = gld.GetSelectedUniqueID();
- Settings::Instance().GetNetPlayServer()->ChangeGame(unique_id.toStdString());
- Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), unique_id);
+ Settings& settings = Settings::Instance();
+
+ const UICommon::GameFile& game = gld.GetSelectedGame();
+ const std::string netplay_name = settings.GetGameListModel()->GetNetPlayName(game);
+
+ settings.GetNetPlayServer()->ChangeGame(game.GetSyncIdentifier(), netplay_name);
+ Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"),
+ QString::fromStdString(netplay_name));
}
});
@@ -416,7 +425,7 @@ void NetPlayDialog::OnStart()
return;
}
- const auto game = FindGameFile(m_current_game);
+ const auto game = FindGameFile(m_current_game_identifier);
if (!game)
{
PanicAlertT("Selected game doesn't exist in game list!");
@@ -583,11 +592,12 @@ void NetPlayDialog::UpdateDiscordPresence()
{
#ifdef USE_DISCORD_PRESENCE
// both m_current_game and m_player_count need to be set for the status to be displayed correctly
- if (m_player_count == 0 || m_current_game.empty())
+ if (m_player_count == 0 || m_current_game_name.empty())
return;
const auto use_default = [this]() {
- Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::Empty, "", m_current_game);
+ Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::Empty, "",
+ m_current_game_name);
};
if (Core::IsRunning())
@@ -602,7 +612,8 @@ void NetPlayDialog::UpdateDiscordPresence()
return use_default();
Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::RoomID,
- std::string(host_id.begin(), host_id.end()), m_current_game);
+ std::string(host_id.begin(), host_id.end()),
+ m_current_game_name);
}
else
{
@@ -612,7 +623,7 @@ void NetPlayDialog::UpdateDiscordPresence()
Discord::UpdateDiscordPresence(
m_player_count, Discord::SecretType::IPAddress,
- Discord::CreateSecretFromIPAddress(*m_external_ip_address, port), m_current_game);
+ Discord::CreateSecretFromIPAddress(*m_external_ip_address, port), m_current_game_name);
}
}
else
@@ -660,9 +671,10 @@ void NetPlayDialog::UpdateGUI()
return '|' + str + '|';
};
- static const std::map<NetPlay::PlayerGameStatus, QString> player_status{
- {NetPlay::PlayerGameStatus::Ok, tr("OK")},
- {NetPlay::PlayerGameStatus::NotFound, tr("Not Found")},
+ static const std::map<NetPlay::SyncIdentifierComparison, QString> player_status{
+ {NetPlay::SyncIdentifierComparison::SameGame, tr("OK")},
+ {NetPlay::SyncIdentifierComparison::DifferentVersion, tr("Wrong Version")},
+ {NetPlay::SyncIdentifierComparison::DifferentGame, tr("Not Found")},
};
for (int i = 0; i < m_player_count; i++)
@@ -805,15 +817,17 @@ void NetPlayDialog::AppendChat(const std::string& msg)
QApplication::alert(this);
}
-void NetPlayDialog::OnMsgChangeGame(const std::string& title)
+void NetPlayDialog::OnMsgChangeGame(const NetPlay::SyncIdentifier& sync_identifier,
+ const std::string& netplay_name)
{
- QString qtitle = QString::fromStdString(title);
- QueueOnObject(this, [this, qtitle, title] {
- m_game_button->setText(qtitle);
- m_current_game = title;
+ QString qname = QString::fromStdString(netplay_name);
+ QueueOnObject(this, [this, qname, netplay_name, &sync_identifier] {
+ m_game_button->setText(qname);
+ m_current_game_identifier = sync_identifier;
+ m_current_game_name = netplay_name;
UpdateDiscordPresence();
});
- DisplayMessage(tr("Game changed to \"%1\"").arg(qtitle), "magenta");
+ DisplayMessage(tr("Game changed to \"%1\"").arg(qname), "magenta");
}
void NetPlayDialog::GameStatusChanged(bool running)
@@ -859,7 +873,12 @@ void NetPlayDialog::OnMsgStartGame()
auto client = Settings::Instance().GetNetPlayClient();
if (client)
- client->StartGame(FindGame(m_current_game));
+ {
+ if (auto game = FindGameFile(m_current_game_identifier))
+ client->StartGame(game->GetFilePath());
+ else
+ PanicAlertT("Selected game doesn't exist in game list!");
+ }
UpdateDiscordPresence();
});
}
@@ -1017,29 +1036,24 @@ bool NetPlayDialog::IsRecording()
return false;
}
-std::string NetPlayDialog::FindGame(const std::string& game)
+std::shared_ptr<const UICommon::GameFile>
+NetPlayDialog::FindGameFile(const NetPlay::SyncIdentifier& sync_identifier,
+ NetPlay::SyncIdentifierComparison* found)
{
- std::optional<std::string> path = RunOnObject(this, [this, &game] {
- for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++)
- {
- if (m_game_list_model->GetUniqueIdentifier(i).toStdString() == game)
- return m_game_list_model->GetPath(i).toStdString();
- }
- return std::string("");
- });
- if (path)
- return *path;
- return std::string("");
-}
+ NetPlay::SyncIdentifierComparison temp;
+ if (!found)
+ found = &temp;
+
+ *found = NetPlay::SyncIdentifierComparison::DifferentGame;
-std::shared_ptr<const UICommon::GameFile> NetPlayDialog::FindGameFile(const std::string& game)
-{
std::optional<std::shared_ptr<const UICommon::GameFile>> game_file =
- RunOnObject(this, [this, &game] {
+ RunOnObject(this, [this, &sync_identifier, found] {
for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++)
{
- if (m_game_list_model->GetUniqueIdentifier(i).toStdString() == game)
- return m_game_list_model->GetGameFile(i);
+ auto game_file = m_game_list_model->GetGameFile(i);
+ *found = std::min(*found, game_file->CompareSyncIdentifier(sync_identifier));
+ if (*found == NetPlay::SyncIdentifierComparison::SameGame)
+ return game_file;
}
return static_cast<std::shared_ptr<const UICommon::GameFile>>(nullptr);
});
@@ -1126,15 +1140,15 @@ void NetPlayDialog::SaveSettings()
Config::SetBase(Config::NETPLAY_NETWORK_MODE, network_mode);
}
-void NetPlayDialog::ShowMD5Dialog(const std::string& file_identifier)
+void NetPlayDialog::ShowMD5Dialog(const std::string& title)
{
- QueueOnObject(this, [this, file_identifier] {
+ QueueOnObject(this, [this, title] {
m_md5_menu->setEnabled(false);
if (m_md5_dialog->isVisible())
m_md5_dialog->close();
- m_md5_dialog->show(QString::fromStdString(file_identifier));
+ m_md5_dialog->show(QString::fromStdString(title));
});
}