DolphinWX: Less duplication between GetTraversalPort/Server

They now also return their results the regular way.
This commit is contained in:
JosJuice 2016-10-02 16:33:59 +02:00
parent e5325fd082
commit 7a165db94f

View File

@ -23,20 +23,25 @@
#include "DolphinWX/NetPlay/NetWindow.h"
#include "DolphinWX/WxUtils.h"
static void GetTraversalPort(IniFile::Section& section, std::string* port)
static std::string GetFromINI(IniFile::Section& section, const std::string& key,
const std::string& default_value)
{
section.Get("TraversalPort", port, "6262");
port->erase(std::remove(port->begin(), port->end(), ' '), port->end());
if (port->empty())
*port = "6262";
std::string result;
section.Get(key, &result, default_value);
result.erase(std::remove(result.begin(), result.end(), ' '), result.end());
if (result.empty())
return default_value;
return result;
}
static void GetTraversalServer(IniFile::Section& section, std::string* server)
static std::string GetTraversalPort(IniFile::Section& section)
{
section.Get("TraversalServer", server, "stun.dolphin-emu.org");
server->erase(std::remove(server->begin(), server->end(), ' '), server->end());
if (server->empty())
*server = "stun.dolphin-emu.org";
return GetFromINI(section, "TraversalPort", "6262");
}
static std::string GetTraversalServer(IniFile::Section& section)
{
return GetFromINI(section, "TraversalServer", "stun.dolphin-emu.org");
}
NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl* const game_list)
@ -98,10 +103,8 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl
m_direct_traversal->Select(DIRECT_CHOICE);
}
std::string centralPort;
GetTraversalPort(netplay_section, &centralPort);
std::string centralServer;
GetTraversalServer(netplay_section, &centralServer);
std::string centralPort = GetTraversalPort(netplay_section);
std::string centralServer = GetTraversalServer(netplay_section);
m_traversal_lbl = new wxStaticText(panel, wxID_ANY, _("Traversal Server:") + " " +
centralServer + ":" + centralPort);
@ -312,13 +315,11 @@ void NetPlaySetupFrame::MakeNetPlayDiag(int port, const std::string& game, bool
inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
std::string centralPortString;
GetTraversalPort(netplay_section, &centralPortString);
std::string centralPortString = GetTraversalPort(netplay_section);
unsigned long int centralPort;
StrToWxStr(centralPortString).ToULong(&centralPort);
std::string centralServer;
GetTraversalServer(netplay_section, &centralServer);
std::string centralServer = GetTraversalServer(netplay_section);
netplay_client = new NetPlayClient(ip, (u16)port, npd, WxStrToStr(m_nickname_text->GetValue()),
trav, centralServer, (u16)centralPort);
@ -394,13 +395,11 @@ void NetPlaySetupFrame::DoHost()
m_host_port_text->GetValue().ToULong(&listen_port);
}
std::string centralPortString;
GetTraversalPort(netplay_section, &centralPortString);
std::string centralPortString = GetTraversalPort(netplay_section);
unsigned long int centralPort;
StrToWxStr(centralPortString).ToULong(&centralPort);
std::string centralServer;
GetTraversalServer(netplay_section, &centralServer);
std::string centralServer = GetTraversalServer(netplay_section);
netplay_server = new NetPlayServer((u16)listen_port, trav, centralServer, (u16)centralPort);
if (netplay_server->is_connected)