mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
a69dc599a9
Fix pointer and pointer array variable naming Huge renaming to match our rules Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)[^a]\w+\[ (?!(return|delete)\b)\b\w+ (?!(m_|ms_|g_|gs_|s_))[^a]\w+\[ Further format static variables Format almost all pointer names accordingly Used regex: (?!(return)\b)\b\w+ \*(?!(m_p|p|s_p|m_ap|s_ap|g_p|g_ap|ap|gs_ap|ms_ap|gs_p|ms_p))\w+\b[^:\(p] clang-format Fix CI fail Fix misnamed non pointer as pointer and non array as array Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)p\w+\b (?!return\b)\b\w+ (ms_|m_|g_|gs_|s_)a\w+\b[^\[] clang-format Revert to SCREAMING_SNAKE_CASE and reinstate dead code
76 lines
1.8 KiB
C++
76 lines
1.8 KiB
C++
#ifdef CONF_UPNP
|
|
|
|
#include "upnp.h"
|
|
#include <base/system.h>
|
|
#include <engine/shared/config.h>
|
|
#include <game/version.h>
|
|
#include <miniupnpc/miniupnpc.h>
|
|
#include <miniupnpc/upnpcommands.h>
|
|
#include <miniupnpc/upnperrors.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
void CUPnP::Open(NETADDR Address)
|
|
{
|
|
if(g_Config.m_SvUseUPnP)
|
|
{
|
|
m_Enabled = false;
|
|
m_Addr = Address;
|
|
m_pUPnPUrls = (struct UPNPUrls *)malloc(sizeof(struct UPNPUrls));
|
|
m_pUPnPData = (struct IGDdatas *)malloc(sizeof(struct IGDdatas));
|
|
|
|
char aLanAddr[64];
|
|
char aPort[6];
|
|
int Error;
|
|
|
|
m_pUPnPDevice = upnpDiscover(2000, NULL, NULL, 0, 0, 2, &Error);
|
|
|
|
int Status = UPNP_GetValidIGD(m_pUPnPDevice, m_pUPnPUrls, m_pUPnPData, aLanAddr, sizeof(aLanAddr));
|
|
dbg_msg("upnp", "status=%d, lan_addr=%s", Status, aLanAddr);
|
|
|
|
if(Status == 1)
|
|
{
|
|
m_Enabled = true;
|
|
dbg_msg("upnp", "found valid IGD: %s", m_pUPnPUrls->controlURL);
|
|
str_format(aPort, sizeof(aPort), "%d", m_Addr.port);
|
|
Error = UPNP_AddPortMapping(m_pUPnPUrls->controlURL, m_pUPnPData->first.servicetype,
|
|
aPort, aPort, aLanAddr,
|
|
"DDNet Server " GAME_RELEASE_VERSION,
|
|
"UDP", NULL, "0");
|
|
|
|
if(Error)
|
|
dbg_msg("upnp", "failed to map port, error: %s", strupnperror(Error));
|
|
else
|
|
dbg_msg("upnp", "successfully mapped port");
|
|
}
|
|
else
|
|
dbg_msg("upnp", "no valid IGD found, disabled");
|
|
}
|
|
}
|
|
|
|
void CUPnP::Shutdown()
|
|
{
|
|
if(g_Config.m_SvUseUPnP)
|
|
{
|
|
if(m_Enabled)
|
|
{
|
|
char aPort[6];
|
|
str_format(aPort, sizeof(aPort), "%d", m_Addr.port);
|
|
int Error = UPNP_DeletePortMapping(m_pUPnPUrls->controlURL, m_pUPnPData->first.servicetype, aPort, "UDP", NULL);
|
|
|
|
if(Error != 0)
|
|
{
|
|
dbg_msg("upnp", "failed to delete port mapping on shutdown: %s", strupnperror(Error));
|
|
}
|
|
FreeUPNPUrls(m_pUPnPUrls);
|
|
freeUPNPDevlist(m_pUPnPDevice);
|
|
}
|
|
free(m_pUPnPUrls);
|
|
free(m_pUPnPData);
|
|
m_pUPnPUrls = NULL;
|
|
m_pUPnPData = NULL;
|
|
}
|
|
}
|
|
|
|
#endif
|