diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 9e89e73987..d8dd0e2af8 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -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 diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index 56b5ed630a..59fc10765d 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -90,6 +90,7 @@ + @@ -129,6 +130,7 @@ + diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index cbbd4ad6b7..9c7b17cb44 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -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(arg); diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index 4c23aa5941..07892426d6 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -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); diff --git a/Source/Core/DolphinWX/Globals.h b/Source/Core/DolphinWX/Globals.h index 5779334918..5661985ef9 100644 --- a/Source/Core/DolphinWX/Globals.h +++ b/Source/Core/DolphinWX/Globals.h @@ -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, 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 a1126429d6..ed99cc7816 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -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, ¢ralPort); - std::string centralServer; - GetTraversalServer(netplay_section, ¢ralServer); - - 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, ¢ralPortString); - unsigned long int centralPort; - StrToWxStr(centralPortString).ToULong(¢ralPort); - - std::string centralServer; - GetTraversalServer(netplay_section, ¢ralServer); - - 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( + 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, ¢ralPortString); - 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, ¢ralServer); + 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(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) 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 200597b9ca..05f7cab98b 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, @@ -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 "";