[Netplay:Traversal] Add "Force Netplay Listen Port" feature that was in old netplay branch
This commit is contained in:
parent
63c373c843
commit
1f83a3d146
|
@ -318,17 +318,19 @@ std::unique_ptr<ENetHost> g_MainNetHost;
|
|||
// need to know not just what port it's on, but whether it was
|
||||
// explicitly requested.
|
||||
static std::string g_OldServer;
|
||||
static u16 g_OldPort;
|
||||
static u16 g_OldServerPort;
|
||||
static u16 g_OldListenPort;
|
||||
|
||||
bool EnsureTraversalClient(const std::string& server, u16 port)
|
||||
bool EnsureTraversalClient(const std::string& server, u16 server_port, u16 listen_port)
|
||||
{
|
||||
|
||||
if (!g_MainNetHost || !g_TraversalClient || server != g_OldServer || port != g_OldPort)
|
||||
if (!g_MainNetHost || !g_TraversalClient || server != g_OldServer || server_port != g_OldServerPort || listen_port != g_OldListenPort)
|
||||
{
|
||||
g_OldServer = server;
|
||||
g_OldPort = port ;
|
||||
g_OldServerPort = server_port;
|
||||
g_OldListenPort = listen_port;
|
||||
|
||||
ENetAddress addr = { ENET_HOST_ANY, 0 };
|
||||
ENetAddress addr = { ENET_HOST_ANY, listen_port };
|
||||
ENetHost* host = enet_host_create(
|
||||
&addr, // address
|
||||
50, // peerCount
|
||||
|
@ -341,7 +343,7 @@ bool EnsureTraversalClient(const std::string& server, u16 port)
|
|||
return false;
|
||||
}
|
||||
g_MainNetHost.reset(host);
|
||||
g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server, port));
|
||||
g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server, server_port));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -77,5 +77,5 @@ extern std::unique_ptr<TraversalClient> g_TraversalClient;
|
|||
// the NetHost connected to the TraversalClient.
|
||||
extern std::unique_ptr<ENetHost> g_MainNetHost;
|
||||
// Create g_TraversalClient and g_MainNetHost if necessary.
|
||||
bool EnsureTraversalClient(const std::string& server, u16 port);
|
||||
bool EnsureTraversalClient(const std::string& server, u16 server_port, u16 listen_port = 0);
|
||||
void ReleaseTraversalClient();
|
||||
|
|
|
@ -79,7 +79,7 @@ NetPlayServer::NetPlayServer(const u16 port, bool traversal, const std::string&
|
|||
|
||||
if (traversal)
|
||||
{
|
||||
if (!EnsureTraversalClient(centralServer, centralPort))
|
||||
if (!EnsureTraversalClient(centralServer, centralPort, port))
|
||||
return;
|
||||
|
||||
g_TraversalClient->m_Client = this;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <wx/notebook.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/spinctrl.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/textctrl.h>
|
||||
|
||||
|
@ -152,6 +153,18 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
|
|||
netplay_section.Get("HostPort", &port, "2626");
|
||||
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 = new wxSpinCtrl(host_tab, wxID_ANY, "", wxDefaultPosition, wxSize(80, -1), wxSP_ARROW_KEYS, 1, 65535);
|
||||
|
||||
unsigned int listen_port;
|
||||
netplay_section.Get("ListenPort", &listen_port, 0);
|
||||
m_traversal_listen_port_enabled->SetValue(listen_port != 0);
|
||||
m_traversal_listen_port->Enable(m_traversal_listen_port_enabled->IsChecked());
|
||||
m_traversal_listen_port->SetValue(listen_port);
|
||||
|
||||
m_traversal_listen_port_enabled->Bind(wxEVT_CHECKBOX, &NetPlaySetupFrame::OnTraversalListenPortChanged, this);
|
||||
m_traversal_listen_port->Bind(wxEVT_TEXT, &NetPlaySetupFrame::OnTraversalListenPortChanged, this);
|
||||
|
||||
wxButton* const host_btn = new wxButton(host_tab, wxID_ANY, _("Host"));
|
||||
host_btn->Bind(wxEVT_BUTTON, &NetPlaySetupFrame::OnHost, this);
|
||||
|
||||
|
@ -167,11 +180,17 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
|
|||
m_upnp_chk = new wxCheckBox(host_tab, wxID_ANY, _("Forward port (UPnP)"));
|
||||
top_szr->Add(m_upnp_chk, 0, wxALL | wxALIGN_RIGHT, 5);
|
||||
#endif
|
||||
wxBoxSizer* const bottom_szr = new wxBoxSizer(wxHORIZONTAL);
|
||||
bottom_szr->Add(m_traversal_listen_port_enabled, 0, wxCENTER | wxLEFT, 5);
|
||||
bottom_szr->Add(m_traversal_listen_port, 0, wxCENTER, 0);
|
||||
wxBoxSizer* const host_btn_szr = new wxBoxSizer(wxVERTICAL);
|
||||
host_btn_szr->Add(host_btn, 0, wxCENTER | wxALIGN_RIGHT, 0);
|
||||
bottom_szr->Add(host_btn_szr, 1, wxALL, 5);
|
||||
|
||||
wxBoxSizer* const host_szr = new wxBoxSizer(wxVERTICAL);
|
||||
host_szr->Add(top_szr, 0, wxALL | wxEXPAND, 5);
|
||||
host_szr->Add(m_game_lbox, 1, wxLEFT | wxRIGHT | wxEXPAND, 5);
|
||||
host_szr->Add(host_btn, 0, wxALL | wxALIGN_RIGHT, 5);
|
||||
host_szr->Add(bottom_szr, 0, wxEXPAND, 0);
|
||||
|
||||
host_tab->SetSizerAndFit(host_szr);
|
||||
}
|
||||
|
@ -234,6 +253,8 @@ NetPlaySetupFrame::~NetPlaySetupFrame()
|
|||
}
|
||||
netplay_section.Set("ConnectPort", WxStrToStr(m_connect_port_text->GetValue()));
|
||||
netplay_section.Set("HostPort", WxStrToStr(m_host_port_text->GetValue()));
|
||||
netplay_section.Set("ListenPort",
|
||||
m_traversal_listen_port_enabled->IsChecked() ? m_traversal_listen_port->GetValue() : 0);
|
||||
|
||||
inifile.Save(dolphin_ini);
|
||||
main_frame->g_NetPlaySetupDiag = nullptr;
|
||||
|
@ -301,13 +322,17 @@ void NetPlaySetupFrame::OnHost(wxCommandEvent&)
|
|||
std::string game(WxStrToStr(m_game_lbox->GetStringSelection()));
|
||||
|
||||
bool trav;
|
||||
unsigned long listen_port = 0;
|
||||
if (m_direct_traversal->GetCurrentSelection() == 1)
|
||||
{
|
||||
trav = true;
|
||||
listen_port = m_traversal_listen_port_enabled->IsChecked() ? m_traversal_listen_port->GetValue() : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
trav = false;
|
||||
|
||||
unsigned long port = 0;
|
||||
m_host_port_text->GetValue().ToULong(&port);
|
||||
m_host_port_text->GetValue().ToULong(&listen_port);
|
||||
}
|
||||
|
||||
IniFile inifile;
|
||||
inifile.Load(File::GetUserPath(D_CONFIG_IDX) + "Dolphin.ini");
|
||||
|
@ -321,14 +346,14 @@ void NetPlaySetupFrame::OnHost(wxCommandEvent&)
|
|||
std::string centralServer;
|
||||
GetTraversalServer(netplay_section, ¢ralServer);
|
||||
|
||||
netplay_server = new NetPlayServer((u16)port, trav, centralServer, (u16) centralPort);
|
||||
netplay_server = new NetPlayServer((u16)listen_port, trav, centralServer, (u16) centralPort);
|
||||
if (netplay_server->is_connected)
|
||||
{
|
||||
netplay_server->ChangeGame(game);
|
||||
netplay_server->AdjustPadBufferSize(INITIAL_PAD_BUFFER_SIZE);
|
||||
#ifdef USE_UPNP
|
||||
if (m_upnp_chk->GetValue())
|
||||
netplay_server->TryPortmapping(port);
|
||||
netplay_server->TryPortmapping(listen_port);
|
||||
#endif
|
||||
MakeNetPlayDiag(netplay_server->GetPort(), game, true);
|
||||
netplay_server->SetNetPlayUI(NetPlayDialog::GetInstance());
|
||||
|
@ -366,6 +391,11 @@ void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event)
|
|||
m_traversal_lbl->SetLabelText(_("Traversal: ") + "stun.dolphin-emu.org:6262");
|
||||
}
|
||||
|
||||
void NetPlaySetupFrame::OnTraversalListenPortChanged(wxCommandEvent& event)
|
||||
{
|
||||
m_traversal_listen_port->Enable(m_traversal_listen_port_enabled->IsChecked());
|
||||
}
|
||||
|
||||
void NetPlaySetupFrame::OnChoice(wxCommandEvent& event)
|
||||
{
|
||||
int sel = m_direct_traversal->GetSelection();
|
||||
|
@ -394,6 +424,8 @@ void NetPlaySetupFrame::OnChoice(wxCommandEvent& event)
|
|||
{
|
||||
m_host_port_lbl->Hide();
|
||||
m_host_port_text->Hide();
|
||||
m_traversal_listen_port->Show();
|
||||
m_traversal_listen_port_enabled->Show();
|
||||
#ifdef USE_UPNP
|
||||
m_upnp_chk->Hide();
|
||||
#endif
|
||||
|
@ -417,6 +449,8 @@ void NetPlaySetupFrame::OnChoice(wxCommandEvent& event)
|
|||
}
|
||||
|
||||
// Server tab
|
||||
m_traversal_listen_port->Hide();
|
||||
m_traversal_listen_port_enabled->Hide();
|
||||
m_host_port_lbl->Show();
|
||||
m_host_port_text->Show();
|
||||
#ifdef USE_UPNP
|
||||
|
|
|
@ -12,6 +12,7 @@ class CGameListCtrl;
|
|||
class wxCheckBox;
|
||||
class wxChoice;
|
||||
class wxListBox;
|
||||
class wxSpinCtrl;
|
||||
class wxStaticText;
|
||||
class wxTextCtrl;
|
||||
|
||||
|
@ -27,6 +28,7 @@ private:
|
|||
void OnQuit(wxCommandEvent& event);
|
||||
void OnChoice(wxCommandEvent& event);
|
||||
void OnResetTraversal(wxCommandEvent& event);
|
||||
void OnTraversalListenPortChanged(wxCommandEvent& event);
|
||||
|
||||
void MakeNetPlayDiag(int port, const std::string& game, bool is_hosting);
|
||||
|
||||
|
@ -40,6 +42,8 @@ private:
|
|||
wxChoice* m_direct_traversal;
|
||||
wxStaticText* m_traversal_lbl;
|
||||
wxButton* m_trav_reset_btn;
|
||||
wxCheckBox* m_traversal_listen_port_enabled;
|
||||
wxSpinCtrl* m_traversal_listen_port;
|
||||
|
||||
wxListBox* m_game_lbox;
|
||||
#ifdef USE_UPNP
|
||||
|
|
Loading…
Reference in New Issue