Skip to content

Commit aa2ddfb

Browse files
committed
- Added a compile flag to disable/enable port mapper
1 parent 136508e commit aa2ddfb

9 files changed

Lines changed: 42 additions & 30 deletions

File tree

‎GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#define GENERALS_ONLINE
55
#endif
66

7+
//#define USE_PORT_MAPPER 1
8+
79
#if !defined(_DEBUG)
810
//#define USE_TEST_ENV 1
911
#endif

‎GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_Init.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ class NGMP_OnlineServicesManager
406406

407407
void Tick();
408408

409+
#if defined(USE_PORT_MAPPER)
409410
PortMapper& GetPortMapper() { return m_PortMapper; }
411+
#endif
410412

411413
void ProcessMOTD(const char* szMOTD)
412414
{
@@ -442,7 +444,9 @@ class NGMP_OnlineServicesManager
442444
ServiceConfig& GetServiceConfig() { return m_ServiceConfig; }
443445

444446
private:
447+
#if defined(USE_PORT_MAPPER)
445448
PortMapper m_PortMapper;
449+
#endif
446450

447451
ServiceConfig m_ServiceConfig;
448452

‎GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/PortMapper.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#if defined(USE_PORT_MAPPER)
4+
35
//#define DISABLE_UPNP 1
46
//#define DISABLE_NATPMP 1
57
//#define DISABLE_PCP 1
@@ -98,4 +100,4 @@ class PortMapper
98100
int m_PCPMappingHandle = -1;
99101
};
100102

101-
// TODO_PORT: What if everything fails? does it still return?
103+
#endif

‎GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp‎

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ static void updateNumPlayersOnline(void)
272272
GadgetListBoxAddEntryText(listboxInfo, UnicodeString(L" "), GameSpyColor[GSCOLOR_MOTD_HEADING], -1, -1);
273273

274274
// NETWORK CAPS
275+
#if defined(USE_PORT_MAPPER)
275276
bool bHasPortMapped = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().HasPortOpen();
276277
PortMapper::EMappingTech mappingTechUsed = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetPortMappingTechnologyUsed();
277278

@@ -314,6 +315,7 @@ static void updateNumPlayersOnline(void)
314315
strPortState = "No Port Mapped";
315316
}
316317
}
318+
#endif
317319

318320
// END NETWORK CAPS
319321
while (aMotd.nextToken(&aLine, "\n"))
@@ -350,9 +352,7 @@ static void updateNumPlayersOnline(void)
350352
GadgetListBoxAddEntryText(listboxInfo, line, c, -1, -1);
351353
}
352354

353-
// add network caps
354-
355-
//ECapabilityState NATDirectConnect = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().HasDirectConnect();
355+
#if defined(USE_PORT_MAPPER)
356356
int preferredPort = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetOpenPort();
357357
{
358358
Color c = GameMakeColor(255, 194, 15, 255);
@@ -366,33 +366,8 @@ static void updateNumPlayersOnline(void)
366366
// network port
367367
line.format(L"Network Port: %d (%hs)", preferredPort, strPortState.c_str());
368368
GadgetListBoxAddEntryText(listboxInfo, line, c, -1, -1);
369-
370-
/*
371-
// direct connect
372-
line.format(L"Direct Connect: %hs%hs",
373-
NATDirectConnect == ECapabilityState::UNDETERMINED ? "Still Being Determined..." : NATDirectConnect == ECapabilityState::SUPPORTED ? "Supported" : "Unsupported",
374-
#if !defined(GENERALS_ONLINE_PORT_MAP_FIREWALL_OVERRIDE_PORT)
375-
(mappingTechUsed == PortMapper::EMappingTech::MANUAL) ? (NATDirectConnect == ECapabilityState::SUPPORTED ? "" : "\n\tWARNING: You have manually set a firewall port which does not appear to be open. Direct connectivity may not work.") : "",
376-
#else
377-
""
378-
#endif
379-
);
380-
381-
GadgetListBoxAddEntryText(listboxInfo, line, c, -1, -1);
382-
*/
383-
384-
/*
385-
// relayed connect
386-
line.format(L"Relayed Connect: %hs", "Supported");
387-
GadgetListBoxAddEntryText(listboxInfo, line, c, -1, -1);
388-
389-
390-
// server region
391-
line.format(L"Server Region: %hs (%dms)", NGMP_OnlineServicesManager::GetInstance()->GetQoSManager().GetPreferredRegionName().c_str(),
392-
NGMP_OnlineServicesManager::GetInstance()->GetQoSManager().GetPreferredRegionLatency());
393-
GadgetListBoxAddEntryText(listboxInfo, line, c, -1, -1);
394-
*/
395369
}
370+
#endif
396371

