Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Core/GameEngine/Include/Common/OptionPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class OptionPreferences : public UserPreferences
Int getFirewallBehavior();
Short getFirewallPortAllocationDelta();
UnsignedShort getFirewallPortOverride();
Bool getFirewallNeedToRefresh();
Bool usesSystemMapDir();
AsciiString getPreferred3DProvider();
AsciiString getSpeakerType();
Expand Down Expand Up @@ -132,4 +131,8 @@ class OptionPreferences : public UserPreferences
Bool getShowMoneyPerMinute() const;

Real getGameWindowTransitionSpeedMultiplier() const;

private:

void setIPAddress(AsciiString key, AsciiString IP);
};
4 changes: 1 addition & 3 deletions Core/GameEngine/Include/GameNetwork/FirewallHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class FirewallHelperClass {
FirewallHelperClass();
virtual ~FirewallHelperClass();
Bool detectFirewall();
void detectFirewallBehavior();
UnsignedShort getRawFirewallBehavior() {return((UnsignedShort)m_behavior);}
Short getSourcePortAllocationDelta();
Int getFirewallHardness(FirewallBehaviorType behavior);
Expand Down Expand Up @@ -239,12 +240,9 @@ class FirewallHelperClass {
return(FALSE);
};



private:

Int getNATPortAllocationScheme(Int numPorts, UnsignedShort *originalPorts, UnsignedShort *mangledPorts, Bool &relativeDelta, Bool &looksGood);
void detectFirewallBehavior(/*Bool &canRecord*/);
Bool getReferencePort();

SpareSocketStruct * findSpareSocketByPort(UnsignedShort port);
Expand Down
43 changes: 20 additions & 23 deletions Core/GameEngine/Source/Common/OptionPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "GameLogic/ScriptEngine.h"

#include "GameNetwork/IPEnumeration.h"
#include "GameNetwork/FirewallHelper.h"

OptionPreferences::OptionPreferences()
{
Expand Down Expand Up @@ -140,16 +141,27 @@ UnsignedInt OptionPreferences::getLANIPAddress()
return TheGlobalData->m_defaultIP;
}

void OptionPreferences::setIPAddress(AsciiString key, AsciiString IP)
{
if ((*this)[key].compareNoCase(IP) == 0)
return;

(*this)[key] = IP;

if (TheFirewallHelper != nullptr)
TheFirewallHelper->flagNeedToRefresh(TRUE);

@xezon xezon Jul 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this class is not intended to set state elsewhere in the program. Can this be implemented differently to keep the focus of this class for writing options?

}

void OptionPreferences::setLANIPAddress(AsciiString IP)
{
(*this)["IPAddress"] = IP;
setIPAddress("IPAddress", IP);
}

void OptionPreferences::setLANIPAddress(UnsignedInt IP)
{
AsciiString tmp;
tmp.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
(*this)["IPAddress"] = tmp;
AsciiString ipString;
ipString.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
setLANIPAddress(ipString);
}

UnsignedInt OptionPreferences::getOnlineIPAddress()
Expand All @@ -170,14 +182,14 @@ UnsignedInt OptionPreferences::getOnlineIPAddress()

void OptionPreferences::setOnlineIPAddress(AsciiString IP)
{
(*this)["GameSpyIPAddress"] = IP;
setIPAddress("GameSpyIPAddress", IP);
}

void OptionPreferences::setOnlineIPAddress(UnsignedInt IP)
{
AsciiString tmp;
tmp.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
(*this)["GameSpyIPAddress"] = tmp;
AsciiString ipString;
ipString.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
setOnlineIPAddress(ipString);
}

Bool OptionPreferences::getArchiveReplaysEnabled() const
Expand Down Expand Up @@ -501,21 +513,6 @@ UnsignedShort OptionPreferences::getFirewallPortOverride()
return portOverride;
}

Bool OptionPreferences::getFirewallNeedToRefresh()
{
OptionPreferences::const_iterator it = find("FirewallNeedToRefresh");
if (it == end()) {
return FALSE;
}

Bool retval = FALSE;
AsciiString str = it->second;
if (str.compareNoCase("TRUE") == 0) {
retval = TRUE;
}
return retval;
}

