NetPlay: add one click host

Add a context menu entry in main game list to host a netplay game
based on saved settings.
This commit is contained in:
Aestek 2016-07-24 14:51:37 +02:00
parent be9416c462
commit 91aaa958e6
12 changed files with 326 additions and 168 deletions

View File

@ -35,6 +35,7 @@ set(GUI_SRCS
Debugger/WatchWindow.cpp
NetPlay/ChangeGameDialog.cpp
NetPlay/MD5Dialog.cpp
NetPlay/NetPlayLauncher.cpp
NetPlay/NetPlaySetupFrame.cpp
NetPlay/NetWindow.cpp
NetPlay/PadMapDialog.cpp

View File

@ -90,6 +90,7 @@
<ClCompile Include="Debugger\WatchWindow.cpp" />
<ClCompile Include="NetPlay\ChangeGameDialog.cpp" />
<ClCompile Include="NetPlay\MD5Dialog.cpp" />
<ClCompile Include="NetPlay\NetPlayLauncher.cpp" />
<ClCompile Include="NetPlay\NetPlaySetupFrame.cpp" />
<ClCompile Include="NetPlay\NetWindow.cpp" />
<ClCompile Include="FifoPlayerDlg.cpp" />
@ -129,6 +130,7 @@
<ClInclude Include="Config\WiiConfigPane.h" />
<ClInclude Include="NetPlay\ChangeGameDialog.h" />
<ClInclude Include="NetPlay\MD5Dialog.h" />
<ClInclude Include="NetPlay\NetPlayLauncher.h" />
<ClInclude Include="NetPlay\NetPlaySetupFrame.h" />
<ClInclude Include="NetPlay\PadMapDialog.h" />
<ClInclude Include="resource.h" />

View File

@ -54,6 +54,7 @@
#include "DolphinWX/ISOFile.h"
#include "DolphinWX/ISOProperties.h"
#include "DolphinWX/Main.h"
#include "DolphinWX/NetPlay/NetPlayLauncher.h"
#include "DolphinWX/WxUtils.h"
struct CompressionProgress final
@ -171,6 +172,7 @@ CGameListCtrl::CGameListCtrl(wxWindow* parent, const wxWindowID id, const wxPoin
Bind(wxEVT_MENU, &CGameListCtrl::OnMultiDecompressISO, this, IDM_MULTI_DECOMPRESS_ISO);
Bind(wxEVT_MENU, &CGameListCtrl::OnDeleteISO, this, IDM_DELETE_ISO);
Bind(wxEVT_MENU, &CGameListCtrl::OnChangeDisc, this, IDM_LIST_CHANGE_DISC);
Bind(wxEVT_MENU, &CGameListCtrl::OnNetPlayHost, this, IDM_START_NETPLAY);
wxTheApp->Bind(DOLPHIN_EVT_LOCAL_INI_CHANGED, &CGameListCtrl::OnLocalIniModified, this);
}
@ -968,6 +970,8 @@ void CGameListCtrl::OnRightClick(wxMouseEvent& event)
if (platform == DiscIO::Platform::WII_WAD)
popupMenu.Append(IDM_LIST_INSTALL_WAD, _("Install to Wii Menu"));
popupMenu.Append(IDM_START_NETPLAY, _("Host with Netplay"));
PopupMenu(&popupMenu);
}
}
@ -1119,6 +1123,29 @@ void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED(event))
WxUtils::Launch(wikiUrl);
}
void CGameListCtrl::OnNetPlayHost(wxCommandEvent& WXUNUSED(event))
{
const GameListItem* iso = GetSelectedISO();
if (!iso)
return;
IniFile ini_file;
const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX);
ini_file.Load(dolphin_ini);
IniFile::Section& netplay_section = *ini_file.GetOrCreateSection("NetPlay");
NetPlayHostConfig config;
config.FromIniConfig(netplay_section);
config.game_name = iso->GetUniqueIdentifier();
config.game_list_ctrl = this;
config.parent_window = m_parent;
netplay_section.Set("SelectedHostGame", config.game_name);
ini_file.Save(dolphin_ini);
NetPlayLauncher::Host(config);
}
bool CGameListCtrl::MultiCompressCB(const std::string& text, float percent, void* arg)
{
CompressionProgress* progress = static_cast<CompressionProgress*>(arg);

View File

@ -96,6 +96,7 @@ private:
void OnSize(wxSizeEvent& event);
void OnProperties(wxCommandEvent& event);
void OnWiki(wxCommandEvent& event);
void OnNetPlayHost(wxCommandEvent& event);
void OnOpenContainingFolder(wxCommandEvent& event);
void OnOpenSaveFolder(wxCommandEvent& event);
void OnExportSave(wxCommandEvent& event);

View File

@ -295,6 +295,7 @@ enum
IDM_SET_DEFAULT_ISO,
IDM_DELETE_ISO,
IDM_COMPRESS_ISO,
IDM_START_NETPLAY,
IDM_MULTI_COMPRESS_ISO,
IDM_MULTI_DECOMPRESS_ISO,
IDM_UPDATE_DISASM_DIALOG,

View File

@ -330,6 +330,41 @@ std::string GameListItem::GetName() const
return name + ext;
}
std::string GameListItem::GetUniqueIdentifier() const
{
const DiscIO::Language lang = DiscIO::Language::LANGUAGE_ENGLISH;
std::vector<std::string> info;
if (!GetUniqueID().empty())
info.push_back(GetUniqueID());
if (GetRevision() != 0)
{
std::string rev_str = "Revision ";
info.push_back(rev_str + std::to_string((long long)GetRevision()));
}
std::string name(GetName(lang));
if (name.empty())
name = GetName();
int disc_number = GetDiscNumber() + 1;
std::string lower_name = name;
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
if (disc_number > 1 &&
lower_name.find(std::string(wxString::Format("disc %i", disc_number))) == std::string::npos &&
lower_name.find(std::string(wxString::Format("disc%i", disc_number))) == std::string::npos)
{
std::string disc_text = "Disc ";
info.push_back(disc_text + std::to_string(disc_number));
}
if (info.empty())
return name;
std::ostringstream ss;
std::copy(info.begin(), info.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
ss << info.back();
return name + " (" + ss.str() + ")";
}
std::vector<DiscIO::Language> GameListItem::GetLanguages() const
{
std::vector<DiscIO::Language> languages;

View File

@ -40,6 +40,7 @@ public:
const std::string& GetFileName() const { return m_FileName; }
std::string GetName(DiscIO::Language language) const;
std::string GetName() const;
std::string GetUniqueIdentifier() const;
std::string GetDescription(DiscIO::Language language) const;
std::string GetDescription() const;
std::vector<DiscIO::Language> GetLanguages() const;

View File

@ -0,0 +1,142 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "NetPlayLauncher.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
#include "DolphinWX/WxUtils.h"
#include "NetWindow.h"
bool NetPlayLauncher::Host(const NetPlayHostConfig& config)
{
NetPlayDialog*& npd = NetPlayDialog::GetInstance();
NetPlayServer*& netplay_server = NetPlayDialog::GetNetPlayServer();
if (npd)
{
WxUtils::ShowErrorDialog(_("A NetPlay window is already open!"));
return false;
}
netplay_server = new NetPlayServer(config.listen_port, config.use_traversal,
config.traversal_host, config.traversal_port);
if (!netplay_server->is_connected)
{
WxUtils::ShowErrorDialog(
_("Failed to listen. Is another instance of the NetPlay server running?"));
return false;
}
netplay_server->ChangeGame(config.game_name);
#ifdef USE_UPNP
if (config.forward_port)
{
netplay_server->TryPortmapping(config.listen_port);
}
#endif
npd = new NetPlayDialog(config.parent_window, config.game_list_ctrl, config.game_name, true);
NetPlayClient*& netplay_client = NetPlayDialog::GetNetPlayClient();
netplay_client =
new NetPlayClient("127.0.0.1", netplay_server->GetPort(), npd, config.player_name, false,
config.traversal_host, config.traversal_port);
if (netplay_client->IsConnected())
{
npd->Show();
netplay_server->SetNetPlayUI(NetPlayDialog::GetInstance());
return true;
}
else
{
npd->Destroy();
return false;
}
}
bool NetPlayLauncher::Join(const NetPlayJoinConfig& config)
{
NetPlayDialog*& npd = NetPlayDialog::GetInstance();
NetPlayClient*& netplay_client = NetPlayDialog::GetNetPlayClient();
npd = new NetPlayDialog(config.parent_window, config.game_list_ctrl, "", false);
std::string host;
if (config.use_traversal)
host = config.connect_hash_code;
else
host = config.connect_host;
netplay_client =
new NetPlayClient(host, config.connect_port, npd, config.player_name, config.use_traversal,
config.traversal_host, config.traversal_port);
if (netplay_client->IsConnected())
{
npd->Show();
return true;
}
else
{
npd->Destroy();
return false;
}
}
const std::string NetPlayLaunchConfig::DEFAULT_TRAVERSAL_HOST = "stun.dolphin-emu.org";
const u16 NetPlayLaunchConfig::DEFAULT_TRAVERSAL_PORT = 6262;
const u16 NetPlayHostConfig::DEFAULT_LISTEN_PORT = 2626;
std::string NetPlayLaunchConfig::GetTraversalHostFromIniConfig(IniFile::Section& netplay_section)
{
std::string host;
netplay_section.Get("TraversalServer", &host, DEFAULT_TRAVERSAL_HOST);
host = StripSpaces(host);
if (host.empty())
return DEFAULT_TRAVERSAL_HOST;
return host;
}
u16 NetPlayLaunchConfig::GetTraversalPortFromIniConfig(IniFile::Section& netplay_section)
{
std::string port_str;
unsigned long port;
netplay_section.Get("TraversalPort", &port_str, std::to_string(DEFAULT_TRAVERSAL_PORT));
StrToWxStr(port_str).ToULong(&port);
if (port == 0)
port = DEFAULT_TRAVERSAL_PORT;
return static_cast<u16>(port);
}
void NetPlayHostConfig::FromIniConfig(IniFile::Section& netplay_section)
{
std::string traversal_choice_setting;
netplay_section.Get("TraversalChoice", &traversal_choice_setting, "direct");
use_traversal = traversal_choice_setting == "traversal";
if (!use_traversal)
{
unsigned long lport = 0;
std::string port_setting;
netplay_section.Get("HostPort", &port_setting, std::to_string(DEFAULT_LISTEN_PORT));
StrToWxStr(port_setting).ToULong(&lport);
listen_port = static_cast<u16>(lport);
}
else
{
traversal_port = GetTraversalPortFromIniConfig(netplay_section);
traversal_host = GetTraversalHostFromIniConfig(netplay_section);
}
}

View File

@ -0,0 +1,54 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <string>
#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
class CGameListCtrl;
class wxWindow;
class NetPlayLaunchConfig
{
public:
static std::string GetTraversalHostFromIniConfig(IniFile::Section& netplay_section);
static u16 GetTraversalPortFromIniConfig(IniFile::Section& netplay_section);
static const std::string DEFAULT_TRAVERSAL_HOST;
static const u16 DEFAULT_TRAVERSAL_PORT;
std::string player_name;
const CGameListCtrl* game_list_ctrl;
wxWindow* parent_window;
bool use_traversal;
std::string traversal_host;
u16 traversal_port;
};
class NetPlayHostConfig : public NetPlayLaunchConfig
{
public:
void FromIniConfig(IniFile::Section& netplay_section);
static const u16 DEFAULT_LISTEN_PORT;
std::string game_name;
u16 listen_port = 0;
bool forward_port;
};
class NetPlayJoinConfig : public NetPlayLaunchConfig
{
public:
std::string connect_host;
u16 connect_port;
std::string connect_hash_code;
};
class NetPlayLauncher
{
public:
static bool Host(const NetPlayHostConfig& config);
static bool Join(const NetPlayJoinConfig& config);
};

View File

@ -19,26 +19,11 @@
#include "Core/NetPlayServer.h"
#include "DolphinWX/Frame.h"
#include "DolphinWX/Main.h"
#include "DolphinWX/NetPlay/NetPlayLauncher.h"
#include "DolphinWX/NetPlay/NetPlaySetupFrame.h"
#include "DolphinWX/NetPlay/NetWindow.h"
#include "DolphinWX/WxUtils.h"
static void GetTraversalPort(IniFile::Section& section, std::string* port)
{
section.Get("TraversalPort", port, "6262");
port->erase(std::remove(port->begin(), port->end(), ' '), port->end());
if (port->empty())
*port = "6262";
}
static void GetTraversalServer(IniFile::Section& section, std::string* server)
{
section.Get("TraversalServer", server, "stun.dolphin-emu.org");
server->erase(std::remove(server->begin(), server->end(), ' '), server->end());
if (server->empty())
*server = "stun.dolphin-emu.org";
}
NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl* const game_list)
: wxFrame(parent, wxID_ANY, _("Dolphin NetPlay Setup")), m_game_list(game_list)
{
@ -98,13 +83,11 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
m_direct_traversal->Select(DIRECT_CHOICE);
}
std::string centralPort;
GetTraversalPort(netplay_section, &centralPort);
std::string centralServer;
GetTraversalServer(netplay_section, &centralServer);
m_traversal_lbl = new wxStaticText(panel, wxID_ANY, _("Traversal Server:") + " " +
centralServer + ":" + centralPort);
m_traversal_lbl = new wxStaticText(
panel, wxID_ANY,
_("Traversal Server:") + " " +
NetPlayLaunchConfig::GetTraversalHostFromIniConfig(netplay_section) + ":" +
std::to_string(NetPlayLaunchConfig::GetTraversalPortFromIniConfig(netplay_section)));
}
// tabs
m_notebook = new wxNotebook(panel, wxID_ANY);
@ -132,7 +115,8 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
// string? w/e
std::string port;
netplay_section.Get("ConnectPort", &port, "2626");
netplay_section.Get("ConnectPort", &port,
std::to_string(NetPlayHostConfig::DEFAULT_LISTEN_PORT));
m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port));
wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect"));
@ -172,7 +156,7 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
// string? w/e
std::string port;
netplay_section.Get("HostPort", &port, "2626");
netplay_section.Get("HostPort", &port, std::to_string(NetPlayHostConfig::DEFAULT_LISTEN_PORT));
m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, StrToWxStr(port));
m_traversal_listen_port_enabled = new wxCheckBox(host_tab, wxID_ANY, _("Force Listen Port: "));
@ -292,47 +276,6 @@ NetPlaySetupFrame::~NetPlaySetupFrame()
main_frame->g_NetPlaySetupDiag = nullptr;
}
void NetPlaySetupFrame::MakeNetPlayDiag(int port, const std::string& game, bool is_hosting)
{
NetPlayDialog*& npd = NetPlayDialog::GetInstance();
NetPlayClient*& netplay_client = NetPlayDialog::GetNetPlayClient();
bool trav = !is_hosting && m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE;
std::string ip;
npd = new NetPlayDialog(m_parent, m_game_list, game, is_hosting);
if (is_hosting)
ip = "127.0.0.1";
else if (trav)
ip = WxStrToStr(m_connect_hashcode_text->GetValue());
else
ip = WxStrToStr(m_connect_ip_text->GetValue());
IniFile inifile;
inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
std::string centralPortString;
GetTraversalPort(netplay_section, &centralPortString);
unsigned long int centralPort;
StrToWxStr(centralPortString).ToULong(&centralPort);
std::string centralServer;
GetTraversalServer(netplay_section, &centralServer);
netplay_client = new NetPlayClient(ip, (u16)port, npd, WxStrToStr(m_nickname_text->GetValue()),
trav, centralServer, (u16)centralPort);
if (netplay_client->IsConnected())
{
npd->Show();
Destroy();
}
else
{
npd->Destroy();
}
}
void NetPlaySetupFrame::OnHost(wxCommandEvent&)
{
DoHost();
@ -340,73 +283,46 @@ void NetPlaySetupFrame::OnHost(wxCommandEvent&)
void NetPlaySetupFrame::DoHost()
{
IniFile ini_file;
const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX);
ini_file.Load(dolphin_ini);
IniFile::Section& netplay_section = *ini_file.GetOrCreateSection("NetPlay");
NetPlayDialog*& npd = NetPlayDialog::GetInstance();
NetPlayServer*& netplay_server = NetPlayDialog::GetNetPlayServer();
if (npd)
{
WxUtils::ShowErrorDialog(_("A NetPlay window is already open!"));
return;
}
if (m_game_lbox->GetSelection() == wxNOT_FOUND)
{
WxUtils::ShowErrorDialog(_("You must choose a game!"));
return;
}
std::string game(WxStrToStr(m_game_lbox->GetStringSelection()));
IniFile ini_file;
const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX);
ini_file.Load(dolphin_ini);
IniFile::Section& netplay_section = *ini_file.GetOrCreateSection("NetPlay");
bool trav;
unsigned long listen_port = 0;
if (m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE)
NetPlayHostConfig host_config;
host_config.game_name = WxStrToStr(m_game_lbox->GetStringSelection());
host_config.use_traversal = m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE;
host_config.player_name = WxStrToStr(m_nickname_text->GetValue());
host_config.game_list_ctrl = m_game_list;
host_config.parent_window = m_parent;
host_config.forward_port = m_upnp_chk->GetValue();
if (host_config.use_traversal)
{
trav = true;
listen_port =
m_traversal_listen_port_enabled->IsChecked() ? m_traversal_listen_port->GetValue() : 0;
host_config.listen_port = static_cast<u16>(
m_traversal_listen_port_enabled->IsChecked() ? m_traversal_listen_port->GetValue() : 0);
}
else
{
trav = false;
unsigned long listen_port;
m_host_port_text->GetValue().ToULong(&listen_port);
host_config.listen_port = static_cast<u16>(listen_port);
}
std::string centralPortString;
GetTraversalPort(netplay_section, &centralPortString);
unsigned long int centralPort;
StrToWxStr(centralPortString).ToULong(&centralPort);
host_config.traversal_port = NetPlayLaunchConfig::GetTraversalPortFromIniConfig(netplay_section);
host_config.traversal_host = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(netplay_section);
std::string centralServer;
GetTraversalServer(netplay_section, &centralServer);
netplay_section.Set("SelectedHostGame", host_config.game_name);
ini_file.Save(dolphin_ini);
netplay_server = new NetPlayServer((u16)listen_port, trav, centralServer, (u16)centralPort);
if (netplay_server->is_connected)
if (NetPlayLauncher::Host(host_config))
{
netplay_server->ChangeGame(game);
netplay_server->AdjustPadBufferSize(INITIAL_PAD_BUFFER_SIZE);
#ifdef USE_UPNP
if (m_upnp_chk->GetValue())
netplay_server->TryPortmapping(listen_port);
#endif
MakeNetPlayDiag(netplay_server->GetPort(), game, true);
netplay_server->SetNetPlayUI(NetPlayDialog::GetInstance());
netplay_section.Set("SelectedHostGame", game);
ini_file.Save(dolphin_ini);
}
else
{
if (trav && m_traversal_listen_port_enabled->IsChecked())
WxUtils::ShowErrorDialog(
_("Failed to listen. Someone is probably already listening on the port you specified."));
else
WxUtils::ShowErrorDialog(
_("Failed to listen. Is another instance of the NetPlay server running?"));
Destroy();
}
}
@ -417,16 +333,33 @@ void NetPlaySetupFrame::OnJoin(wxCommandEvent&)
void NetPlaySetupFrame::DoJoin()
{
NetPlayDialog*& npd = NetPlayDialog::GetInstance();
if (npd)
{
WxUtils::ShowErrorDialog(_("A NetPlay window is already open!"));
return;
}
IniFile inifile;
inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
NetPlayJoinConfig join_config;
join_config.use_traversal = m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE;
join_config.player_name = WxStrToStr(m_nickname_text->GetValue());
join_config.game_list_ctrl = m_game_list;
join_config.parent_window = m_parent;
unsigned long port = 0;
m_connect_port_text->GetValue().ToULong(&port);
MakeNetPlayDiag(port, "", false);
join_config.connect_port = static_cast<u16>(port);
if (join_config.use_traversal)
join_config.connect_hash_code = WxStrToStr(m_connect_hashcode_text->GetValue());
else
join_config.connect_host = WxStrToStr(m_connect_ip_text->GetValue());
join_config.traversal_port = NetPlayLaunchConfig::GetTraversalPortFromIniConfig(netplay_section);
join_config.traversal_host = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(netplay_section);
if (NetPlayLauncher::Join(join_config))
{
Destroy();
}
}
void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event)
@ -435,11 +368,12 @@ void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event)
const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX);
inifile.Load(dolphin_ini);
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
netplay_section.Set("TraversalServer", (std::string) "stun.dolphin-emu.org");
netplay_section.Set("TraversalPort", (std::string) "6262");
netplay_section.Set("TraversalServer", NetPlayLaunchConfig::DEFAULT_TRAVERSAL_HOST);
netplay_section.Set("TraversalPort", std::to_string(NetPlayLaunchConfig::DEFAULT_TRAVERSAL_PORT));
inifile.Save(dolphin_ini);
m_traversal_lbl->SetLabelText(_("Traversal: ") + "stun.dolphin-emu.org:6262");
m_traversal_lbl->SetLabelText(_("Traversal: ") + NetPlayLaunchConfig::DEFAULT_TRAVERSAL_HOST +
":" + std::to_string(NetPlayLaunchConfig::DEFAULT_TRAVERSAL_PORT));
}
void NetPlaySetupFrame::OnTraversalListenPortChanged(wxCommandEvent& event)

