Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 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
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(/*Bool &canRecord*/);
Comment thread
githubawn marked this conversation as resolved.
Outdated
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
34 changes: 15 additions & 19 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 @@ -142,14 +143,19 @@ UnsignedInt OptionPreferences::getLANIPAddress()

void OptionPreferences::setLANIPAddress(AsciiString IP)
{
(*this)["IPAddress"] = IP;
if ((*this)["IPAddress"].compareNoCase(IP) != 0)
Comment thread
githubawn marked this conversation as resolved.
Outdated
{
(*this)["IPAddress"] = IP;
if (TheFirewallHelper != nullptr)
Comment thread
githubawn marked this conversation as resolved.
Outdated
TheFirewallHelper->flagNeedToRefresh(TRUE);
}
}

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

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

void OptionPreferences::setOnlineIPAddress(AsciiString IP)
{
(*this)["GameSpyIPAddress"] = IP;
if ((*this)["GameSpyIPAddress"].compareNoCase(IP) != 0)
Comment thread
githubawn marked this conversation as resolved.
Outdated
{
(*this)["GameSpyIPAddress"] = IP;
if (TheFirewallHelper != nullptr)
TheFirewallHelper->flagNeedToRefresh(TRUE);
}
}

void OptionPreferences::setOnlineIPAddress(UnsignedInt IP)
{
AsciiString tmp;
Comment thread
githubawn marked this conversation as resolved.
Outdated
tmp.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
(*this)["GameSpyIPAddress"] = tmp;
setOnlineIPAddress(tmp);
}

Bool OptionPreferences::getArchiveReplaysEnabled() const
Expand Down Expand Up @@ -501,21 +512,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
30 changes: 10 additions & 20 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 @@ -583,13 +574,12 @@ void FirewallHelperClass::readFirewallBehavior()
*=============================================================================================*/
void FirewallHelperClass::detectFirewallBehavior(/*Bool &canRecord*/)
{
m_behavior = FIREWALL_TYPE_SIMPLE;
m_behavior = FIREWALL_TYPE_UNKNOWN;

m_currentState = DETECTIONSTATE_BEGIN;
}

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

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,9 @@ 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);
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 +1695,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 @@ -592,8 +587,6 @@ void WOLWelcomeMenuUpdate( WindowLayout * layout, void *userData)
{
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.
Expand Down
10 changes: 0 additions & 10 deletions Generals/Code/GameEngine/Source/GameNetwork/GameSpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,6 @@ 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;
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,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 @@ -999,8 +997,9 @@ 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);
GameWindow *buttonFirewallRefresh = TheWindowManager->winGetWindowFromId(nullptr, NAMEKEY("OptionsMenu.wnd:ButtonFirewallRefresh"));
if (buttonFirewallRefresh)
buttonFirewallRefresh->winHide(TRUE);
Comment thread
githubawn marked this conversation as resolved.
checkDrawAnchorID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:CheckBoxDrawAnchor" );
checkDrawAnchor = TheWindowManager->winGetWindowFromId( nullptr, checkDrawAnchorID);
checkMoveAnchorID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:CheckBoxMoveAnchor" );
Expand Down Expand Up @@ -1732,18 +1731,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 @@ -1369,7 +1369,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;
hostSlot->setNATBehavior(natBehavior);
hostSlot->setPingString(TheGameSpyInfo->getPingString());
game->setMap(customPref.getPreferredMap());

Expand Down Expand Up @@ -1437,7 +1438,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 @@ -1756,8 +1756,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 @@ -506,11 +506,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 @@ -609,8 +604,6 @@ void WOLWelcomeMenuUpdate( WindowLayout * layout, void *userData)
{
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.
Expand Down
Loading