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 91aaa958e6
Author: Aestek <thib.gilles@gmail.com>
Date: Sun Jul 24 14:51:37 2016 +0200
This commit is contained in:
parent
46b6a32b46
commit
41e7c43d0d
|
@ -36,6 +36,7 @@ set(GUI_SRCS
|
||||||
Debugger/WatchWindow.cpp
|
Debugger/WatchWindow.cpp
|
||||||
NetPlay/ChangeGameDialog.cpp
|
NetPlay/ChangeGameDialog.cpp
|
||||||
NetPlay/MD5Dialog.cpp
|
NetPlay/MD5Dialog.cpp
|
||||||
|
NetPlay/NetPlayLauncher.cpp
|
||||||
NetPlay/NetPlaySetupFrame.cpp
|
NetPlay/NetPlaySetupFrame.cpp
|
||||||
NetPlay/NetWindow.cpp
|
NetPlay/NetWindow.cpp
|
||||||
NetPlay/PadMapDialog.cpp
|
NetPlay/PadMapDialog.cpp
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
<ClCompile Include="Debugger\WatchWindow.cpp" />
|
<ClCompile Include="Debugger\WatchWindow.cpp" />
|
||||||
<ClCompile Include="NetPlay\ChangeGameDialog.cpp" />
|
<ClCompile Include="NetPlay\ChangeGameDialog.cpp" />
|
||||||
<ClCompile Include="NetPlay\MD5Dialog.cpp" />
|
<ClCompile Include="NetPlay\MD5Dialog.cpp" />
|
||||||
|
<ClCompile Include="NetPlay\NetPlayLauncher.cpp" />
|
||||||
<ClCompile Include="NetPlay\NetPlaySetupFrame.cpp" />
|
<ClCompile Include="NetPlay\NetPlaySetupFrame.cpp" />
|
||||||
<ClCompile Include="NetPlay\NetWindow.cpp" />
|
<ClCompile Include="NetPlay\NetWindow.cpp" />
|
||||||
<ClCompile Include="FifoPlayerDlg.cpp" />
|
<ClCompile Include="FifoPlayerDlg.cpp" />
|
||||||
|
@ -132,6 +133,7 @@
|
||||||
<ClInclude Include="Config\WiiConfigPane.h" />
|
<ClInclude Include="Config\WiiConfigPane.h" />
|
||||||
<ClInclude Include="NetPlay\ChangeGameDialog.h" />
|
<ClInclude Include="NetPlay\ChangeGameDialog.h" />
|
||||||
<ClInclude Include="NetPlay\MD5Dialog.h" />
|
<ClInclude Include="NetPlay\MD5Dialog.h" />
|
||||||
|
<ClInclude Include="NetPlay\NetPlayLauncher.h" />
|
||||||
<ClInclude Include="NetPlay\NetPlaySetupFrame.h" />
|
<ClInclude Include="NetPlay\NetPlaySetupFrame.h" />
|
||||||
<ClInclude Include="NetPlay\PadMapDialog.h" />
|
<ClInclude Include="NetPlay\PadMapDialog.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
#include "DolphinWX/ISOFile.h"
|
#include "DolphinWX/ISOFile.h"
|
||||||
#include "DolphinWX/ISOProperties.h"
|
#include "DolphinWX/ISOProperties.h"
|
||||||
#include "DolphinWX/Main.h"
|
#include "DolphinWX/Main.h"
|
||||||
|
#include "DolphinWX/NetPlay/NetPlayLauncher.h"
|
||||||
#include "DolphinWX/WxUtils.h"
|
#include "DolphinWX/WxUtils.h"
|
||||||
|
|
||||||
struct CompressionProgress final
|
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::OnMultiDecompressISO, this, IDM_MULTI_DECOMPRESS_ISO);
|
||||||
Bind(wxEVT_MENU, &CGameListCtrl::OnDeleteISO, this, IDM_DELETE_ISO);
|
Bind(wxEVT_MENU, &CGameListCtrl::OnDeleteISO, this, IDM_DELETE_ISO);
|
||||||
Bind(wxEVT_MENU, &CGameListCtrl::OnChangeDisc, this, IDM_LIST_CHANGE_DISC);
|
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);
|
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)
|
if (platform == DiscIO::Platform::WII_WAD)
|
||||||
popupMenu.Append(IDM_LIST_INSTALL_WAD, _("Install to Wii Menu"));
|
popupMenu.Append(IDM_LIST_INSTALL_WAD, _("Install to Wii Menu"));
|
||||||
|
|
||||||
|
popupMenu.Append(IDM_START_NETPLAY, _("Host with Netplay"));
|
||||||
|
|
||||||
PopupMenu(&popupMenu);
|
PopupMenu(&popupMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1119,6 +1123,29 @@ void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED(event))
|
||||||
WxUtils::Launch(wikiUrl);
|
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)
|
bool CGameListCtrl::MultiCompressCB(const std::string& text, float percent, void* arg)
|
||||||
{
|
{
|
||||||
CompressionProgress* progress = static_cast<CompressionProgress*>(arg);
|
CompressionProgress* progress = static_cast<CompressionProgress*>(arg);
|
||||||
|
|
|
@ -93,6 +93,7 @@ private:
|
||||||
void OnSize(wxSizeEvent& event);
|
void OnSize(wxSizeEvent& event);
|
||||||
void OnProperties(wxCommandEvent& event);
|
void OnProperties(wxCommandEvent& event);
|
||||||
void OnWiki(wxCommandEvent& event);
|
void OnWiki(wxCommandEvent& event);
|
||||||
|
void OnNetPlayHost(wxCommandEvent& event);
|
||||||
void OnOpenContainingFolder(wxCommandEvent& event);
|
void OnOpenContainingFolder(wxCommandEvent& event);
|
||||||
void OnOpenSaveFolder(wxCommandEvent& event);
|
void OnOpenSaveFolder(wxCommandEvent& event);
|
||||||
void OnExportSave(wxCommandEvent& event);
|
void OnExportSave(wxCommandEvent& event);
|
||||||
|
|
|
@ -297,6 +297,7 @@ enum
|
||||||
IDM_SET_DEFAULT_ISO,
|
IDM_SET_DEFAULT_ISO,
|
||||||
IDM_DELETE_ISO,
|
IDM_DELETE_ISO,
|
||||||
IDM_COMPRESS_ISO,
|
IDM_COMPRESS_ISO,
|
||||||
|
IDM_START_NETPLAY,
|
||||||
IDM_MULTI_COMPRESS_ISO,
|
IDM_MULTI_COMPRESS_ISO,
|
||||||
IDM_MULTI_DECOMPRESS_ISO,
|
IDM_MULTI_DECOMPRESS_ISO,
|
||||||
IDM_UPDATE_DISASM_DIALOG,
|
IDM_UPDATE_DISASM_DIALOG,
|
||||||
|
|
|
@ -330,6 +330,41 @@ std::string GameListItem::GetName() const
|
||||||
return name + ext;
|
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> GameListItem::GetLanguages() const
|
||||||
{
|
{
|
||||||
std::vector<DiscIO::Language> languages;
|
std::vector<DiscIO::Language> languages;
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
const std::string& GetFileName() const { return m_FileName; }
|
const std::string& GetFileName() const { return m_FileName; }
|
||||||
std::string GetName(DiscIO::Language language) const;
|
std::string GetName(DiscIO::Language language) const;
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
|
std::string GetUniqueIdentifier() const;
|
||||||
std::string GetDescription(DiscIO::Language language) const;
|
std::string GetDescription(DiscIO::Language language) const;
|
||||||
std::string GetDescription() const;
|
std::string GetDescription() const;
|
||||||
std::vector<DiscIO::Language> GetLanguages() const;
|
std::vector<DiscIO::Language> GetLanguages() const;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
};
|
|
@ -19,40 +19,17 @@
|
||||||
#include "Core/NetPlayServer.h"
|
#include "Core/NetPlayServer.h"
|
||||||
#include "DolphinWX/Frame.h"
|
#include "DolphinWX/Frame.h"
|
||||||
#include "DolphinWX/Main.h"
|
#include "DolphinWX/Main.h"
|
||||||
|
#include "DolphinWX/NetPlay/NetPlayLauncher.h"
|
||||||
#include "DolphinWX/NetPlay/NetPlaySetupFrame.h"
|
#include "DolphinWX/NetPlay/NetPlaySetupFrame.h"
|
||||||
#include "DolphinWX/NetPlay/NetWindow.h"
|
#include "DolphinWX/NetPlay/NetWindow.h"
|
||||||
#include "DolphinWX/WxUtils.h"
|
#include "DolphinWX/WxUtils.h"
|
||||||
|
|
||||||
namespace
|
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)
|
wxString GetTraversalLabelText(IniFile::Section& section)
|
||||||
{
|
{
|
||||||
std::string server = GetTraversalServer(section);
|
std::string server = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(section);
|
||||||
std::string port = GetTraversalPort(section);
|
std::string port = std::to_string(NetPlayLaunchConfig::GetTraversalPortFromIniConfig(section));
|
||||||
return wxString::Format(_("Traversal Server: %s"), (server + ":" + port).c_str());
|
return wxString::Format(_("Traversal Server: %s"), (server + ":" + port).c_str());
|
||||||
}
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
@ -144,7 +121,8 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
|
||||||
|
|
||||||
// string? w/e
|
// string? w/e
|
||||||
std::string port;
|
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));
|
m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port));
|
||||||
|
|
||||||
wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect"));
|
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
|
// string? w/e
|
||||||
std::string port;
|
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_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: "));
|
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;
|
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&)
|
void NetPlaySetupFrame::OnHost(wxCommandEvent&)
|
||||||
{
|
{
|
||||||
DoHost();
|
DoHost();
|
||||||
|
@ -368,71 +289,46 @@ void NetPlaySetupFrame::OnHost(wxCommandEvent&)
|
||||||
|
|
||||||
void NetPlaySetupFrame::DoHost()
|
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)
|
if (m_game_lbox->GetSelection() == wxNOT_FOUND)
|
||||||
{
|
{
|
||||||
WxUtils::ShowErrorDialog(_("You must choose a game!"));
|
WxUtils::ShowErrorDialog(_("You must choose a game!"));
|
||||||
return;
|
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;
|
NetPlayHostConfig host_config;
|
||||||
unsigned long listen_port = 0;
|
host_config.game_name = WxStrToStr(m_game_lbox->GetStringSelection());
|
||||||
if (m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE)
|
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;
|
host_config.listen_port = static_cast<u16>(
|
||||||
listen_port =
|
m_traversal_listen_port_enabled->IsChecked() ? m_traversal_listen_port->GetValue() : 0);
|
||||||
m_traversal_listen_port_enabled->IsChecked() ? m_traversal_listen_port->GetValue() : 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trav = false;
|
unsigned long listen_port;
|
||||||
m_host_port_text->GetValue().ToULong(&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);
|
host_config.traversal_port = NetPlayLaunchConfig::GetTraversalPortFromIniConfig(netplay_section);
|
||||||
unsigned long int centralPort;
|
host_config.traversal_host = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(netplay_section);
|
||||||
StrToWxStr(centralPortString).ToULong(¢ralPort);
|
|
||||||
|
|
||||||
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 (NetPlayLauncher::Host(host_config))
|
||||||
if (netplay_server->is_connected)
|
|
||||||
{
|
{
|
||||||
netplay_server->ChangeGame(game);
|
Destroy();
|
||||||
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?"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,16 +339,33 @@ void NetPlaySetupFrame::OnJoin(wxCommandEvent&)
|
||||||
|
|
||||||
void NetPlaySetupFrame::DoJoin()
|
void NetPlaySetupFrame::DoJoin()
|
||||||
{
|
{
|
||||||
NetPlayDialog*& npd = NetPlayDialog::GetInstance();
|
IniFile inifile;
|
||||||
if (npd)
|
inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
|
||||||
{
|
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
|
||||||
WxUtils::ShowErrorDialog(_("A NetPlay window is already open!"));
|
|
||||||
return;
|
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;
|
unsigned long port = 0;
|
||||||
m_connect_port_text->GetValue().ToULong(&port);
|
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)
|
void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event)
|
||||||
|
|
|
@ -42,8 +42,6 @@ private:
|
||||||
void OnAfterTabChange(wxIdleEvent& event);
|
void OnAfterTabChange(wxIdleEvent& event);
|
||||||
void DispatchFocus();
|
void DispatchFocus();
|
||||||
|
|
||||||
void MakeNetPlayDiag(int port, const std::string& game, bool is_hosting);
|
|
||||||
|
|
||||||
wxStaticText* m_ip_lbl;
|
wxStaticText* m_ip_lbl;
|
||||||
wxStaticText* m_client_port_lbl;
|
wxStaticText* m_client_port_lbl;
|
||||||
wxTextCtrl* m_nickname_text;
|
wxTextCtrl* m_nickname_text;
|
||||||
|
|
|
@ -37,8 +37,6 @@
|
||||||
#include "Core/NetPlayProto.h"
|
#include "Core/NetPlayProto.h"
|
||||||
#include "Core/NetPlayServer.h"
|
#include "Core/NetPlayServer.h"
|
||||||
|
|
||||||
#include "DiscIO/Enums.h"
|
|
||||||
|
|
||||||
#include "DolphinWX/Frame.h"
|
#include "DolphinWX/Frame.h"
|
||||||
#include "DolphinWX/GameListCtrl.h"
|
#include "DolphinWX/GameListCtrl.h"
|
||||||
#include "DolphinWX/ISOFile.h"
|
#include "DolphinWX/ISOFile.h"
|
||||||
|
@ -56,46 +54,10 @@ NetPlayServer* NetPlayDialog::netplay_server = nullptr;
|
||||||
NetPlayClient* NetPlayDialog::netplay_client = nullptr;
|
NetPlayClient* NetPlayDialog::netplay_client = nullptr;
|
||||||
NetPlayDialog* NetPlayDialog::npd = 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)
|
void NetPlayDialog::FillWithGameNames(wxListBox* game_lbox, const CGameListCtrl& game_list)
|
||||||
{
|
{
|
||||||
for (u32 i = 0; auto game = game_list.GetISO(i); ++i)
|
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,
|
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..
|
// find path for selected game, sloppy..
|
||||||
for (u32 i = 0; auto game = m_game_list->GetISO(i); ++i)
|
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 game->GetFileName();
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in New Issue