Merge pull request #4279 from shuffle2/Aestek-feature/netplay-oneclick

Aestek feature/netplay oneclick
This commit is contained in:
shuffle2 2016-10-03 16:13:29 -07:00 committed by GitHub
commit 20ebf03804
13 changed files with 350 additions and 183 deletions

View File

@ -36,6 +36,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

@ -91,6 +91,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" />
@ -132,6 +133,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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="GUI">
@ -205,6 +205,9 @@
<ClCompile Include="Cheats\ARCodeAddEdit.cpp">
<Filter>GUI\Cheats</Filter>
</ClCompile>
<ClCompile Include="NetPlay\NetPlayLauncher.cpp">
<Filter>GUI\NetPlay</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Main.h" />
@ -375,6 +378,9 @@
<ClInclude Include="Cheats\ARCodeAddEdit.h">
<Filter>GUI\Cheats</Filter>
</ClInclude>
<ClInclude Include="NetPlay\NetPlayLauncher.h">
<Filter>GUI\NetPlay</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />

View File

@ -59,6 +59,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
@ -176,6 +177,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);
}
@ -972,6 +974,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.SetDialogInfo(netplay_section, 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

@ -93,6 +93,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

@ -297,6 +297,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,161 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <wx/gdicmn.h>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
#include "DolphinWX/NetPlay/NetPlayLauncher.h"
#include "DolphinWX/NetPlay/NetWindow.h"
#include "DolphinWX/WxUtils.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->SetSize(config.window_pos);
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->SetSize(config.window_pos);
npd->Show();
return true;
}
else
{
npd->Destroy();
return false;
}
}
const std::string NetPlayLaunchConfig::DEFAULT_TRAVERSAL_HOST = "stun.dolphin-emu.org";
std::string
NetPlayLaunchConfig::GetTraversalHostFromIniConfig(const 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(const 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 NetPlayLaunchConfig::SetDialogInfo(const IniFile::Section& section, wxWindow* parent)
{
parent_window = parent;
section.Get("NetWindowPosX", &window_pos.x, window_defaults.GetX());
section.Get("NetWindowPosY", &window_pos.y, window_defaults.GetY());
section.Get("NetWindowWidth", &window_pos.width, window_defaults.GetWidth());
section.Get("NetWindowHeight", &window_pos.height, window_defaults.GetHeight());
if (window_pos.GetX() == window_defaults.GetX() || window_pos.GetY() == window_defaults.GetY())
{
// Center over toplevel dolphin window
window_pos = window_defaults.CenterIn(parent_window->GetScreenRect());
}
}
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,58 @@
// 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 wxRect;
class wxWindow;
class NetPlayLaunchConfig
{
public:
static std::string GetTraversalHostFromIniConfig(const IniFile::Section& netplay_section);
static u16 GetTraversalPortFromIniConfig(const IniFile::Section& netplay_section);
void SetDialogInfo(const IniFile::Section& section, wxWindow* parent);
static const std::string DEFAULT_TRAVERSAL_HOST;
static constexpr u16 DEFAULT_TRAVERSAL_PORT = 6262;
const wxRect window_defaults{wxDefaultCoord, wxDefaultCoord, 768, 768 - 128};
std::string player_name;
const CGameListCtrl* game_list_ctrl;
wxWindow* parent_window;
bool use_traversal;
std::string traversal_host;
u16 traversal_port;
wxRect window_pos{window_defaults};
};
class NetPlayHostConfig : public NetPlayLaunchConfig
{
public:
void FromIniConfig(IniFile::Section& netplay_section);
static constexpr u16 DEFAULT_LISTEN_PORT = 2626;
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,40 +19,17 @@
#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"
namespace
{
const std::string DEFAULT_TRAVERSAL_SERVER = "stun.dolphin-emu.org";
const std::string DEFAULT_TRAVERSAL_PORT = "6262";
std::string GetFromINI(IniFile::Section& section, const std::string& key,
const std::string& default_value)
{
std::string result;
section.Get(key, &result, default_value);
result.erase(std::remove(result.begin(), result.end(), ' '), result.end());
if (result.empty())
return default_value;
return result;
}
std::string GetTraversalPort(IniFile::Section& section)
{
return GetFromINI(section, "TraversalPort", DEFAULT_TRAVERSAL_PORT);
}
std::string GetTraversalServer(IniFile::Section& section)
{
return GetFromINI(section, "TraversalServer", DEFAULT_TRAVERSAL_SERVER);
}
wxString GetTraversalLabelText(IniFile::Section& section)
{
std::string server = GetTraversalServer(section);
std::string port = GetTraversalPort(section);
std::string server = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(section);
std::string port = std::to_string(NetPlayLaunchConfig::GetTraversalPortFromIniConfig(section));
return wxString::Format(_("Traversal Server: %s"), (server + ":" + port).c_str());
}
} // Anonymous namespace
@ -144,7 +121,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"));
@ -184,7 +162,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: "));
@ -304,63 +282,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);
unsigned long int centralPort;
StrToWxStr(centralPortString).ToULong(&centralPort);
std::string centralServer = GetTraversalServer(netplay_section);
netplay_client = new NetPlayClient(ip, (u16)port, npd, WxStrToStr(m_nickname_text->GetValue()),
trav, centralServer, (u16)centralPort);
if (netplay_client->IsConnected())
{
int winPosX, winPosY, winWidth, winHeight;
// Remember the window size and position for NetWindow
netplay_section.Get("NetWindowPosX", &winPosX, -1);
netplay_section.Get("NetWindowPosY", &winPosY, -1);
netplay_section.Get("NetWindowWidth", &winWidth, 768);
netplay_section.Get("NetWindowHeight", &winHeight, 768 - 128);
if (winPosX == -1 || winPosY == -1)
{
npd->SetSize(768, 768 - 128);
npd->Center();
}
else
{
npd->SetSize(winPosX, winPosY, winWidth, winHeight);
}
npd->Show();
Destroy();
}
else
{
npd->Destroy();
}
}
void NetPlaySetupFrame::OnHost(wxCommandEvent&)
{
DoHost();
@ -368,71 +289,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.SetDialogInfo(netplay_section, 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);
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);
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();
}
}
@ -443,16 +339,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.SetDialogInfo(netplay_section, 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)

View File

@ -29,6 +29,7 @@ private:
static constexpr int DIRECT_CHOICE = 0;
static constexpr int TRAVERSAL_CHOICE = 1;
void GetWindowRect(const IniFile::Section& section, wxRect* rect) const;
void OnJoin(wxCommandEvent& event);
void OnHost(wxCommandEvent& event);
void DoJoin();
@ -42,8 +43,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,
@ -307,7 +269,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 "";