397372
}
398373
}

‎GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NetworkMesh.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,11 @@ NetworkMesh::NetworkMesh()
642642
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING LOGFUNC] %s", pszMsg);
643643
});
644644

645+
#if defined(USE_PORT_MAPPER)
645646
int localPort = serviceConf.use_mapped_port ? NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetOpenPort() : 0;
647+
#else
648+
int localPort = 0;
649+
#endif
646650

647651
// create sockets
648652
SteamNetworkingConfigValue_t opt;
@@ -772,7 +776,12 @@ void NetworkMesh::StartConnectionSignalling(int64_t remoteUserID, uint16_t prefe
772776

773777
ServiceConfig& serviceConf = pOnlineServicesMgr->GetServiceConfig();
774778

779+
#if defined(USE_PORT_MAPPER)
775780
int g_nLocalPort = serviceConf.use_mapped_port ? pOnlineServicesMgr->GetPortMapper().GetOpenPort() : 0;
781+
#else
782+
int g_nLocalPort = 0;
783+
#endif
784+
776785
int g_nVirtualPortRemote = serviceConf.use_mapped_port ? preferredPort : 0;
777786

778787
// Our remote and local port don't match, so we need to set it explicitly

‎GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_Auth.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ void NGMP_OnlineServices_AuthInterface::GoToDetermineNetworkCaps()
7575
{
7676
// move on to network capabilities section
7777
// this is done in the background, but we'll update the MOTD when done to show the latest status
78+
#if defined(USE_PORT_MAPPER)
7879
NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().DetermineLocalNetworkCapabilities();
80+
#endif
7981

8082
// GET MOTD
8183
std::string strURI = NGMP_OnlineServicesManager::GetAPIEndpoint("MOTD");

‎GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_Init.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ void NGMP_OnlineServicesManager::Tick()
434434
m_pAuthInterface->Tick();
435435
}
436436

437+
#if defined(USE_PORT_MAPPER)
437438
m_PortMapper.Tick();
439+
#endif
438440

439441
if (m_pRoomInterface != nullptr)
440442
{

‎GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,12 @@ void NGMP_OnlineServices_LobbyInterface::JoinLobby(LobbyEntry lobbyInfo, std::st
853853
bool bHasMap = TheMapCache->findMap(AsciiString(lobbyInfo.map_path.c_str()));
854854

855855
nlohmann::json j;
856+
#if defined(USE_PORT_MAPPER)
856857
j["preferred_port"] = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetOpenPort();
858+
#else
859+
j["preferred_port"] = 0;
860+
#endif
861+
857862
j["has_map"] = bHasMap;
858863

859864
if (!strPassword.empty())
@@ -1088,7 +1093,11 @@ void NGMP_OnlineServices_LobbyInterface::CreateLobby(UnicodeString strLobbyName,
10881093
j["map_path"] = sanitizedMapPath.str();
10891094
j["map_official"] = bIsOfficial;
10901095
j["max_players"] = initialMaxSize;
1096+
#if defined(USE_PORT_MAPPER)
10911097
j["preferred_port"] = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetOpenPort();
1098+
#else
1099+
j["preferred_port"] = 0;
1100+
#endif
10921101
j["vanilla_teams"] = bVanillaTeamsOnly;
10931102
j["track_stats"] = bTrackStats;
10941103
j["starting_cash"] = startingCash;
@@ -1157,7 +1166,11 @@ void NGMP_OnlineServices_LobbyInterface::CreateLobby(UnicodeString strLobbyName,
11571166
me.user_id = m_CurrentLobby.owner;
11581167
me.display_name = pAuthInterface->GetDisplayName();
11591168
me.m_bIsReady = true; // host is always ready
1169+
#if defined(USE_PORT_MAPPER)
11601170
me.preferredPort = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetOpenPort();
1171+
#else
1172+
me.preferredPort = 0;
1173+
#endif
11611174

11621175
m_CurrentLobby.members.push_back(me);
11631176

‎GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/PortMapper.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#if defined(USE_PORT_MAPPER)
2+
13
#if defined(_DEBUG)
24
//#define DISABLE_PORT_MAPPING 1
35
#endif
@@ -519,3 +521,4 @@ void PortMapper::InvokeCallback()
519521
NGMP_OnlineServicesManager::GetInstance()->m_cbPortMapperCallback();
520522
}
521523
}
524+
#endif

0 commit comments

Comments
 (0)