From 9afb2ff40ea45292932f5b6a8a30cf19d92d4e8a Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:25:14 -0700 Subject: [PATCH 01/13] Common/CMakeLists: sort source files --- Source/Core/Common/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 4f5c01e6a6..322bf5d641 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -6,6 +6,9 @@ set(SRCS Config/Config.cpp Config/Layer.cpp Config/Section.cpp + Crypto/AES.cpp + Crypto/bn.cpp + Crypto/ec.cpp ENetUtil.cpp File.cpp FileSearch.cpp @@ -15,7 +18,9 @@ set(SRCS HttpRequest.cpp IniFile.cpp JitRegister.cpp + Logging/LogManager.cpp MathUtil.cpp + MD5.cpp MemArena.cpp MemoryUtil.cpp MsgHandler.cpp @@ -35,11 +40,6 @@ set(SRCS Version.cpp x64ABI.cpp x64Emitter.cpp - MD5.cpp - Crypto/AES.cpp - Crypto/bn.cpp - Crypto/ec.cpp - Logging/LogManager.cpp ) set(LIBS ${LIBS} ${MBEDTLS_LIBRARIES}) From 3386543a9c3244db5f36d267a0ca44c95c97910e Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:26:01 -0700 Subject: [PATCH 02/13] Common: extract UPnP namespace from NetPlayServer --- Source/Core/Common/CMakeLists.txt | 1 + Source/Core/Common/Common.vcxproj | 2 + Source/Core/Common/Common.vcxproj.filters | 2 + Source/Core/Common/UPnP.cpp | 173 ++++++++++++++++++++++ Source/Core/Common/UPnP.h | 17 +++ Source/Core/Core/NetPlayServer.cpp | 152 +------------------ Source/Core/Core/NetPlayServer.h | 15 -- 7 files changed, 198 insertions(+), 164 deletions(-) create mode 100644 Source/Core/Common/UPnP.cpp create mode 100644 Source/Core/Common/UPnP.h diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 322bf5d641..3b9951ede2 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -37,6 +37,7 @@ set(SRCS Thread.cpp Timer.cpp TraversalClient.cpp + UPnP.cpp Version.cpp x64ABI.cpp x64Emitter.cpp diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 9466fda774..651808e5f7 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -151,6 +151,7 @@ + @@ -202,6 +203,7 @@ + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index 4b48650ec1..c7ceb7adcb 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -94,6 +94,7 @@ + GL @@ -307,6 +308,7 @@ + Logging diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp new file mode 100644 index 0000000000..6dc84b0dca --- /dev/null +++ b/Source/Core/Common/UPnP.cpp @@ -0,0 +1,173 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#ifdef USE_UPNP + +#include "Common/UPnP.h" + +#include "Common/Logging/Log.h" +#include "Common/StringUtil.h" + +#include +#include +#include +#include +#include +#include + +static struct UPNPUrls m_upnp_urls; +static struct IGDdatas m_upnp_data; +static std::string m_upnp_ourip; +static u16 m_upnp_mapped = 0; +static std::thread m_upnp_thread; + +// called from ---UPnP--- thread +// discovers the IGD +static bool initUPnP() +{ + static bool s_inited = false; + static bool s_error = false; + + std::vector igds; + int descXMLsize = 0, upnperror = 0; + char cIP[20]; + + // Don't init if already inited + if (s_inited) + return true; + + // Don't init if it failed before + if (s_error) + return false; + + std::memset(&m_upnp_urls, 0, sizeof(UPNPUrls)); + std::memset(&m_upnp_data, 0, sizeof(IGDdatas)); + + // Find all UPnP devices + std::unique_ptr devlist(nullptr, freeUPNPDevlist); +#if MINIUPNPC_API_VERSION >= 14 + devlist.reset(upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &upnperror)); +#else + devlist.reset(upnpDiscover(2000, nullptr, nullptr, 0, 0, &upnperror)); +#endif + if (!devlist) + { + WARN_LOG(NETPLAY, "An error occurred trying to discover UPnP devices."); + + s_error = true; + + return false; + } + + // Look for the IGD + for (UPNPDev* dev = devlist.get(); dev; dev = dev->pNext) + { + if (std::strstr(dev->st, "InternetGatewayDevice")) + igds.push_back(dev); + } + + for (const UPNPDev* dev : igds) + { + std::unique_ptr descXML(nullptr, std::free); + int statusCode = 200; +#if MINIUPNPC_API_VERSION >= 16 + descXML.reset(static_cast( + miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0, &statusCode))); +#else + descXML.reset( + static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0))); +#endif + if (descXML && statusCode == 200) + { + parserootdesc(descXML.get(), descXMLsize, &m_upnp_data); + GetUPNPUrls(&m_upnp_urls, &m_upnp_data, dev->descURL, 0); + + m_upnp_ourip = cIP; + + NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL); + break; + } + else + { + WARN_LOG(NETPLAY, "Error getting info from IGD at %s.", dev->descURL); + } + } + + s_inited = true; + + return true; +} + +// called from ---UPnP--- thread +// Attempt to stop portforwarding. +// -- +// NOTE: It is important that this happens! A few very crappy routers +// apparently do not delete UPnP mappings on their own, so if you leave them +// hanging, the NVRAM will fill with portmappings, and eventually all UPnP +// requests will fail silently, with the only recourse being a factory reset. +// -- +static bool UPnPUnmapPort(const u16 port) +{ + std::string port_str = StringFromFormat("%d", port); + UPNP_DeletePortMapping(m_upnp_urls.controlURL, m_upnp_data.first.servicetype, port_str.c_str(), + "UDP", nullptr); + + return true; +} + +// called from ---UPnP--- thread +// Attempt to portforward! +static bool UPnPMapPort(const std::string& addr, const u16 port) +{ + if (m_upnp_mapped > 0) + UPnPUnmapPort(m_upnp_mapped); + + std::string port_str = StringFromFormat("%d", port); + int result = UPNP_AddPortMapping( + m_upnp_urls.controlURL, m_upnp_data.first.servicetype, port_str.c_str(), port_str.c_str(), + addr.c_str(), (std::string("dolphin-emu UDP on ") + addr).c_str(), "UDP", nullptr, nullptr); + + if (result != 0) + return false; + + m_upnp_mapped = port; + + return true; +} + +// UPnP thread: try to map a port +static void mapPortThread(const u16 port) +{ + if (initUPnP() && UPnPMapPort(m_upnp_ourip, port)) + { + NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, m_upnp_ourip.c_str()); + return; + } + + WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, m_upnp_ourip.c_str()); +} + +// UPnP thread: try to unmap a port +static void unmapPortThread() +{ + if (m_upnp_mapped > 0) + UPnPUnmapPort(m_upnp_mapped); +} + +void UPnP::TryPortmapping(u16 port) +{ + if (m_upnp_thread.joinable()) + m_upnp_thread.join(); + m_upnp_thread = std::thread(&mapPortThread, port); +} + +void UPnP::StopPortmapping() +{ + if (m_upnp_thread.joinable()) + m_upnp_thread.join(); + m_upnp_thread = std::thread(&unmapPortThread); + m_upnp_thread.join(); +} + +#endif diff --git a/Source/Core/Common/UPnP.h b/Source/Core/Common/UPnP.h new file mode 100644 index 0000000000..d4d9191fb1 --- /dev/null +++ b/Source/Core/Common/UPnP.h @@ -0,0 +1,17 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#ifdef USE_UPNP + +#include "Common/CommonTypes.h" + +namespace UPnP +{ +void TryPortmapping(u16 port); +void StopPortmapping(); +} + +#endif diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 5eaddab1e2..11a05e069b 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -18,6 +18,7 @@ #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" +#include "Common/UPnP.h" #include "Core/ConfigManager.h" #include "Core/HW/Sram.h" #include "Core/NetPlayClient.h" //for NetPlayUI @@ -57,10 +58,7 @@ NetPlayServer::~NetPlayServer() } #ifdef USE_UPNP - if (m_upnp_thread.joinable()) - m_upnp_thread.join(); - m_upnp_thread = std::thread(&NetPlayServer::unmapPortThread); - m_upnp_thread.join(); + UPnP::StopPortmapping(); #endif } @@ -935,153 +933,9 @@ std::vector> NetPlayServer::GetInterfaceList } #ifdef USE_UPNP -#include -#include -#include - -struct UPNPUrls NetPlayServer::m_upnp_urls; -struct IGDdatas NetPlayServer::m_upnp_data; -std::string NetPlayServer::m_upnp_ourip; -u16 NetPlayServer::m_upnp_mapped = 0; -std::thread NetPlayServer::m_upnp_thread; - // called from ---GUI--- thread void NetPlayServer::TryPortmapping(u16 port) { - if (m_upnp_thread.joinable()) - m_upnp_thread.join(); - m_upnp_thread = std::thread(&NetPlayServer::mapPortThread, port); -} - -// UPnP thread: try to map a port -void NetPlayServer::mapPortThread(const u16 port) -{ - if (initUPnP() && UPnPMapPort(m_upnp_ourip, port)) - { - NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, m_upnp_ourip.c_str()); - return; - } - - WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, m_upnp_ourip.c_str()); -} - -// UPnP thread: try to unmap a port -void NetPlayServer::unmapPortThread() -{ - if (m_upnp_mapped > 0) - UPnPUnmapPort(m_upnp_mapped); -} - -// called from ---UPnP--- thread -// discovers the IGD -bool NetPlayServer::initUPnP() -{ - static bool s_inited = false; - static bool s_error = false; - - std::vector igds; - int descXMLsize = 0, upnperror = 0; - char cIP[20]; - - // Don't init if already inited - if (s_inited) - return true; - - // Don't init if it failed before - if (s_error) - return false; - - memset(&m_upnp_urls, 0, sizeof(UPNPUrls)); - memset(&m_upnp_data, 0, sizeof(IGDdatas)); - - // Find all UPnP devices - std::unique_ptr devlist(nullptr, freeUPNPDevlist); -#if MINIUPNPC_API_VERSION >= 14 - devlist.reset(upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &upnperror)); -#else - devlist.reset(upnpDiscover(2000, nullptr, nullptr, 0, 0, &upnperror)); -#endif - if (!devlist) - { - WARN_LOG(NETPLAY, "An error occurred trying to discover UPnP devices."); - - s_error = true; - - return false; - } - - // Look for the IGD - for (UPNPDev* dev = devlist.get(); dev; dev = dev->pNext) - { - if (strstr(dev->st, "InternetGatewayDevice")) - igds.push_back(dev); - } - - for (const UPNPDev* dev : igds) - { - std::unique_ptr descXML(nullptr, std::free); - int statusCode = 200; -#if MINIUPNPC_API_VERSION >= 16 - descXML.reset(static_cast( - miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0, &statusCode))); -#else - descXML.reset( - static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0))); -#endif - if (descXML && statusCode == 200) - { - parserootdesc(descXML.get(), descXMLsize, &m_upnp_data); - GetUPNPUrls(&m_upnp_urls, &m_upnp_data, dev->descURL, 0); - - m_upnp_ourip = cIP; - - NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL); - break; - } - else - { - WARN_LOG(NETPLAY, "Error getting info from IGD at %s.", dev->descURL); - } - } - - s_inited = true; - return true; -} - -// called from ---UPnP--- thread -// Attempt to portforward! -bool NetPlayServer::UPnPMapPort(const std::string& addr, const u16 port) -{ - if (m_upnp_mapped > 0) - UPnPUnmapPort(m_upnp_mapped); - - std::string port_str = StringFromFormat("%d", port); - int result = UPNP_AddPortMapping( - m_upnp_urls.controlURL, m_upnp_data.first.servicetype, port_str.c_str(), port_str.c_str(), - addr.c_str(), (std::string("dolphin-emu UDP on ") + addr).c_str(), "UDP", nullptr, nullptr); - - if (result != 0) - return false; - - m_upnp_mapped = port; - - return true; -} - -// called from ---UPnP--- thread -// Attempt to stop portforwarding. -// -- -// NOTE: It is important that this happens! A few very crappy routers -// apparently do not delete UPnP mappings on their own, so if you leave them -// hanging, the NVRAM will fill with portmappings, and eventually all UPnP -// requests will fail silently, with the only recourse being a factory reset. -// -- -bool NetPlayServer::UPnPUnmapPort(const u16 port) -{ - std::string port_str = StringFromFormat("%d", port); - UPNP_DeletePortMapping(m_upnp_urls.controlURL, m_upnp_data.first.servicetype, port_str.c_str(), - "UDP", nullptr); - - return true; + UPnP::TryPortmapping(port); } #endif diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index a4adacdcba..cf8d2e958a 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -123,19 +123,4 @@ private: ENetHost* m_server = nullptr; TraversalClient* m_traversal_client = nullptr; NetPlayUI* m_dialog = nullptr; - -#ifdef USE_UPNP - static void mapPortThread(const u16 port); - static void unmapPortThread(); - - static bool initUPnP(); - static bool UPnPMapPort(const std::string& addr, const u16 port); - static bool UPnPUnmapPort(const u16 port); - - static struct UPNPUrls m_upnp_urls; - static struct IGDdatas m_upnp_data; - static std::string m_upnp_ourip; - static u16 m_upnp_mapped; - static std::thread m_upnp_thread; -#endif }; From 106ae9636ed3c0396e0b6d6d9b9cfa520dccca1c Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:37:17 -0700 Subject: [PATCH 03/13] UPnP: cleanup variable names --- Source/Core/Common/UPnP.cpp | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index 6dc84b0dca..6aff963724 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -16,11 +16,11 @@ #include #include -static struct UPNPUrls m_upnp_urls; -static struct IGDdatas m_upnp_data; -static std::string m_upnp_ourip; -static u16 m_upnp_mapped = 0; -static std::thread m_upnp_thread; +static UPNPUrls s_urls; +static IGDdatas s_data; +static std::string s_our_ip; +static u16 s_mapped = 0; +static std::thread s_thread; // called from ---UPnP--- thread // discovers the IGD @@ -41,8 +41,8 @@ static bool initUPnP() if (s_error) return false; - std::memset(&m_upnp_urls, 0, sizeof(UPNPUrls)); - std::memset(&m_upnp_data, 0, sizeof(IGDdatas)); + std::memset(&s_urls, 0, sizeof(UPNPUrls)); + std::memset(&s_data, 0, sizeof(IGDdatas)); // Find all UPnP devices std::unique_ptr devlist(nullptr, freeUPNPDevlist); @@ -80,10 +80,10 @@ static bool initUPnP() #endif if (descXML && statusCode == 200) { - parserootdesc(descXML.get(), descXMLsize, &m_upnp_data); - GetUPNPUrls(&m_upnp_urls, &m_upnp_data, dev->descURL, 0); + parserootdesc(descXML.get(), descXMLsize, &s_data); + GetUPNPUrls(&s_urls, &s_data, dev->descURL, 0); - m_upnp_ourip = cIP; + s_our_ip = cIP; NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL); break; @@ -110,8 +110,8 @@ static bool initUPnP() static bool UPnPUnmapPort(const u16 port) { std::string port_str = StringFromFormat("%d", port); - UPNP_DeletePortMapping(m_upnp_urls.controlURL, m_upnp_data.first.servicetype, port_str.c_str(), - "UDP", nullptr); + UPNP_DeletePortMapping(s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), "UDP", + nullptr); return true; } @@ -120,18 +120,18 @@ static bool UPnPUnmapPort(const u16 port) // Attempt to portforward! static bool UPnPMapPort(const std::string& addr, const u16 port) { - if (m_upnp_mapped > 0) - UPnPUnmapPort(m_upnp_mapped); + if (s_mapped > 0) + UPnPUnmapPort(s_mapped); std::string port_str = StringFromFormat("%d", port); int result = UPNP_AddPortMapping( - m_upnp_urls.controlURL, m_upnp_data.first.servicetype, port_str.c_str(), port_str.c_str(), - addr.c_str(), (std::string("dolphin-emu UDP on ") + addr).c_str(), "UDP", nullptr, nullptr); + s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), port_str.c_str(), addr.c_str(), + (std::string("dolphin-emu UDP on ") + addr).c_str(), "UDP", nullptr, nullptr); if (result != 0) return false; - m_upnp_mapped = port; + s_mapped = port; return true; } @@ -139,35 +139,35 @@ static bool UPnPMapPort(const std::string& addr, const u16 port) // UPnP thread: try to map a port static void mapPortThread(const u16 port) { - if (initUPnP() && UPnPMapPort(m_upnp_ourip, port)) + if (initUPnP() && UPnPMapPort(s_our_ip, port)) { - NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, m_upnp_ourip.c_str()); + NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, s_our_ip.c_str()); return; } - WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, m_upnp_ourip.c_str()); + WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, s_our_ip.c_str()); } // UPnP thread: try to unmap a port static void unmapPortThread() { - if (m_upnp_mapped > 0) - UPnPUnmapPort(m_upnp_mapped); + if (s_mapped > 0) + UPnPUnmapPort(s_mapped); } void UPnP::TryPortmapping(u16 port) { - if (m_upnp_thread.joinable()) - m_upnp_thread.join(); - m_upnp_thread = std::thread(&mapPortThread, port); + if (s_thread.joinable()) + s_thread.join(); + s_thread = std::thread(&mapPortThread, port); } void UPnP::StopPortmapping() { - if (m_upnp_thread.joinable()) - m_upnp_thread.join(); - m_upnp_thread = std::thread(&unmapPortThread); - m_upnp_thread.join(); + if (s_thread.joinable()) + s_thread.join(); + s_thread = std::thread(&unmapPortThread); + s_thread.join(); } #endif From 281f90efc33d59e2752b81b7d9c0398c8aecad26 Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:41:48 -0700 Subject: [PATCH 04/13] UPnP: coalesce s_our_ip and cIP --- Source/Core/Common/UPnP.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index 6aff963724..db8fc3ad6d 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -9,6 +9,7 @@ #include "Common/Logging/Log.h" #include "Common/StringUtil.h" +#include #include #include #include @@ -18,7 +19,7 @@ static UPNPUrls s_urls; static IGDdatas s_data; -static std::string s_our_ip; +static std::array s_our_ip; static u16 s_mapped = 0; static std::thread s_thread; @@ -31,7 +32,6 @@ static bool initUPnP() std::vector igds; int descXMLsize = 0, upnperror = 0; - char cIP[20]; // Don't init if already inited if (s_inited) @@ -72,19 +72,18 @@ static bool initUPnP() std::unique_ptr descXML(nullptr, std::free); int statusCode = 200; #if MINIUPNPC_API_VERSION >= 16 - descXML.reset(static_cast( - miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0, &statusCode))); -#else descXML.reset( - static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0))); + static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, s_our_ip.data(), + static_cast(s_our_ip.size()), 0, &statusCode))); +#else + descXML.reset(static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, s_our_ip.data(), + static_cast(s_our_ip.size()), 0))); #endif if (descXML && statusCode == 200) { parserootdesc(descXML.get(), descXMLsize, &s_data); GetUPNPUrls(&s_urls, &s_data, dev->descURL, 0); - s_our_ip = cIP; - NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL); break; } @@ -118,14 +117,14 @@ static bool UPnPUnmapPort(const u16 port) // called from ---UPnP--- thread // Attempt to portforward! -static bool UPnPMapPort(const std::string& addr, const u16 port) +static bool UPnPMapPort(const char* addr, const u16 port) { if (s_mapped > 0) UPnPUnmapPort(s_mapped); std::string port_str = StringFromFormat("%d", port); int result = UPNP_AddPortMapping( - s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), port_str.c_str(), addr.c_str(), + s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), port_str.c_str(), addr, (std::string("dolphin-emu UDP on ") + addr).c_str(), "UDP", nullptr, nullptr); if (result != 0) @@ -139,13 +138,13 @@ static bool UPnPMapPort(const std::string& addr, const u16 port) // UPnP thread: try to map a port static void mapPortThread(const u16 port) { - if (initUPnP() && UPnPMapPort(s_our_ip, port)) + if (initUPnP() && UPnPMapPort(s_our_ip.data(), port)) { - NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, s_our_ip.c_str()); + NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, s_our_ip.data()); return; } - WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, s_our_ip.c_str()); + WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, s_our_ip.data()); } // UPnP thread: try to unmap a port From 862e0bec7961441103db917f8fe63cffdaa89afc Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:43:24 -0700 Subject: [PATCH 05/13] UPnP: cleanup function names --- Source/Core/Common/UPnP.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index db8fc3ad6d..cb4a51574c 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -25,7 +25,7 @@ static std::thread s_thread; // called from ---UPnP--- thread // discovers the IGD -static bool initUPnP() +static bool InitUPnP() { static bool s_inited = false; static bool s_error = false; @@ -106,7 +106,7 @@ static bool initUPnP() // hanging, the NVRAM will fill with portmappings, and eventually all UPnP // requests will fail silently, with the only recourse being a factory reset. // -- -static bool UPnPUnmapPort(const u16 port) +static bool UnmapPort(const u16 port) { std::string port_str = StringFromFormat("%d", port); UPNP_DeletePortMapping(s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), "UDP", @@ -117,10 +117,10 @@ static bool UPnPUnmapPort(const u16 port) // called from ---UPnP--- thread // Attempt to portforward! -static bool UPnPMapPort(const char* addr, const u16 port) +static bool MapPort(const char* addr, const u16 port) { if (s_mapped > 0) - UPnPUnmapPort(s_mapped); + UnmapPort(s_mapped); std::string port_str = StringFromFormat("%d", port); int result = UPNP_AddPortMapping( @@ -136,9 +136,9 @@ static bool UPnPMapPort(const char* addr, const u16 port) } // UPnP thread: try to map a port -static void mapPortThread(const u16 port) +static void MapPortThread(const u16 port) { - if (initUPnP() && UPnPMapPort(s_our_ip.data(), port)) + if (InitUPnP() && MapPort(s_our_ip.data(), port)) { NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, s_our_ip.data()); return; @@ -148,24 +148,24 @@ static void mapPortThread(const u16 port) } // UPnP thread: try to unmap a port -static void unmapPortThread() +static void UnmapPortThread() { if (s_mapped > 0) - UPnPUnmapPort(s_mapped); + UnmapPort(s_mapped); } void UPnP::TryPortmapping(u16 port) { if (s_thread.joinable()) s_thread.join(); - s_thread = std::thread(&mapPortThread, port); + s_thread = std::thread(&MapPortThread, port); } void UPnP::StopPortmapping() { if (s_thread.joinable()) s_thread.join(); - s_thread = std::thread(&unmapPortThread); + s_thread = std::thread(&UnmapPortThread); s_thread.join(); } From ff1d1a7a4d2c020f647000070ea73791f7073c43 Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:45:39 -0700 Subject: [PATCH 06/13] UPnP: use std::to_string --- Source/Core/Common/UPnP.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index cb4a51574c..bedecf9a43 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -7,15 +7,16 @@ #include "Common/UPnP.h" #include "Common/Logging/Log.h" -#include "Common/StringUtil.h" #include +#include #include #include #include #include #include #include +#include static UPNPUrls s_urls; static IGDdatas s_data; @@ -108,7 +109,7 @@ static bool InitUPnP() // -- static bool UnmapPort(const u16 port) { - std::string port_str = StringFromFormat("%d", port); + std::string port_str = std::to_string(port); UPNP_DeletePortMapping(s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), "UDP", nullptr); @@ -122,7 +123,7 @@ static bool MapPort(const char* addr, const u16 port) if (s_mapped > 0) UnmapPort(s_mapped); - std::string port_str = StringFromFormat("%d", port); + std::string port_str = std::to_string(port); int result = UPNP_AddPortMapping( s_urls.controlURL, s_data.first.servicetype, port_str.c_str(), port_str.c_str(), addr, (std::string("dolphin-emu UDP on ") + addr).c_str(), "UDP", nullptr, nullptr); From a09f8744b9ef1c003e8271d031c3da93cb711635 Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 6 Aug 2017 23:58:00 -0700 Subject: [PATCH 07/13] UPnP: cleanup variable name desc_xml --- Source/Core/Common/UPnP.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index bedecf9a43..411beb45f0 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -32,7 +32,7 @@ static bool InitUPnP() static bool s_error = false; std::vector igds; - int descXMLsize = 0, upnperror = 0; + int upnperror = 0; // Don't init if already inited if (s_inited) @@ -70,19 +70,20 @@ static bool InitUPnP() for (const UPNPDev* dev : igds) { - std::unique_ptr descXML(nullptr, std::free); + int desc_xml_size = 0; + std::unique_ptr desc_xml(nullptr, std::free); int statusCode = 200; #if MINIUPNPC_API_VERSION >= 16 - descXML.reset( - static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, s_our_ip.data(), + desc_xml.reset( + static_cast(miniwget_getaddr(dev->descURL, &desc_xml_size, s_our_ip.data(), static_cast(s_our_ip.size()), 0, &statusCode))); #else - descXML.reset(static_cast(miniwget_getaddr(dev->descURL, &descXMLsize, s_our_ip.data(), - static_cast(s_our_ip.size()), 0))); + desc_xml.reset(static_cast(miniwget_getaddr( + dev->descURL, &desc_xml_size, s_our_ip.data(), static_cast(s_our_ip.size()), 0))); #endif - if (descXML && statusCode == 200) + if (desc_xml && statusCode == 200) { - parserootdesc(descXML.get(), descXMLsize, &s_data); + parserootdesc(desc_xml.get(), desc_xml_size, &s_data); GetUPNPUrls(&s_urls, &s_data, dev->descURL, 0); NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL); From fdb5828d626932653d8f3628f567d2f9cfae83d2 Mon Sep 17 00:00:00 2001 From: Michael M Date: Thu, 10 Aug 2017 12:47:27 -0700 Subject: [PATCH 08/13] Qt MainWindow: clean up Netplay settings logic --- Source/Core/DolphinQt2/MainWindow.cpp | 34 +++++++++++---------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 6797c6296b..b906b2801d 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -663,9 +663,8 @@ bool MainWindow::NetPlayJoin() } // Settings - std::string host_ip, traversal_host, nickname; - int host_port, traversal_port; - bool is_traversal; + std::string host_ip; + u16 host_port; if (Settings::Instance().GetNetPlayServer() != nullptr) { host_ip = "127.0.0.1"; @@ -677,12 +676,12 @@ bool MainWindow::NetPlayJoin() host_port = Config::Get(Config::NETPLAY_HOST_PORT); } - std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE); - is_traversal = traversal_choice == "traversal"; + const std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE); + const bool is_traversal = traversal_choice == "traversal"; - traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); - traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); - nickname = Config::Get(Config::NETPLAY_NICKNAME); + const std::string traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); + const u16 traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); + const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME); // Create Client Settings::Instance().ResetNetPlayClient( @@ -721,19 +720,14 @@ bool MainWindow::NetPlayHost(const QString& game_id) } // Settings - std::string traversal_host, nickname; - int host_port, traversal_port; - bool is_traversal, use_upnp; + u16 host_port = Config::Get(Config::NETPLAY_HOST_PORT); + const std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE); + const bool is_traversal = traversal_choice == "traversal"; + const bool use_upnp = Config::Get(Config::NETPLAY_USE_UPNP); - host_port = Config::Get(Config::NETPLAY_HOST_PORT); - std::string traversal_choice; - traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE); - is_traversal = traversal_choice == "traversal"; - use_upnp = Config::Get(Config::NETPLAY_USE_UPNP); - - traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); - traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); - nickname = Config::Get(Config::NETPLAY_NICKNAME); + const std::string traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); + const u16 traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); + const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME); if (is_traversal) host_port = Config::Get(Config::NETPLAY_LISTEN_PORT); From 4b50e77a26f651d6e77b3cc8a02f5c51739259a7 Mon Sep 17 00:00:00 2001 From: Michael M Date: Mon, 7 Aug 2017 00:22:33 -0700 Subject: [PATCH 09/13] NetPlayClient/Server: apply Parameter Object pattern to traversal parameters --- Source/Core/Core/NetPlayClient.cpp | 7 +++---- Source/Core/Core/NetPlayClient.h | 3 +-- Source/Core/Core/NetPlayProto.h | 14 ++++++++++++++ Source/Core/Core/NetPlayServer.cpp | 8 ++++---- Source/Core/Core/NetPlayServer.h | 2 +- Source/Core/DolphinQt2/MainWindow.cpp | 12 ++++++------ .../Core/DolphinWX/NetPlay/NetPlayLauncher.cpp | 16 ++++++++-------- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index b0c7f6fd16..2c98e18721 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -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(); diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 00decb8093..978cec9cb4 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -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& pid_list); diff --git a/Source/Core/Core/NetPlayProto.h b/Source/Core/Core/NetPlayProto.h index deb8d073c2..3172c7a1c8 100644 --- a/Source/Core/Core/NetPlayProto.h +++ b/Source/Core/Core/NetPlayProto.h @@ -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; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 11a05e069b..68a01365aa 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -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; diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index cf8d2e958a..517f5fc61a 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, bool traversal, const std::string& centralServer, u16 centralPort); + NetPlayServer(const u16 port, const NetTraversalConfig& traversal_config); ~NetPlayServer(); bool ChangeGame(const std::string& game); diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index b906b2801d..87a2f8e5e2 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -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) { diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp index 307a03385e..758cfa7af0 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp @@ -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); From b5d070b0cfd4c956046ee68952b9ce1986ddce49 Mon Sep 17 00:00:00 2001 From: Michael M Date: Mon, 7 Aug 2017 00:27:04 -0700 Subject: [PATCH 10/13] NetPlayServer: handle port forwarding in constructor --- Source/Core/Core/NetPlayServer.cpp | 16 +++++++--------- Source/Core/Core/NetPlayServer.h | 6 +----- Source/Core/DolphinQt2/MainWindow.cpp | 7 +------ .../Core/DolphinWX/NetPlay/NetPlayLauncher.cpp | 9 +-------- Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h | 4 +--- 5 files changed, 11 insertions(+), 31 deletions(-) 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 From 7ce9f1f984b4941dc953981ae0cdeab28f0a8efc Mon Sep 17 00:00:00 2001 From: Michael M Date: Mon, 7 Aug 2017 11:34:08 -0700 Subject: [PATCH 11/13] UPnP: remove unneeded vector in InitUPnP() --- Source/Core/Common/UPnP.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index 411beb45f0..767f49c418 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -31,7 +31,6 @@ static bool InitUPnP() static bool s_inited = false; static bool s_error = false; - std::vector igds; int upnperror = 0; // Don't init if already inited @@ -64,12 +63,9 @@ static bool InitUPnP() // Look for the IGD for (UPNPDev* dev = devlist.get(); dev; dev = dev->pNext) { - if (std::strstr(dev->st, "InternetGatewayDevice")) - igds.push_back(dev); - } + if (!std::strstr(dev->st, "InternetGatewayDevice")) + continue; - for (const UPNPDev* dev : igds) - { int desc_xml_size = 0; std::unique_ptr desc_xml(nullptr, std::free); int statusCode = 200; From 0e51082bbba2d1d1722b496580e50acb7e3040b3 Mon Sep 17 00:00:00 2001 From: Michael M Date: Mon, 7 Aug 2017 11:34:53 -0700 Subject: [PATCH 12/13] UPnP: move variable declaration to where it's used --- Source/Core/Common/UPnP.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index 767f49c418..2ca9fc9e54 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -31,8 +31,6 @@ static bool InitUPnP() static bool s_inited = false; static bool s_error = false; - int upnperror = 0; - // Don't init if already inited if (s_inited) return true; @@ -45,6 +43,7 @@ static bool InitUPnP() std::memset(&s_data, 0, sizeof(IGDdatas)); // Find all UPnP devices + int upnperror = 0; std::unique_ptr devlist(nullptr, freeUPNPDevlist); #if MINIUPNPC_API_VERSION >= 14 devlist.reset(upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &upnperror)); From 8702ffccc3683d7b3d57bfdfbf6078fcfd02075b Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 13 Aug 2017 18:45:54 -0700 Subject: [PATCH 13/13] UPnP: use value-initialization instead of std::memset --- Source/Core/Common/UPnP.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/UPnP.cpp b/Source/Core/Common/UPnP.cpp index 2ca9fc9e54..47c4cf8337 100644 --- a/Source/Core/Common/UPnP.cpp +++ b/Source/Core/Common/UPnP.cpp @@ -39,8 +39,8 @@ static bool InitUPnP() if (s_error) return false; - std::memset(&s_urls, 0, sizeof(UPNPUrls)); - std::memset(&s_data, 0, sizeof(IGDdatas)); + s_urls = {}; + s_data = {}; // Find all UPnP devices int upnperror = 0;