NetPlayClient/Server: apply Parameter Object pattern to traversal parameters
This commit is contained in:
parent
fdb5828d62
commit
4b50e77a26
|
@ -74,13 +74,12 @@ NetPlayClient::~NetPlayClient()
|
|||
|
||||
// called from ---GUI--- thread
|
||||
NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog,
|
||||
const std::string& name, bool traversal,
|
||||
const std::string& centralServer, u16 centralPort)
|
||||
const std::string& name, const NetTraversalConfig& traversal_config)
|
||||
: m_dialog(dialog), m_player_name(name)
|
||||
{
|
||||
ClearBuffers();
|
||||
|
||||
if (!traversal)
|
||||
if (!traversal_config.use_traversal)
|
||||
{
|
||||
// Direct Connection
|
||||
m_client = enet_host_create(nullptr, 1, 3, 0, 0);
|
||||
|
@ -124,7 +123,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
|
|||
return;
|
||||
}
|
||||
|
||||
if (!EnsureTraversalClient(centralServer, centralPort))
|
||||
if (!EnsureTraversalClient(traversal_config.traversal_host, traversal_config.traversal_port))
|
||||
return;
|
||||
m_client = g_MainNetHost.get();
|
||||
|
||||
|
|
|
@ -67,8 +67,7 @@ public:
|
|||
void SendAsync(sf::Packet&& packet);
|
||||
|
||||
NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog,
|
||||
const std::string& name, bool traversal, const std::string& centralServer,
|
||||
u16 centralPort);
|
||||
const std::string& name, const NetTraversalConfig& traversal_config);
|
||||
~NetPlayClient();
|
||||
|
||||
void GetPlayerList(std::string& list, std::vector<int>& pid_list);
|
||||
|
|
|
@ -27,6 +27,20 @@ struct NetSettings
|
|||
ExpansionInterface::TEXIDevices m_EXIDevice[2];
|
||||
};
|
||||
|
||||
struct NetTraversalConfig
|
||||
{
|
||||
NetTraversalConfig() = default;
|
||||
NetTraversalConfig(bool use_traversal_, std::string traversal_host_, u16 traversal_port_)
|
||||
: use_traversal{use_traversal_}, traversal_host{std::move(traversal_host_)},
|
||||
traversal_port{traversal_port_}
|
||||
{
|
||||
}
|
||||
|
||||
bool use_traversal = false;
|
||||
std::string traversal_host;
|
||||
u16 traversal_port = 0;
|
||||
};
|
||||
|
||||
extern NetSettings g_NetPlaySettings;
|
||||
extern u64 g_netplay_initial_rtc;
|
||||
|
||||
|
|
|
@ -63,8 +63,7 @@ NetPlayServer::~NetPlayServer()
|
|||
}
|
||||
|
||||
// called from ---GUI--- thread
|
||||
NetPlayServer::NetPlayServer(const u16 port, bool traversal, const std::string& centralServer,
|
||||
u16 centralPort)
|
||||
NetPlayServer::NetPlayServer(const u16 port, const NetTraversalConfig& traversal_config)
|
||||
{
|
||||
//--use server time
|
||||
if (enet_initialize() != 0)
|
||||
|
@ -75,9 +74,10 @@ NetPlayServer::NetPlayServer(const u16 port, bool traversal, const std::string&
|
|||
m_pad_map.fill(-1);
|
||||
m_wiimote_map.fill(-1);
|
||||
|
||||
if (traversal)
|
||||
if (traversal_config.use_traversal)
|
||||
{
|
||||
if (!EnsureTraversalClient(centralServer, centralPort, port))
|
||||
if (!EnsureTraversalClient(traversal_config.traversal_host, traversal_config.traversal_port,
|
||||
port))
|
||||
return;
|
||||
|
||||
g_TraversalClient->m_Client = this;
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
void ThreadFunc();
|
||||
void SendAsyncToClients(sf::Packet&& packet);
|
||||
|
||||
NetPlayServer(const u16 port, bool traversal, const std::string& centralServer, u16 centralPort);
|
||||
NetPlayServer(const u16 port, const NetTraversalConfig& traversal_config);
|
||||
~NetPlayServer();
|
||||
|
||||
bool ChangeGame(const std::string& game);
|
||||
|
|
|
@ -684,10 +684,10 @@ bool MainWindow::NetPlayJoin()
|
|||
const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME);
|
||||
|
||||
// Create Client
|
||||
Settings::Instance().ResetNetPlayClient(
|
||||
new NetPlayClient(host_ip, host_port, m_netplay_dialog, nickname,
|
||||
Settings::Instance().GetNetPlayServer() != nullptr ? false : is_traversal,
|
||||
traversal_host, traversal_port));
|
||||
Settings::Instance().ResetNetPlayClient(new NetPlayClient(
|
||||
host_ip, host_port, m_netplay_dialog, nickname,
|
||||
NetTraversalConfig{Settings::Instance().GetNetPlayServer() != nullptr ? false : is_traversal,
|
||||
traversal_host, traversal_port}));
|
||||
|
||||
if (!Settings::Instance().GetNetPlayClient()->IsConnected())
|
||||
{
|
||||
|
@ -733,8 +733,8 @@ bool MainWindow::NetPlayHost(const QString& game_id)
|
|||
host_port = Config::Get(Config::NETPLAY_LISTEN_PORT);
|
||||
|
||||
// Create Server
|
||||
Settings::Instance().ResetNetPlayServer(
|
||||
new NetPlayServer(host_port, is_traversal, traversal_host, traversal_port));
|
||||
Settings::Instance().ResetNetPlayServer(new NetPlayServer(
|
||||
host_port, NetTraversalConfig{is_traversal, traversal_host, traversal_port}));
|
||||
|
||||
if (!Settings::Instance().GetNetPlayServer()->is_connected)
|
||||
{
|
||||
|
|
|
@ -23,8 +23,9 @@ bool NetPlayLauncher::Host(const NetPlayHostConfig& config)
|
|||
return false;
|
||||
}
|
||||
|
||||
netplay_server = new NetPlayServer(config.listen_port, config.use_traversal,
|
||||
config.traversal_host, config.traversal_port);
|
||||
netplay_server = new NetPlayServer(
|
||||
config.listen_port,
|
||||
NetTraversalConfig{config.use_traversal, config.traversal_host, config.traversal_port});
|
||||
|
||||
if (!netplay_server->is_connected)
|
||||
{
|
||||
|
@ -45,9 +46,8 @@ bool NetPlayLauncher::Host(const NetPlayHostConfig& config)
|
|||
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);
|
||||
netplay_client = new NetPlayClient("127.0.0.1", netplay_server->GetPort(), npd,
|
||||
config.player_name, NetTraversalConfig{});
|
||||
|
||||
if (netplay_client->IsConnected())
|
||||
{
|
||||
|
@ -76,9 +76,9 @@ bool NetPlayLauncher::Join(const NetPlayJoinConfig& config)
|
|||
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);
|
||||
netplay_client = new NetPlayClient(
|
||||
host, config.connect_port, npd, config.player_name,
|
||||
NetTraversalConfig{config.use_traversal, config.traversal_host, config.traversal_port});
|
||||
if (netplay_client->IsConnected())
|
||||
{
|
||||
npd->SetSize(config.window_pos);
|
||||
|
|
Loading…
Reference in New Issue