View File

@ -42,8 +42,6 @@ private:
void OnAfterTabChange(wxIdleEvent& event);
void DispatchFocus();
void MakeNetPlayDiag(int port, const std::string& game, bool is_hosting);
wxStaticText* m_ip_lbl;
wxStaticText* m_client_port_lbl;
wxTextCtrl* m_nickname_text;

View File

@ -37,8 +37,6 @@
#include "Core/NetPlayProto.h"
#include "Core/NetPlayServer.h"
#include "DiscIO/Enums.h"
#include "DolphinWX/Frame.h"
#include "DolphinWX/GameListCtrl.h"
#include "DolphinWX/ISOFile.h"
@ -56,46 +54,10 @@ NetPlayServer* NetPlayDialog::netplay_server = nullptr;
NetPlayClient* NetPlayDialog::netplay_client = nullptr;
NetPlayDialog* NetPlayDialog::npd = nullptr;
static std::string BuildGameName(const GameListItem& game)
{
// Lang needs to be consistent
const DiscIO::Language lang = DiscIO::Language::LANGUAGE_ENGLISH;
std::vector<std::string> info;
if (!game.GetUniqueID().empty())
info.push_back(game.GetUniqueID());
if (game.GetRevision() != 0)
{
std::string rev_str = "Revision ";
info.push_back(rev_str + std::to_string((long long)game.GetRevision()));
}
std::string name(game.GetName(lang));
if (name.empty())
name = game.GetName();
int disc_number = game.GetDiscNumber() + 1;
std::string lower_name = name;
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
if (disc_number > 1 &&
lower_name.find(std::string(wxString::Format("disc %i", disc_number))) == std::string::npos &&
lower_name.find(std::string(wxString::Format("disc%i", disc_number))) == std::string::npos)
{
std::string disc_text = "Disc ";
info.push_back(disc_text + std::to_string(disc_number));
}
if (info.empty())
return name;
std::ostringstream ss;
std::copy(info.begin(), info.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
ss << info.back();
return name + " (" + ss.str() + ")";
}
void NetPlayDialog::FillWithGameNames(wxListBox* game_lbox, const CGameListCtrl& game_list)
{
for (u32 i = 0; auto game = game_list.GetISO(i); ++i)
game_lbox->Append(StrToWxStr(BuildGameName(*game)));
game_lbox->Append(StrToWxStr(game->GetUniqueIdentifier()));
}
NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const game_list,
@ -298,7 +260,7 @@ std::string NetPlayDialog::FindGame(const std::string& target_game)
{
// find path for selected game, sloppy..
for (u32 i = 0; auto game = m_game_list->GetISO(i); ++i)
if (target_game == BuildGameName(*game))
if (target_game == game->GetUniqueIdentifier())
return game->GetFileName();
return "";