AsciiString OptionPreferences::getPreferred3DProvider()
{
OptionPreferences::const_iterator it = find("3DAudioProvider");
Expand Down
41 changes: 19 additions & 22 deletions Core/GameEngine/Source/GameNetwork/FirewallHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@
#include "GameNetwork/NAT.h"
#include "GameNetwork/udp.h"
#include "GameNetwork/NetworkDefs.h"
#include "GameNetwork/IPEnumeration.h"
#include "GameNetwork/GameSpy/GSConfig.h"


FirewallHelperClass *TheFirewallHelper = nullptr;

FirewallHelperClass * createFirewallHelper()
{
return NEW FirewallHelperClass();
FirewallHelperClass *helper = NEW FirewallHelperClass();
Comment thread
githubawn marked this conversation as resolved.
helper->detectFirewallBehavior();
return helper;
}


Expand Down Expand Up @@ -176,22 +179,12 @@ void FirewallHelperClass::reset()
*=============================================================================================*/
Bool FirewallHelperClass::detectFirewall()
{
OptionPreferences pref;

OptionPreferences::const_iterator it = pref.find("FirewallNeedToRefresh");
if (it != pref.end()) {
AsciiString str = it->second;
if (str.compareNoCase("TRUE") == 0) {
TheWritableGlobalData->m_firewallBehavior = FIREWALL_TYPE_UNKNOWN;
}
}

if (TheWritableGlobalData->m_firewallBehavior == FIREWALL_TYPE_UNKNOWN) {
if (m_behavior == FIREWALL_TYPE_UNKNOWN) {
detectFirewallBehavior();

return FALSE;
} else {
DEBUG_LOG(("FirewallHelperClass::detectFirewall - firewall behavior already specified as %d, port allocation delta is %d, skipping detection.", TheWritableGlobalData->m_firewallBehavior, TheWritableGlobalData->m_firewallPortAllocationDelta));
DEBUG_LOG(("FirewallHelperClass::detectFirewall - firewall behavior already specified as %d, port allocation delta is %d, skipping detection.", m_behavior, m_sourcePortAllocationDelta));
}

return TRUE;
Expand Down Expand Up @@ -535,11 +528,9 @@ void FirewallHelperClass::writeFirewallBehavior()
*=============================================================================================*/
void FirewallHelperClass::flagNeedToRefresh(Bool flag)
{
Comment thread
greptile-apps[bot] marked this conversation as resolved.
OptionPreferences pref;

(pref)["FirewallNeedToRefresh"] = flag ? "TRUE" : "FALSE";

pref.write();
if (flag) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag argument looks very useless. Can be removed. "Munkee" text above needs updating then.

detectFirewallBehavior();
}
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.


Expand Down Expand Up @@ -581,15 +572,21 @@ void FirewallHelperClass::readFirewallBehavior()
* HISTORY: *
* 3/15/01 12:30PM ST : Created *
*=============================================================================================*/
void FirewallHelperClass::detectFirewallBehavior(/*Bool &canRecord*/)
void FirewallHelperClass::detectFirewallBehavior()
{
m_behavior = FIREWALL_TYPE_SIMPLE;

reset();
m_currentTry = 0;
m_numManglers = 0;
m_numResponses = 0;
m_packetID = 0;
m_timeoutLength = 0;
m_timeoutStart = 0;
m_sourcePortAllocationDelta = 0;
m_behavior = FIREWALL_TYPE_UNKNOWN;
m_currentState = DETECTIONSTATE_BEGIN;
}

FirewallHelperClass::FirewallBehaviorType FirewallHelperClass::getFirewallBehavior() {
m_currentState = DETECTIONSTATE_IDLE;
return m_behavior;
}

Expand Down
14 changes: 0 additions & 14 deletions Core/GameEngine/Source/GameNetwork/NAT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ NATStateType NAT::update() {
{
m_NATState = NATSTATE_DONE;
TheEstablishConnectionsMenu->endMenu();

delete TheFirewallHelper;
TheFirewallHelper = nullptr;
}
} else if (m_NATState == NATSTATE_DOCONNECTIONPATHS) {
if (allConnectionsDoneThisRound() == TRUE) {
Expand Down Expand Up @@ -257,18 +254,7 @@ NATStateType NAT::update() {
m_NATState = NATSTATE_FAILED;
TheEstablishConnectionsMenu->endMenu();
if (TheFirewallHelper != nullptr) {
// we failed NAT negotiation, perhaps we need to redetect our firewall settings.
// We don't trust the user to do it for themselves so we force them to do it next time
// the log in.
// 2/19/03 - ok, we don't want to do this right away, if the user tries to play in another game
// before they log out and log back in the game won't have a chance at working.
// so we need to simply flag it so that when they log out the firewall behavior gets blown away.
TheFirewallHelper->flagNeedToRefresh(TRUE);
// TheWritableGlobalData->m_firewallBehavior = FirewallHelperClass::FIREWALL_TYPE_UNKNOWN;
// TheFirewallHelper->writeFirewallBehavior();

delete TheFirewallHelper;
TheFirewallHelper = nullptr;
}
// we failed to connect, so we don't have to pass on the transport to the network.
delete m_transport;
Expand Down
1 change: 0 additions & 1 deletion Generals/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,6 @@ void GlobalData::parseGameDataDefinition( INI* ini )
TheWritableGlobalData->m_moveScrollAnchor = optionPref.getMoveScrollAnchor();
TheWritableGlobalData->m_defaultIP = optionPref.getLANIPAddress();
TheWritableGlobalData->m_firewallSendDelay = optionPref.getSendDelay();
TheWritableGlobalData->m_firewallBehavior = optionPref.getFirewallBehavior();
TheWritableGlobalData->m_firewallPortAllocationDelta = optionPref.getFirewallPortAllocationDelta();
TheWritableGlobalData->m_firewallPortOverride = optionPref.getFirewallPortOverride();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ static GameWindow * checkDrawAnchor = nullptr;
static NameKeyType checkMoveAnchorID = NAMEKEY_INVALID;
static GameWindow * checkMoveAnchor = nullptr;

static NameKeyType buttonFirewallRefreshID = NAMEKEY_INVALID;
static GameWindow * buttonFirewallRefresh = nullptr;
//
//static NameKeyType checkAudioHardwareID = NAMEKEY_INVALID;
//static GameWindow * checkAudioHardware = nullptr;
Expand Down Expand Up @@ -970,8 +968,10 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
checkLanguageFilter = TheWindowManager->winGetWindowFromId( nullptr, checkLanguageFilterID );
checkSendDelayID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:CheckSendDelay" );
checkSendDelay = TheWindowManager->winGetWindowFromId( nullptr, checkSendDelayID);
buttonFirewallRefreshID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:ButtonFirewallRefresh" );
buttonFirewallRefresh = TheWindowManager->winGetWindowFromId( nullptr, buttonFirewallRefreshID);
// TheSuperHackers @info 25/07/2026 Refresh button has been hidden, we have migrated this to self-healing NAT
GameWindow *buttonFirewallRefresh = TheWindowManager->winGetWindowFromId(nullptr, NAMEKEY("OptionsMenu.wnd:ButtonFirewallRefresh"));
if (buttonFirewallRefresh)
buttonFirewallRefresh->winHide(TRUE);
checkDrawAnchorID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:CheckBoxDrawAnchor" );
checkDrawAnchor = TheWindowManager->winGetWindowFromId( nullptr, checkDrawAnchorID);
checkMoveAnchorID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:CheckBoxMoveAnchor" );
Expand Down Expand Up @@ -1696,18 +1696,6 @@ WindowMsgHandledType OptionsMenuSystem( GameWindow *window, UnsignedInt msg,
(*pref)["UseCameraInReplays"] = "no";
}
}
else if (controlID == buttonFirewallRefreshID)
{
// setting the behavior to unknown will force the firewall helper to detect the firewall behavior
// the next time we log into gamespy/WOL/whatever.
char num[16];
num[0] = 0;
TheWritableGlobalData->m_firewallBehavior = FirewallHelperClass::FIREWALL_TYPE_UNKNOWN;
itoa(TheGlobalData->m_firewallBehavior, num, 10);
AsciiString numstr;
numstr = num;
(*pref)["FirewallBehavior"] = numstr;
}
break;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,8 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )
CustomMatchPreferences customPref;
hostSlot->setColor( customPref.getPreferredColor() );
hostSlot->setPlayerTemplate( customPref.getPreferredFaction() );
hostSlot->setNATBehavior((FirewallHelperClass::FirewallBehaviorType)natPref.getFirewallBehavior());
FirewallHelperClass::FirewallBehaviorType natBehavior = TheFirewallHelper ? TheFirewallHelper->getFirewallBehavior() : FirewallHelperClass::FIREWALL_TYPE_UNKNOWN;
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
hostSlot->setNATBehavior(natBehavior);
hostSlot->setPingString(TheGameSpyInfo->getPingString());
game->setMap(customPref.getPreferredMap());

Expand Down Expand Up @@ -1260,7 +1261,8 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )
options.format("Color=%d", customPref.getPreferredColor());
req.options = options.str();
TheGameSpyPeerMessageQueue->addRequest(req);
options.format("NAT=%d", natPref.getFirewallBehavior());
FirewallHelperClass::FirewallBehaviorType natBehavior = TheFirewallHelper ? TheFirewallHelper->getFirewallBehavior() : FirewallHelperClass::FIREWALL_TYPE_UNKNOWN;
options.format("NAT=%d", natBehavior);
req.options = options.str();
TheGameSpyPeerMessageQueue->addRequest(req);
options.format("Ping=%s", TheGameSpyInfo->getPingString().str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,7 @@ WindowMsgHandledType WOLQuickMatchMenuSystem( GameWindow *window, UnsignedInt ms
index = (Int)GadgetComboBoxGetItemData( comboBoxColor, selected );
req.QM.color = index;

OptionPreferences natPref;
req.QM.NAT = natPref.getFirewallBehavior();
req.QM.NAT = TheFirewallHelper ? TheFirewallHelper->getFirewallBehavior() : FirewallHelperClass::FIREWALL_TYPE_UNKNOWN;

if (ladderIndex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,6 @@ void WOLWelcomeMenuInit( WindowLayout *layout, void *userData )
if (TheFirewallHelper == nullptr) {
TheFirewallHelper = createFirewallHelper();
}
if (TheFirewallHelper->detectFirewall() == TRUE) {
// don't need to detect firewall, already been done.
delete TheFirewallHelper;
TheFirewallHelper = nullptr;
}
/*

if (TheGameSpyChat && TheGameSpyChat->isConnected())
Expand Down Expand Up @@ -550,9 +545,6 @@ void WOLWelcomeMenuShutdown( WindowLayout *layout, void *userData )
{
listboxInfo = nullptr;

delete TheFirewallHelper;
TheFirewallHelper = nullptr;

isShuttingDown = TRUE;

// if we are shutting down for an immediate pop, skip the animations
Expand Down Expand Up @@ -590,18 +582,7 @@ void WOLWelcomeMenuUpdate( WindowLayout * layout, void *userData)

if (TheFirewallHelper != nullptr)
{
if (TheFirewallHelper->behaviorDetectionUpdate())
{
TheWritableGlobalData->m_firewallBehavior = TheFirewallHelper->getFirewallBehavior();

TheFirewallHelper->writeFirewallBehavior();

TheFirewallHelper->flagNeedToRefresh(FALSE); // 2/19/03 BGC, we're done, so we don't need to refresh the NAT anymore.

// we are now done with the firewall helper
delete TheFirewallHelper;
TheFirewallHelper = nullptr;
}
TheFirewallHelper->behaviorDetectionUpdate();
}

if (TheShell->isAnimFinished() && !buttonPushed && TheGameSpyPeerMessageQueue)
Expand Down
16 changes: 1 addition & 15 deletions Generals/Code/GameEngine/Source/GameNetwork/GameSpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,7 @@ void GameSpyChat::update()
}

if (TheFirewallHelper != nullptr) {
if (TheFirewallHelper->behaviorDetectionUpdate()) {
TheGlobalData->m_firewallBehavior = TheFirewallHelper->getFirewallBehavior();
OptionPreferences *pref = NEW OptionPreferences;
char num[16];
num[0] = 0;
itoa(TheGlobalData->m_firewallBehavior, num, 10);
AsciiString numstr;
numstr = num;
(*pref)["FirewallBehavior"] = numstr;
pref->write();

// we are now done with the firewall helper
delete TheFirewallHelper;
TheFirewallHelper = nullptr;
}
TheFirewallHelper->behaviorDetectionUpdate();
}

UnsignedInt now = timeGetTime();
Expand Down
1 change: 0 additions & 1 deletion GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,6 @@ void GlobalData::parseGameDataDefinition( INI* ini )
TheWritableGlobalData->m_moveScrollAnchor = optionPref.getMoveScrollAnchor();
TheWritableGlobalData->m_defaultIP = optionPref.getLANIPAddress();
TheWritableGlobalData->m_firewallSendDelay = optionPref.getSendDelay();
TheWritableGlobalData->m_firewallBehavior = optionPref.getFirewallBehavior();
TheWritableGlobalData->m_firewallPortAllocationDelta = optionPref.getFirewallPortAllocationDelta();
TheWritableGlobalData->m_firewallPortOverride = optionPref.getFirewallPortOverride();

Expand Down
Loading
Loading