2016-10-03 12:35:27 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-08-02 23:51:05 +00:00
|
|
|
#include <wx/config.h>
|
2016-10-03 22:57:32 +00:00
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
|
2016-10-03 12:35:27 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/StringUtil.h"
|
2017-08-02 23:52:26 +00:00
|
|
|
#include "Core/Config/NetplaySettings.h"
|
2016-10-03 22:57:32 +00:00
|
|
|
#include "DolphinWX/NetPlay/NetPlayLauncher.h"
|
|
|
|
#include "DolphinWX/NetPlay/NetWindow.h"
|
2016-10-03 12:35:27 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2017-08-07 07:22:33 +00:00
|
|
|
netplay_server = new NetPlayServer(
|
|
|
|
config.listen_port,
|
|
|
|
NetTraversalConfig{config.use_traversal, config.traversal_host, config.traversal_port});
|
2016-10-03 12:35:27 +00:00
|
|
|
|
|
|
|
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();
|
2017-08-07 07:22:33 +00:00
|
|
|
netplay_client = new NetPlayClient("127.0.0.1", netplay_server->GetPort(), npd,
|
|
|
|
config.player_name, NetTraversalConfig{});
|
2016-10-03 12:35:27 +00:00
|
|
|
|
|
|
|
if (netplay_client->IsConnected())
|
|
|
|
{
|
2016-10-03 22:57:32 +00:00
|
|
|
npd->SetSize(config.window_pos);
|
2016-10-03 12:35:27 +00:00
|
|
|
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;
|
|
|
|
|
2017-08-07 07:22:33 +00:00
|
|
|
netplay_client = new NetPlayClient(
|
|
|
|
host, config.connect_port, npd, config.player_name,
|
|
|
|
NetTraversalConfig{config.use_traversal, config.traversal_host, config.traversal_port});
|
2016-10-03 12:35:27 +00:00
|
|
|
if (netplay_client->IsConnected())
|
|
|
|
{
|
2016-10-03 22:57:32 +00:00
|
|
|
npd->SetSize(config.window_pos);
|
2016-10-03 12:35:27 +00:00
|
|
|
npd->Show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
npd->Destroy();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 23:51:05 +00:00
|
|
|
void NetPlayLaunchConfig::SetDialogInfo(wxWindow* parent)
|
2016-10-03 22:57:32 +00:00
|
|
|
{
|
|
|
|
parent_window = parent;
|
|
|
|
|
2017-08-02 23:51:05 +00:00
|
|
|
wxConfig::Get()->Read("NetWindowPosX", &window_pos.x, window_defaults.GetX());
|
|
|
|
wxConfig::Get()->Read("NetWindowPosY", &window_pos.y, window_defaults.GetY());
|
|
|
|
wxConfig::Get()->Read("NetWindowWidth", &window_pos.width, window_defaults.GetWidth());
|
|
|
|
wxConfig::Get()->Read("NetWindowHeight", &window_pos.height, window_defaults.GetHeight());
|
2016-10-03 22:57:32 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 23:52:26 +00:00
|
|
|
void NetPlayHostConfig::FromConfig()
|
2016-10-03 12:35:27 +00:00
|
|
|
{
|
2017-08-02 23:52:26 +00:00
|
|
|
player_name = Config::Get(Config::NETPLAY_NICKNAME);
|
2016-12-25 15:36:19 +00:00
|
|
|
|
2017-08-02 23:52:26 +00:00
|
|
|
const std::string traversal_choice_setting = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE);
|
2016-10-03 12:35:27 +00:00
|
|
|
use_traversal = traversal_choice_setting == "traversal";
|
|
|
|
|
|
|
|
if (!use_traversal)
|
|
|
|
{
|
2017-08-02 23:52:26 +00:00
|
|
|
listen_port = Config::Get(Config::NETPLAY_HOST_PORT);
|
2016-10-03 12:35:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-02 23:52:26 +00:00
|
|
|
traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT);
|
|
|
|
traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER);
|
2016-10-03 12:35:27 +00:00
|
|
|
}
|
2017-08-02 23:52:26 +00:00
|
|
|
}
|