NetPlayServer: handle port forwarding in constructor
This commit is contained in:
parent
4b50e77a26
commit
b5d070b0cf
|
@ -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<std::pair<std::string, std::string>> 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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue