diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 68a01365aa..238d1b48e9 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -63,7 +63,8 @@ NetPlayServer::~NetPlayServer() } // called from ---GUI--- thread -NetPlayServer::NetPlayServer(const u16 port, const NetTraversalConfig& traversal_config) +NetPlayServer::NetPlayServer(const u16 port, const bool forward_port, + const NetTraversalConfig& traversal_config) { //--use server time if (enet_initialize() != 0) @@ -103,6 +104,11 @@ NetPlayServer::NetPlayServer(const u16 port, const NetTraversalConfig& traversal m_do_loop = true; m_thread = std::thread(&NetPlayServer::ThreadFunc, this); m_target_buffer_size = 5; + +#ifdef USE_UPNP + if (forward_port) + UPnP::TryPortmapping(port); +#endif } } @@ -931,11 +937,3 @@ std::vector> NetPlayServer::GetInterfaceList result.emplace_back(std::make_pair("!local!", "127.0.0.1")); return result; } - -#ifdef USE_UPNP -// called from ---GUI--- thread -void NetPlayServer::TryPortmapping(u16 port) -{ - UPnP::TryPortmapping(port); -} -#endif diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 517f5fc61a..84bb2fba6e 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -28,7 +28,7 @@ public: void ThreadFunc(); void SendAsyncToClients(sf::Packet&& packet); - NetPlayServer(const u16 port, const NetTraversalConfig& traversal_config); + NetPlayServer(u16 port, bool forward_port, const NetTraversalConfig& traversal_config); ~NetPlayServer(); bool ChangeGame(const std::string& game); @@ -58,10 +58,6 @@ public: bool is_connected = false; -#ifdef USE_UPNP - void TryPortmapping(u16 port); -#endif - private: class Client { diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 87a2f8e5e2..6dc3ff4ec9 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -734,7 +734,7 @@ bool MainWindow::NetPlayHost(const QString& game_id) // Create Server Settings::Instance().ResetNetPlayServer(new NetPlayServer( - host_port, NetTraversalConfig{is_traversal, traversal_host, traversal_port})); + host_port, use_upnp, NetTraversalConfig{is_traversal, traversal_host, traversal_port})); if (!Settings::Instance().GetNetPlayServer()->is_connected) { @@ -748,11 +748,6 @@ bool MainWindow::NetPlayHost(const QString& game_id) Settings::Instance().GetNetPlayServer()->ChangeGame(game_id.toStdString()); -#ifdef USE_UPNP - if (use_upnp) - Settings::Instance().GetNetPlayServer()->TryPortmapping(host_port); -#endif - // Join our local server return NetPlayJoin(); } diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp index 758cfa7af0..e10375812e 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp @@ -24,7 +24,7 @@ bool NetPlayLauncher::Host(const NetPlayHostConfig& config) } netplay_server = new NetPlayServer( - config.listen_port, + config.listen_port, config.forward_port, NetTraversalConfig{config.use_traversal, config.traversal_host, config.traversal_port}); if (!netplay_server->is_connected) @@ -36,13 +36,6 @@ bool NetPlayLauncher::Host(const NetPlayHostConfig& config) 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(); diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h index ddc92f6f34..6ce2b69df4 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h @@ -34,9 +34,7 @@ public: std::string game_name; u16 listen_port = 0; -#ifdef USE_UPNP - bool forward_port; -#endif + bool forward_port = false; }; class NetPlayJoinConfig : public NetPlayLaunchConfig