From 41e7c43d0d2809bf7f0bc99f6fac4bb4e20539ae Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 3 Oct 2016 05:35:27 -0700 Subject: [PATCH] NetPlay: add one click host Add a context menu entry in main game list to host a netplay game based on saved settings. Original commit: commit 91aaa958e6af0275c07b63443938a0be471e0669 Author: Aestek Date: Sun Jul 24 14:51:37 2016 +0200 --- Source/Core/DolphinWX/CMakeLists.txt | 1 + Source/Core/DolphinWX/DolphinWX.vcxproj | 2 + Source/Core/DolphinWX/GameListCtrl.cpp | 27 +++ Source/Core/DolphinWX/GameListCtrl.h | 1 + Source/Core/DolphinWX/Globals.h | 1 + Source/Core/DolphinWX/ISOFile.cpp | 35 ++++ Source/Core/DolphinWX/ISOFile.h | 1 + .../DolphinWX/NetPlay/NetPlayLauncher.cpp | 142 +++++++++++++ .../Core/DolphinWX/NetPlay/NetPlayLauncher.h | 54 +++++ .../DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 193 +++++------------- .../DolphinWX/NetPlay/NetPlaySetupFrame.h | 2 - Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 42 +--- 12 files changed, 319 insertions(+), 182 deletions(-) create mode 100644 Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp create mode 100644 Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index d9073287e2..9a01978bbc 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -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 diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index 31dc2180be..43bcc08c8a 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -91,6 +91,7 @@ + @@ -132,6 +133,7 @@ + diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index e382588b75..2bb88f10ab 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -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.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(arg); diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index 7d6275ed47..adf4a6f154 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -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); diff --git a/Source/Core/DolphinWX/Globals.h b/Source/Core/DolphinWX/Globals.h index 9b95f5a3e0..2aa26350a6 100644 --- a/Source/Core/DolphinWX/Globals.h +++ b/Source/Core/DolphinWX/Globals.h @@ -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, diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index 7173a6aeda..1b986c02c6 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -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 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(ss, ", ")); + ss << info.back(); + return name + " (" + ss.str() + ")"; +} + std::vector GameListItem::GetLanguages() const { std::vector languages; diff --git a/Source/Core/DolphinWX/ISOFile.h b/Source/Core/DolphinWX/ISOFile.h index e74e0add28..b5c19dd5ef 100644 --- a/Source/Core/DolphinWX/ISOFile.h +++ b/Source/Core/DolphinWX/ISOFile.h @@ -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 GetLanguages() const; diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp new file mode 100644 index 0000000000..8c1cab04df --- /dev/null +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp @@ -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(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(lport); + } + else + { + traversal_port = GetTraversalPortFromIniConfig(netplay_section); + traversal_host = GetTraversalHostFromIniConfig(netplay_section); + } +} \ No newline at end of file diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h new file mode 100644 index 0000000000..30d7807a72 --- /dev/null +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h @@ -0,0 +1,54 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#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); +}; \ No newline at end of file diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index c93515c069..b29205ac06 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -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(¢ralPort); - - 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.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( + 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(listen_port); } - std::string centralPortString = GetTraversalPort(netplay_section); - unsigned long int centralPort; - StrToWxStr(centralPortString).ToULong(¢ralPort); + 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.parent_window = m_parent; unsigned long port = 0; m_connect_port_text->GetValue().ToULong(&port); - MakeNetPlayDiag(port, "", false); + + join_config.connect_port = static_cast(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) diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h index 87fc1468a9..7518de6954 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h @@ -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; diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 7013beef06..18dabd91e2 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -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 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(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 "";