Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gamenetwork): say so when the system binds another address

Olcay Seygand749500c8652
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 022c15042..3dc5b8d7c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1476,6 +1476,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- The second copy used to come up with a socket error and an empty game list, because the lobby's one network port was already taken by the first. Each copy now takes an address of its own on the machine's own loopback range and they announce themselves to each other across it.
- The second copy also used to be thrown out on the way in. It arrived carrying the same player name, which a host refuses, and the same serial number, which a host refuses harder - a rule written against two people sharing one bought copy, and two windows on one desk are not that. Both copies get their own name now, and the serial rule is waived only between two addresses on the same machine. Anything that could be a second computer still answers to it.
- `lan-play.ps1` starts as many copies as you ask for, gives each its own name, address and log, opens each on the LAN screen instead of the main menu, and lays the windows out side by side so they are not stacked on top of one another.
+- A VPN's split tunnel or a firewall can quietly move the game's connection to another network card than the LAN IP picked in Options. The LAN screen then looked open and was dead: you saw yourself listed twice, nobody else, and nobody on your virtual LAN could see you. The LAN screen now refuses to open in that state and says which address you picked and which one Windows used instead, so you know to turn the split tunnel off for the game.
## Whose side is that
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index af54f25c5..39d50d789 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -3614,3 +3614,9 @@ END
CONTROLBAR:Infa_ToolTipChinaScienceRedGuardTraining
"All Mini-Gunners will be built three ranks above Veteran"
END
+
+// the LAN lobby's error box when the system bound the socket on another adapter; the first %ls is the
+// LAN IP chosen in Options, the second the address the system bound instead
+GUI:SocketRedirected
+"The LAN IP is %ls, but the system put the game's connection on %ls. A VPN split tunnel or a firewall redirected it, so nobody on your network can hear you. Turn split tunnelling off for the game and try again."
+END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index cc4b750f7..d96193742 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -17854,3 +17854,7 @@ END
GUI:FactionPickSideNameHint
"Bir tarafın rastgele bir ordusuyla oynamak için o tarafın adına tıklayın."
END
+
+GUI:SocketRedirected
+"LAN IP adresi %ls, ama sistem oyunun bağlantısını %ls üzerine koydu. Bir VPN'in bölünmüş tüneli (split tunnel) ya da bir güvenlik duvarı bağlantıyı yönlendirdi, bu yüzden ağınızdaki kimse sizi duyamıyor. Oyun için bölünmüş tüneli kapatıp yeniden deneyin."
+END
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h
index c2ee670b5..c36134ec8 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h
@@ -225,6 +225,7 @@ public:
virtual inline UnicodeString GetMyName( void ) { return m_name; } ///< What's my name?
virtual inline LANGameInfo* GetMyGame( void ) { return m_currentGame; } ///< What's my Game?
virtual inline UnsignedInt GetLocalIP( void ) { return m_localIP; } ///< What's my IP?
+ UnsignedInt GetRedirectedIP( void ) const { return m_transport->getRedirectedIP(); } ///< Where the system bound the lobby socket instead of GetLocalIP, 0 when it did not
virtual void fillInLANMessage( LANMessage *msg ); ///< Fill in default params
virtual void checkMOTD( void );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/Transport.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/Transport.h
index 73991bedb..104a800ee 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/Transport.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/Transport.h
@@ -63,6 +63,10 @@ public:
inline Bool allowBroadcasts(Bool val) { if (!m_udpsock) return false; return (m_udpsock->AllowBroadcasts(val))?true:false; }
+ /// The address the system bound when the last init() was refused because it was not the one asked
+ /// for (a VPN split tunnel or a firewall redirecting the socket), 0 otherwise
+ UnsignedInt getRedirectedIP( void ) const { return m_redirectedIP; }
+
#if !defined(_WIN32)
/* Port defect 29 (udp.h): shareAddress(TRUE) before init lets this socket share its port with another
copy's broadcast listener; initBroadcastListener binds the wildcard address to take only the
@@ -96,6 +100,7 @@ public:
private:
Bool m_winsockInit;
UDP *m_udpsock;
+ UnsignedInt m_redirectedIP;
#if !defined(_WIN32)
Bool m_shareAddress;
Bool m_broadcastsOnly;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanLobbyMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanLobbyMenu.cpp
index 862c0ac33..161de1e07 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanLobbyMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanLobbyMenu.cpp
@@ -619,7 +619,19 @@ void LanLobbyMenuUpdate( WindowLayout * layout, void *userData)
if (LANSocketErrorDetected == TRUE) {
LANSocketErrorDetected = FALSE;
DEBUG_LOG(("SOCKET ERROR! BAILING!\n"));
- MessageBoxOk(TheGameText->fetch("GUI:NetworkError"), TheGameText->fetch("GUI:SocketError"), NULL);
+ // The socket opened, but the system put it on another adapter than the LAN IP chosen (issue 146).
+ const UnsignedInt redirectedIP = TheLAN->GetRedirectedIP();
+ if (redirectedIP)
+ {
+ const UnsignedInt askedIP = TheLAN->GetLocalIP();
+ UnicodeString asked, bound, text;
+ asked.format(u"%d.%d.%d.%d", askedIP >> 24, (askedIP >> 16) & 0xff, (askedIP >> 8) & 0xff, askedIP & 0xff);
+ bound.format(u"%d.%d.%d.%d", redirectedIP >> 24, (redirectedIP >> 16) & 0xff, (redirectedIP >> 8) & 0xff, redirectedIP & 0xff);
+ text.format(TheGameText->fetch("GUI:SocketRedirected").str(), asked.str(), bound.str());
+ MessageBoxOk(TheGameText->fetch("GUI:NetworkError"), text, NULL);
+ }
+ else
+ MessageBoxOk(TheGameText->fetch("GUI:NetworkError"), TheGameText->fetch("GUI:SocketError"), NULL);
// we have a socket problem, back out to the main menu.
TheWindowManager->winSendSystemMsg(buttonBack->winGetParent(), GBM_SELECTED,
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp
index 159c26762..57af62b29 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp
@@ -80,6 +80,7 @@ Transport::Transport(void)
{
m_winsockInit = false;
m_udpsock = NULL;
+ m_redirectedIP = 0;
// EA never initialized these two. It did not bite because everything that read them was
// compiled out of the shipping build; now that the simulator is built in every configuration,
// a Transport that is used before init() would have run on whatever was on the heap.
@@ -125,6 +126,7 @@ Bool Transport::init( UnsignedInt ip, UnsignedShort port )
#endif
// ------- Bind our port --------
+ m_redirectedIP = 0;
if (m_udpsock)
delete m_udpsock;
m_udpsock = NEW UDP();
@@ -153,6 +155,24 @@ Bool Transport::init( UnsignedInt ip, UnsignedShort port )
return false;
}
+ /* A VPN's split tunnel (a WFP bind redirect) or a firewall can move the socket to another adapter
+ after bind() succeeds. Everything then leaves from an address the lobby does not know as its own:
+ the player hears his own announcements as a stranger's and nobody on the chosen network hears him.
+ Refuse the socket and say which address the system bound. A wildcard bind has nothing to compare. */
+ UnsignedInt boundIP;
+ UnsignedShort boundPort;
+ m_udpsock->getLocalAddr(boundIP, boundPort);
+ if (ip != INADDR_ANY && boundIP != ip)
+ {
+ DEBUG_LOG(("Transport::init - asked for %d.%d.%d.%d:%d, the system bound %d.%d.%d.%d:%d (a VPN split tunnel or a firewall redirected the socket)\n",
+ ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, port,
+ boundIP >> 24, (boundIP >> 16) & 0xff, (boundIP >> 8) & 0xff, boundIP & 0xff, boundPort));
+ m_redirectedIP = boundIP;
+ delete m_udpsock;
+ m_udpsock = NULL;
+ return false;
+ }
+
// ------- Clear buffers --------
// i is used after the loop; VC6 for-scope let it escape.
int i;