From 83c8ec1b4a3d17cd6a78aa3eefeceda8151cbb8d Mon Sep 17 00:00:00 2001 From: Dunedan Date: Thu, 20 Feb 2025 21:48:00 +0100 Subject: [PATCH] Create port forwarding for correct port with UPnP Up to know the UPnP logic ignored the port a user was hosting a game on and always added a port forwarding for the default port UDP 20595. This commit fixes that, so a port forwarding is added for the actual port a game is hosted on. (cherry picked from commit fcd3fc2aa33a45458d080b7ef9a3e02e7d8fa8ba) Signed-off-by: Itms --- source/network/NetServer.cpp | 6 +++--- source/network/NetServer.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index b3706530a6..2d1aaaf758 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -193,20 +193,20 @@ bool CNetServerWorker::SetupConnection(const u16 port) #if CONFIG2_MINIUPNPC // Launch the UPnP thread - m_UPnPThread = std::thread(Threading::HandleExceptions::Wrapper); + m_UPnPThread = std::thread(Threading::HandleExceptions::Wrapper, port); #endif return true; } #if CONFIG2_MINIUPNPC -void CNetServerWorker::SetupUPnP() +void CNetServerWorker::SetupUPnP(const u16 port) { debug_SetThreadName("UPnP"); // Values we want to set. char psPort[6]; - sprintf_s(psPort, ARRAY_SIZE(psPort), "%d", PS_DEFAULT_PORT); + sprintf_s(psPort, ARRAY_SIZE(psPort), "%d", port); const char* leaseDuration = "0"; // Indefinite/permanent lease duration. const char* description = "0AD Multiplayer"; const char* protocall = "UDP"; diff --git a/source/network/NetServer.h b/source/network/NetServer.h index 3d6151b7eb..27ee62ef27 100644 --- a/source/network/NetServer.h +++ b/source/network/NetServer.h @@ -436,7 +436,7 @@ private: /** * Try to find a UPnP root on the network and setup port forwarding. */ - static void SetupUPnP(); + static void SetupUPnP(const u16 port); std::thread m_UPnPThread; #endif