From acc78d0ee511bbd5dd787bf16992014875e2ce85 Mon Sep 17 00:00:00 2001 From: Logan-A Date: Sat, 30 Dec 2023 23:41:34 -0500 Subject: [PATCH] Update i_tcp.c made UPnP port mapping enabled by default lowered UPnP Discover delay from 2000 ms to 500 ms only look for first InternetGatewayDevice found remove UPnP port mapping on shutdown --- src/i_tcp.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 387cf4f5e..05e678acd 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -268,23 +268,24 @@ static const char* inet_ntopA(short af, const void *cp, char *buf, socklen_t len #endif #ifdef HAVE_MINIUPNPC // based on old XChat patch +static void I_ShutdownUPnP(void); static struct UPNPUrls urls; static struct IGDdatas data; static char lanaddr[64]; -static void I_ShutdownUPnP(void) -{ - FreeUPNPUrls(&urls); -} - static inline void I_InitUPnP(void) { + const char * const deviceTypes[] = { + "urn:schemas-upnp-org:device:InternetGatewayDevice:2", + "urn:schemas-upnp-org:device:InternetGatewayDevice:1", + 0 + }; struct UPNPDev * devlist = NULL; int upnp_error = -2; int scope_id = 0; int status_code = 0; CONS_Printf(M_GetText("Looking for UPnP Internet Gateway Device\n")); - devlist = upnpDiscover(2000, NULL, NULL, 0, false, 2, &upnp_error); + devlist = upnpDiscoverDevices(deviceTypes, 500, NULL, NULL, 0, false, 2, &upnp_error, 0); if (devlist) { struct UPNPDev *dev = devlist; @@ -340,6 +341,12 @@ static inline void I_UPnP_rem(const char *port, const char * servicetype) UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port, servicetype, NULL); } + +static void I_ShutdownUPnP(void) +{ + I_UPnP_rem(serverport_name, "UDP"); + FreeUPNPUrls(&urls); +} #endif static const char *SOCK_AddrToStr(mysockaddr_t *sk) @@ -1130,10 +1137,10 @@ boolean I_InitTcpDriver(void) { I_AddExitFunc(I_ShutdownTcpDriver); #ifdef HAVE_MINIUPNPC - if (M_CheckParm("-useUPnP")) - I_InitUPnP(); - else + if (M_CheckParm("-noUPnP")) UPNP_support = false; + else + I_InitUPnP(); #endif } return init_tcp_driver;