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.

merge: turkiye units, side-styled huds, sdl water, lobby service client

Olcay Seygan7187faa32a98
diff --cc CHANGELOG.md
index 8acb2dc12,007e4a83d..ae07c343b
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -29,15 -59,12 +59,17 @@@ found and fixed, EA's own, not port dam
- You pick for your own seat and the host picks for the computer seats, the way colour and team already work. The pick is in the replay and the saved game, and a room that leaves the column at 100% plays and replays as it did.
- Promotions and armour research still come on top, at the seat's share: an Elite Paladin with Composite Armor reads 364 at 50% against 728 at 100%. A vehicle stolen from a handicapped player moves to its new owner's column and keeps its share of health, so a Humvee at 80 of 120 becomes 160 of 240 with no damage dealt and no repair given.
+## Long routes in big computer matches
+
+- A unit looking for a long way across a crowded map no longer stops mid-search and gives up. A search that runs out of its share of a step waits for the next one and carries on, and the limit on how much ground one search can cover is doubled. In eight Hard computer players on Twilight Flame, six matches a side, the pathfinding cost 34.9 seconds a match where it cost 42.8, with 28% fewer cells searched, and fewer units sat wedged. The worst frames of those matches did not get measurably shorter. Replays recorded before this change play out differently.
+- Before a long search the pathfinder sketches a rough corridor over the map in blocks of ten cells, and two kinds of sketch were pure waste. One was drawn for a unit whose destination turned out to be taken, which then had to look for the nearest free spot instead. The other was a worker a step from his own building site: the half-built walls split the blocks the sketch walks while the ground he walks stays open, so it covered the whole map, 4 to 7 ms of a single frame, and found nothing. Now the sketch is drawn only for a search that will run, and it gives up past 5,000 cells, a size no sketch that found its corridor reached in three long matches. Every unit is handed the route it was handed before. Eight Hard computer players on Twilight Flame, one match at a time on three seeds: frames where the pathfinder's own queue took over 5 ms went from 13 to none, and over 3 ms from 337 to 139, fewer on every seed. The pathfinder's total time stayed where it was, and the few frames over 33 ms are the opening's scripts, the same frames in every build. Which frame works a route out has moved, so replays recorded before this change play out differently.
+
- ## Computer players earn double
+ ## Computer players earn half as much again, and more when they fall behind
- - A computer player in a skirmish or a network match now earns double, on every difficulty. A truckload worth 75 banks 150, and the 1000 for capturing an oil derrick is 2000. It counts everything the computer makes by playing: supply docks, oil derricks and other tech buildings, black markets, drop zones, hackers, bounties, crates, salvage and stolen cash. On one generated map, two Easy computers earned 25,800 and 28,200 in six minutes and forty seconds and now earn 51,600 and 56,400. Two Hard ones on the same seed went from 22,800 and 24,825 to 74,800 and 81,090, because Hard spends the extra money on more income: one of them built four supply centers and two drop zones where it used to build two and one.
- - Money it gets back stays what it was. Selling a building or cancelling a queue returns the same sum as yours does, or a computer could queue and cancel its way to a fortune, and cash from a map's script or from an ally is not doubled either. The money figure floating over a computer's truck or building shows what it really banked.
+ - A computer player in a skirmish or a network match earns half as much again as you would, on every difficulty, where it used to earn double. A truckload worth 75 banks 112, and the 1000 for capturing an oil derrick is 1500. It counts everything the computer makes by playing: supply docks, oil derricks and other tech buildings, black markets, drop zones, hackers, bounties, crates, salvage and stolen cash.
+ - A computer that falls behind earns more. Every thirty seconds it weighs its team against the strongest enemy team still in the match, each team's armies, bases and banks at their prices, divided by its living players, so a team of three does not look rich next to a lone enemy just for having three bases. Its human allies count toward its team, and in a free-for-all every enemy is a team of one. Level or ahead, it stays at half again. Behind, it gains up to 25 points of income at each weighing, toward double at three quarters of the enemy team's worth and triple at a quarter and below, so a computer that is being crushed reaches triple in three minutes. It gives the points back the same way as it catches up.
+ - The score screen and its charts show what the computer would have earned without the bonus, so its money earned reads against yours on the same terms.
+ - Money it gets back stays what it was. Selling a building or cancelling a queue returns the same sum as yours does, or a computer could queue and cancel its way to a fortune, and cash from a map's script or from an ally gets no bonus either. The money figure floating over a computer's truck or building shows what it really banked.
- Your own income does not change, and your cut of a computer ally's income under Share Income is the plain cut. Campaign missions and Generals' Challenge opponents earn what they always did.
- Replays recorded before this change play out differently.
- It also goes for that money from the start. A computer used to buy the capture research only once a soldier stood idle at home, and by then its opening had often spent the bank. Now the first barracks trains the soldier and starts the research within five seconds of standing, and he walks to the nearest oil derrick while it runs. The same four-player match on Twilight Flame: Hard's first derrick fell at 2 minutes 20 seconds where it had taken 4 minutes 40, Medium's at 2 minutes 35 against 3 minutes 10, Easy's at 2 minutes 50 against 4 minutes 11. Script teams also stopped recruiting that soldier off a half-captured derrick. During the first six minutes a computer that can expand looks for a new supply dock every 15 seconds instead of every minute and will spend its last dollar on the building, where it used to want twice the price in the bank. Replays recorded before this change play out differently.
diff --cc GeneralsMD/Code/BuildFingerprint.manifest
index fafa726e9,9cfcc2b8e..3b884e9e1
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@@ -3095,8 -3304,9 +3311,10 @@@ Libraries/Source/gamespy-strlwr-c-only.
Libraries/Source/glslang/.gitignore
Libraries/Source/lzhl-clear-history.patch
Libraries/Source/max4sdk/.gitignore
+Libraries/Source/mbedtls/.gitignore
Libraries/Source/miniaudio/.gitignore
+ Libraries/Source/online/.gitignore
+ Libraries/Source/online/vcpkg.json
Libraries/Source/profile/_pch.cpp
Libraries/Source/profile/_pch.h
Libraries/Source/profile/compile_doxygen.bat
@@@ -4250,10 -4473,9 +4482,12 @@@ Tools/package-common.s
Tools/packaging-resolution-check.sh
Tools/peacetime_layout.py
Tools/pink_laser.py
+ Tools/radar_marks.py
+ Tools/recon_marks.py
Tools/record-dx11-shaders.ps1
+Tools/relay/README.md
+Tools/relay/relay.js
+Tools/relay/test.js
Tools/replay-check.sh
Tools/root-readonly-check.sh
Tools/signal_marks.py
diff --cc GeneralsMD/Code/Data/Patch.str
index 1e8285101,fd442c302..1c12b1699
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@@ -3235,26 -3693,99 +3693,123 @@@ GUI:SocketRedirecte
"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
+// the online service's one chat room; the lobby's room box shows GUI:<room name>
+GUI:Lobby
+"Lobby"
+END
+
+// EA's oldFactionsOnly box, read by players as a unit cap and mixed up with Unit Limit
+GUI:LimitArmies
+"Original Armies Only"
+END
+
+TOOLTIP:LimitArmies
+"Only the original USA, China and GLA armies can be picked, no generals' armies"
+END
+
+// a seat's colour left to chance; EA's label for it was "???"
+GUI:???
+"Random"
+END
+
+// the online login screen's one account field: the service takes the email or the nick
+GUI:OnlineLoginName
+"Email or Nickname"
+END
++
+ // A vehicle transport's Evacuate asks for a spot, the transport goes there and empties; Alt empties it where it stands
+ CONTROLBAR:ToolTipEvacuateAt
+ "Go to the chosen spot and order all units to exit\nAlt: unload here"
+ END
+
+ GUI:OptionsTabWater
+ "Water"
+ END
+
+ GUI:OptionsGroupReflections
+ "Reflections"
+ END
+
+ GUI:OptionsGroupModernWater
+ "Modern water"
+ END
+
+ GUI:WaterReflectionEnabled
+ "Scene reflections"
+ END
+
+ TOOLTIP:WaterReflectionEnabled
+ "Reflects the scene in Modern water. Turn off to improve performance while keeping sky colour and sun highlights. Your reflection mode is remembered. Applied when you Accept."
+ END
+
+ GUI:WaterFftResolution
+ "Wave detail"
+ END
+
+ GUI:WaterFftResolution0
+ "Low"
+ END
+
+ GUI:WaterFftResolution1
+ "High"
+ END
+
+ TOOLTIP:WaterFftResolution
+ "Controls fine detail in Modern water waves. Low improves performance; High shows more detail. Applied when you Accept."
+ END
+
+ GUI:WaterRefractionQuality
+ "Refraction"
+ END
+
+ GUI:WaterRefractionQuality0
+ "Full"
+ END
+
+ GUI:WaterRefractionQuality1
+ "Simple"
+ END
+
+ GUI:WaterRefractionQuality2
+ "Off"
+ END
+
+ TOOLTIP:WaterRefractionQuality
+ "For Modern water. Full distorts the view below the surface. Simple keeps clear water without distortion. Off uses opaque tinted water for better performance. Applied when you Accept."
+ END
+
+ GUI:WaterReflectionDetail
+ "Reflection detail"
+ END
+
+ GUI:WaterReflectionDetail0
+ "Low"
+ END
+
+ GUI:WaterReflectionDetail1
+ "High"
+ END
+
+ TOOLTIP:WaterReflectionDetail
+ "Controls scene reflection detail in Modern water. Low improves performance. High gives clearer reflections. SSR resolution is unchanged. Applied when you Accept."
+ END
+
+ GUI:WaterReflection
+ "Reflection mode"
+ END
+
+ GUI:WaterReflection0
+ "Legacy"
+ END
+
+ GUI:WaterReflection1
+ "SSR"
+ END
+
+ GUI:WaterReflection2
+ "Hybrid"
+ END
+
+ TOOLTIP:WaterReflection
+ "For Modern water when Scene reflections is on. Legacy uses the original reflections. SSR reflects visible screen content. Hybrid combines both and is the default. Applied when you Accept."
+ END
diff --cc GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 04e735698,1b5c26770..dab7f63cd
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@@ -140,7 -142,7 +142,8 @@@
#include "GameNetwork/LANAPICallbacks.h"
#include "GameNetwork/NetworkUtil.h"
#include "GameNetwork/GameSpy/GameResultsThread.h"
+#include "GameNetwork/Online/OnlineQueues.h"
+ #include "GameNetwork/GeneralsOnline/OnlineBridge.h"
#include "Common/version.h"
diff --cc GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
index 5a68e6db4,ae974d8de..35adc956d
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
@@@ -37,9 -37,10 +37,11 @@@
#include "Common/Money.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
+ #include "Common/NameKeyGenerator.h"
#include "GameClient/Display.h"
+ #include "GameClient/GadgetListBox.h"
#include "GameClient/GameWindowManager.h"
+#include "GameClient/GUICallbacks.h" // ToggleQuitMenu, for quitmenu
#include "GameClient/InGameUI.h"
#include "GameClient/KeyDefs.h"
#include "GameClient/Shell.h"
diff --cc GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp
index 75ac2090d,308b108ae..b273345c9
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLWelcomeMenu.cpp
@@@ -69,7 -69,7 +69,8 @@@
#include "GameNetwork/GameSpy/BuddyThread.h"
#include "GameNetwork/GameSpy/ThreadUtils.h"
#include "GameNetwork/GameSpy/MainMenuUtils.h"
+#include "GameNetwork/Online/OnlineQueues.h"
+ #include "GameNetwork/GeneralsOnline/OnlineBridge.h"
#include "GameNetwork/WOLBrowser/WebBrowser.h"
#ifdef _INTERNAL
@@@ -514,9 -514,21 +515,23 @@@ void WOLWelcomeMenuInit( WindowLayout *
buttonLadderID = TheNameKeyGenerator->nameToKey( AsciiString( "WOLWelcomeMenu.wnd:ButtonLadder" ) );
buttonLadder = TheWindowManager->winGetWindowFromId( parentWOLWelcome, buttonLadderID );
+ Bool serviceOnline = FALSE;
+ #ifdef ZH_ONLINE
+ serviceOnline = OnlineBridge_IsConfigured();
+ #endif
+ if (serviceOnline)
+ {
+ // lobbies and custom games only, and the service's connections need no firewall detection
+ if (buttonQuickMatch)
+ buttonQuickMatch->winHide(TRUE);
+ if (buttonLadder)
+ buttonLadder->winHide(TRUE);
+ if (buttonBuddies)
+ buttonBuddies->winHide(TRUE);
+ }
- else
+ // -online: every packet goes through our relay, so EA's firewall probe (against its dead mangler
+ // servers) has nothing to find
- if (!OnlineIsEnabled())
++ else if (!OnlineIsEnabled())
{
if (TheFirewallHelper == NULL) {
TheFirewallHelper = createFirewallHelper();
diff --cc GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index 8b8fb1db1,a333b6041..5532adbfb
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@@ -171,12 -171,20 +171,25 @@@ static Int thePFWedgeWorst = 0; ///<
static Int thePFEscapes = 0; ///< backing-out manoeuvres started
static Int thePFCrowdRepaths = 0; ///< routes given up on because nothing on them could get past
static Int thePFDithers = 0; ///< units caught driving a long way and gaining nothing
+/* The queue's budget is a count of cells, and the claim it makes is about the frame: these count the
+ logic frames whose queue, the zone pass left out, ran past 3 and past 5 ms. The match's queue total
+ hides the frames that blow the budget among the many that do not. */
+static Int thePFQueueOver3 = 0;
+static Int thePFQueueOver5 = 0;
+ /* How long a request stood in the path queue before it was answered. The frame it went in is kept
+ beside its slot for this count alone and nothing reads it back into a decision, so it is not
+ saved and not in the CRC. */
+ static UnsignedInt theQueuedFrame[ PATHFIND_QUEUE_LEN ];
+ static Int thePFQServed = 0; ///< requests taken off the queue
+ static Int64 thePFQWaitSum = 0; ///< frames they waited, summed
+ static Int thePFQWaitMax = 0; ///< the longest one waited
+ static Int thePFQLate = 0; ///< answered more than a second after asking
+ static Int thePFQPeak = 0; ///< the deepest the queue got
+ static Int thePFQFull = 0; ///< refused because the queue was full
+ static Int thePFQCapFrames = 0; ///< frames the request cap stopped with requests left
+ static Int thePFQCellFrames = 0; ///< frames the cell budget stopped with requests left
+
inline void pfBump( Int slot ) { thePFCalls[ slot ]++; }
class PathProfile
@@@ -5286,8 -5281,14 +5299,16 @@@ void Pathfinder::resetMatchProfile( voi
thePFEscapes = 0;
thePFCrowdRepaths = 0;
thePFDithers = 0;
+ thePFQueueOver3 = 0;
+ thePFQueueOver5 = 0;
+ thePFQServed = 0;
+ thePFQWaitSum = 0;
+ thePFQWaitMax = 0;
+ thePFQLate = 0;
+ thePFQPeak = 0;
+ thePFQFull = 0;
+ thePFQCapFrames = 0;
+ thePFQCellFrames = 0;
}
void Pathfinder::bumpNoPath( void )
@@@ -5349,12 -5350,17 +5370,18 @@@ const char *Pathfinder::getMatchProfile
strcpy( thePFMatchReport + len, one );
len += oneLen;
}
- if( len < (Int)sizeof( thePFMatchReport ) - 128 )
+ if( len < (Int)sizeof( thePFMatchReport ) - 192 )
sprintf( thePFMatchReport + len,
- "| nopath %d outofcells %d blocked %d stuck %d wedge %d worst %d escape %d repath %d dither %d",
+ "| nopath %d outofcells %d blocked %d stuck %d wedge %d worst %d escape %d repath %d dither %d queueover3ms %d queueover5ms %d",
thePFNoPath, thePFOutOfCells, thePFBlockedFrames, thePFStuckFrames,
- thePFWedgeFrames, thePFWedgeWorst, thePFEscapes, thePFCrowdRepaths, thePFDithers );
+ thePFWedgeFrames, thePFWedgeWorst, thePFEscapes, thePFCrowdRepaths, thePFDithers,
+ thePFQueueOver3, thePFQueueOver5 );
+ len = strlen( thePFMatchReport );
+ if( len < (Int)sizeof( thePFMatchReport ) - 160 )
+ sprintf( thePFMatchReport + len,
+ " | queued %d wait %.1f longest %d late %d peak %d full %d capped %d cellcapped %d",
+ thePFQServed, thePFQServed ? (double)thePFQWaitSum / thePFQServed : 0.0, thePFQWaitMax,
+ thePFQLate, thePFQPeak, thePFQFull, thePFQCapFrames, thePFQCellFrames );
return thePFMatchReport;
}
@@@ -7845,18 -7793,41 +7877,37 @@@ void Pathfinder::processPathfindQueue(v
/* Kept at three per frame at 60 logic frames a second rather than halved: one and a half is not a
count, two was measured worse, and the cap is there to clip a burst within a frame, which a
frame half as long needs no less. */
- enum { PATHFIND_REQUESTS_PER_FRAME = 3 };
+ /* "Many times the demand" stops being true twenty minutes into a 4v4 between Hard computers: a
+ match then asks for close to three paths a frame, the cap holds 60% of all frames, the queue
+ stands 300 to 600 deep, and a unit given an order waits up to 239 frames (4 s) for its path.
+ So past 180 waiting, a second of draining at three, the cap rises by one for every 60 more,
+ to six at most, and the cell budget still bounds the frame. Iron Dragon, four seeds of 90000
+ frames on Hard: longest wait 239, 104, 164, 109 frames to 109, 88, 102, 97, blocked unit-frames
+ per 1000 frames 3,696 to 3,355, wedged 933 to 925, p99.9 35.9 to 36.6 ms with four matches on
+ the box (a one-frame control moved it to 34.6). Medium likewise, Easy never gets that deep.
+ Up to twelve a frame cut the wait further and drove worse (blocked 3,814 to 5,402). The
+ 841-unit order is held by the cell budget, not by this, and leaves as it did. */
+ enum { PATHFIND_REQUESTS_PER_FRAME = 3, PATHFIND_DEEP_QUEUE = 180, PATHFIND_DEEP_STEP = 60,
+ PATHFIND_REQUESTS_PER_FRAME_DEEP = 6 };
+ Int requestCap = PATHFIND_REQUESTS_PER_FRAME;
+ const Int depth = (m_queuePRTail - m_queuePRHead + PATHFIND_QUEUE_LEN) % PATHFIND_QUEUE_LEN;
+ if (depth > PATHFIND_DEEP_QUEUE)
+ requestCap += (depth - PATHFIND_DEEP_QUEUE) / PATHFIND_DEEP_STEP;
+ if (requestCap > PATHFIND_REQUESTS_PER_FRAME_DEEP)
+ requestCap = PATHFIND_REQUESTS_PER_FRAME_DEEP;
Int requestsThisFrame = 0;
+ const UnsignedInt now = TheGameLogic->getFrame();
while (m_cumulativeCellsAllocated < PATHFIND_CELLS_PER_FRAME &&
- requestsThisFrame < PATHFIND_REQUESTS_PER_FRAME &&
+ requestsThisFrame < requestCap &&
m_queuePRTail!=m_queuePRHead) {
++requestsThisFrame;
+ const ObjectID id = m_queuedPathfindRequests[m_queuePRHead];
+ const Int waited = (Int)(now - theQueuedFrame[m_queuePRHead]);
- thePFQServed++;
- thePFQWaitSum += waited;
- if (waited > thePFQWaitMax)
- thePFQWaitMax = waited;
- if (waited > LOGICFRAMES_PER_SECOND)
- thePFQLate++;
- Object *obj = TheGameLogic->findObjectByID(m_queuedPathfindRequests[m_queuePRHead]);
- m_isQueuedForPath[m_queuedPathfindRequests[m_queuePRHead]] = false;
+ Object *obj = TheGameLogic->findObjectByID(id);
+ m_isQueuedForPath[id] = false;
m_queuedPathfindRequests[m_queuePRHead] = INVALID_ID;
+ m_search.claimed = FALSE;
if (obj) {
AIUpdateInterface *ai = obj->getAIUpdateInterface();
if (ai) {
@@@ -7868,17 -7837,6 +7919,24 @@@
#endif
}
}
+ // a stopped search its unit did not come back for: gone, or asking something else now
+ if (m_search.owner != INVALID_ID && !m_search.claimed) {
+ dropSuspendedSearch();
+ }
+ if (m_search.owner != INVALID_ID) {
+ // the frame's cells ran out inside this unit's search: it keeps the head of the queue and
+ // carries on from the same cell next frame, so nobody behind it is answered first
+ m_queuedPathfindRequests[m_queuePRHead] = id;
+ m_isQueuedForPath[id] = true;
+ break;
+ }
++ // counted as it leaves the queue: a search carried over frames is one request, waiting until it ends
++ thePFQServed++;
++ thePFQWaitSum += waited;
++ if (waited > thePFQWaitMax)
++ thePFQWaitMax = waited;
++ if (waited > LOGICFRAMES_PER_SECOND)
++ thePFQLate++;
m_queuePRHead = m_queuePRHead+1;
if (m_queuePRHead >= PATHFIND_QUEUE_LEN) {
m_queuePRHead = 0;
diff --cc GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/MainMenuUtils.cpp
index f9b8478c0,a6f382bea..8a265a52e
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/MainMenuUtils.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/MainMenuUtils.cpp
@@@ -61,8 -61,7 +61,9 @@@
#include "GameNetwork/GameSpy/MainMenuUtils.h"
#include "GameNetwork/GameSpy/PeerDefs.h"
#include "GameNetwork/GameSpy/PeerThread.h"
+#include "GameNetwork/Online/OnlineQueues.h"
+#include "Lib/Clock.h"
+ #include "GameNetwork/GeneralsOnline/OnlineBridge.h"
#include "WWDownload/Registry.h"
#include "WWDownload/urlBuilder.h"
diff --cc GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp
index a3101283b,ffbd12d53..73b24c654
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp
@@@ -604,31 -603,9 +604,32 @@@ void GameSpyStagingRoom::startGame(Int
}
}
+ /* -online: every machine is a relay vip already (the login's relay.ok gave ours, the server's player
+ records gave the others'), so there is no path to negotiate. Every copy uses the game's own
+ logical port, the one launchGame binds without a NAT. */
+ if (OnlineIsEnabled())
+ {
+ for (Int i=0; i<MAX_SLOTS; ++i)
+ {
+ if (m_GameSpySlot[i].isHuman())
+ {
+ m_GameSpySlot[i].setPort(8888);
+ const UnsignedInt ip = m_GameSpySlot[i].getIP();
+ DEBUG_LOG(("ONLINE LAUNCH slot=%d vip=%d.%d.%d.%d\n", i, ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff));
+ }
+ }
+ // what every seat starts under, for online_check.py to set the host's line beside the guest's
+ DEBUG_LOG(("ONLINE OPTIONS prorules=%d turbo=%d unitlimit=%d stats=%d map=%s\n", (Int)getProRules(), (Int)getTurbo(),
+ (Int)getUnitLimit(), (Int)getUseStats(), getMap().str()));
+ launchGame();
+ if (TheGameSpyInfo)
+ TheGameSpyInfo->leaveStagingRoom();
+ return;
+ }
+
//#if defined(_DEBUG) || defined(_INTERNAL)
- if (numHumans < 2)
+ // with a route there is no firewall to negotiate: the connections already stand
+ if (numHumans < 2 || TheTransportRoute != NULL)
{
launchGame();
if (TheGameSpyInfo)
diff --cc GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp
index f392d1cb0,a43529c9c..a40448d87
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Transport.cpp
@@@ -79,340 -74,10 +79,342 @@@ static inline void decryptBuf( unsigne
}
}
+//--------------------------------------------------------------------------
+/* -relay host:port. Two homes behind NAT cannot reach each other, so in relay mode no Transport owns a
+ socket: the process has one, bound to an ephemeral port, and everything goes through the relay in
+ a small envelope (big-endian, every packet opens 'Z','R',type):
+ HELLO 1 us -> relay: exeCRC u32, iniCRC u32, session 8 bytes (0 the first time), wantVip u32 (0 = any),
+ name UTF-8 <= 32 bytes
+ WELCOME 2 relay -> us: session 8 bytes, vip u32 - our virtual 10.x.y.z address
+ DATA 3 us -> relay: session 8 bytes, dstVip u32, dstPort u16, srcPort u16, payload
+ DATA 3 relay -> us: srcVip u32, srcPort u16, dstPort u16, payload
+ The relay puts a machine in the room of its (exeCRC, iniCRC) and forgets a session idle for 120 s,
+ and a HELLO with our session goes out every 10 s whenever a Transport is pumped (the multiplayer load
+ screen pumps it too). The relay forwards nothing to us until a packet carrying the session it sent
+ comes back, so a second HELLO answers the first WELCOME at once. Every WELCOME carries the session
+ to use from then on: the relay hands out a new one when NAT moves our port. wantVip is the address
+ the first init() was handed when it is in 10.0.0.0/8, so a -netgame slot list of 10.x addresses gets
+ each copy the slot it names, and after the first WELCOME it is the vip we have, so a relay that
+ restarted or forgot us gives it back. The lobby asks for nothing at first, because LANAPI::init runs
+ with no address before SetLocalIP picks one. The ports are the logical ones (the lobby's 8086,
+ the game's 8088): a received DATA is handed to whichever Transport holds dstPort, with the sender's
+ vip and port as its address, so LANAPI and ConnectionManager see a LAN where every machine is a
+ vip and a broadcast is dstVip 255.255.255.255. Nothing here touches the game logic.
+
+ -online uses the same socket with HELLO_AUTH (type 4) in place of HELLO: the header above, then the
+ 16-byte ticket the service handed out at login, then the name (left empty: the service knows the
+ account). openOnlineRelay() makes the handshake right after login, against OnlineGetRelayEndpoint,
+ so the vip exists before any Transport does; keepOnlineRelay() sends the keepalive while the lobby
+ has no Transport to pump. */
+namespace
+{
+ enum { RELAY_HELLO = 1, RELAY_WELCOME = 2, RELAY_DATA = 3, RELAY_HELLO_AUTH = 4 };
+ const Int RELAY_MAX_PACKET = 1400;
+ const Int RELAY_SESSION_BYTES = 8;
+ const Int RELAY_TICKET_BYTES = 16;
+ const Int RELAY_HELLO_HEADER = 23; ///< 'ZR', type, exeCRC, iniCRC, session, wantVip
+ const Int RELAY_WELCOME_SIZE = 15; ///< 'ZR', type, session, vip
+ const Int RELAY_DATA_OUT_HEADER = 19; ///< 'ZR', type, session, dstVip, dstPort, srcPort
+ const Int RELAY_DATA_IN_HEADER = 11; ///< 'ZR', type, srcVip, srcPort, dstPort
+ const Int RELAY_NAME_BYTES = 32;
+ const UnsignedInt RELAY_KEEPALIVE_MS = 10000;
+ const Int RELAY_HELLO_TRIES = 10; ///< one HELLO every 500 ms: five seconds, then a socket error
+ const UnsignedInt RELAY_RETRY_AFTER_MS = 10000; ///< a failed handshake is not tried again for this long
+ const Int RELAY_MAX_TRANSPORTS = 4;
+
+ struct RelayLink
+ {
+ UDP *sock;
+ UnsignedInt ip;
+ UnsignedShort port;
+ unsigned char session[RELAY_SESSION_BYTES]; ///< opaque, as the relay sent it; zero before the first WELCOME
+ UnsignedInt wantVip;
+ UnsignedInt vip;
+ UnsignedInt lastHello;
+ UnsignedInt failedAt;
+ Bool wsaStarted;
+ Bool authed; ///< -online: every hello is a HELLO_AUTH carrying ticket
+ unsigned char ticket[RELAY_TICKET_BYTES];
+ Int nameLength;
+ unsigned char name[RELAY_NAME_BYTES];
+ Transport *users[RELAY_MAX_TRANSPORTS];
+ };
+ RelayLink s_relay; // zero
+
+ void put32( unsigned char *p, UnsignedInt v ) { p[0] = (unsigned char)(v >> 24); p[1] = (unsigned char)(v >> 16); p[2] = (unsigned char)(v >> 8); p[3] = (unsigned char)v; }
+ void put16( unsigned char *p, UnsignedShort v ) { p[0] = (unsigned char)(v >> 8); p[1] = (unsigned char)v; }
+ UnsignedInt get32( const unsigned char *p ) { return ((UnsignedInt)p[0] << 24) | ((UnsignedInt)p[1] << 16) | ((UnsignedInt)p[2] << 8) | p[3]; }
+ UnsignedShort get16( const unsigned char *p ) { return (UnsignedShort)((p[0] << 8) | p[1]); }
+
+ /// The lobby name, UTF-8, cut at a whole character before RELAY_NAME_BYTES; the relay only shows it
+ void relayTakeName( void )
+ {
+ UnicodeString name;
+ if (TheGlobalData->m_lanPlayerName.isNotEmpty())
+ name.translate( TheGlobalData->m_lanPlayerName );
+ else
+ name = LANPreferences().getUserName();
+ Int n = 0;
+ for (Int i = 0; i < name.getLength(); ++i)
+ {
+ const UnsignedInt c = (UnsignedInt)name.getCharAt(i);
+ const Int size = c < 0x80 ? 1 : (c < 0x800 ? 2 : 3);
+ if (n + size > RELAY_NAME_BYTES)
+ break;
+ if (size == 1)
+ s_relay.name[n] = (unsigned char)c;
+ else if (size == 2)
+ {
+ s_relay.name[n] = (unsigned char)(0xC0 | (c >> 6));
+ s_relay.name[n + 1] = (unsigned char)(0x80 | (c & 0x3F));
+ }
+ else
+ {
+ s_relay.name[n] = (unsigned char)(0xE0 | (c >> 12));
+ s_relay.name[n + 1] = (unsigned char)(0x80 | ((c >> 6) & 0x3F));
+ s_relay.name[n + 2] = (unsigned char)(0x80 | (c & 0x3F));
+ }
+ n += size;
+ }
+ s_relay.nameLength = n;
+ }
+
+ void relaySendHello( void )
+ {
+ unsigned char buf[RELAY_HELLO_HEADER + RELAY_TICKET_BYTES + RELAY_NAME_BYTES];
+ buf[0] = 'Z'; buf[1] = 'R'; buf[2] = s_relay.authed ? RELAY_HELLO_AUTH : RELAY_HELLO;
+ put32( buf + 3, TheGlobalData->m_exeCRC );
+ put32( buf + 7, TheGlobalData->m_iniCRC );
+ memcpy( buf + 11, s_relay.session, RELAY_SESSION_BYTES );
+ put32( buf + 19, s_relay.wantVip );
+ Int len = RELAY_HELLO_HEADER;
+ if (s_relay.authed)
+ {
+ memcpy( buf + len, s_relay.ticket, RELAY_TICKET_BYTES );
+ len += RELAY_TICKET_BYTES;
+ }
+ memcpy( buf + len, s_relay.name, s_relay.nameLength );
+ len += s_relay.nameLength;
+ s_relay.sock->Write( buf, len, s_relay.ip, s_relay.port );
+ s_relay.lastHello = Clock_Milliseconds();
+ }
+}
+
+UnsignedInt Transport::getRelayIP( void )
+{
+ return s_relay.vip;
+}
+
+/// Reads everything the relay socket holds: WELCOMEs set the session, DATA goes to the Transport on its dstPort
+void Transport::pumpRelay( void )
+{
+ if (!s_relay.sock)
+ return;
+ const UnsignedInt now = Clock_Milliseconds();
+ if (s_relay.vip && now - s_relay.lastHello >= RELAY_KEEPALIVE_MS)
+ relaySendHello();
+
+ unsigned char buf[RELAY_MAX_PACKET];
+ sockaddr_in from;
+ Int len;
+ while ((len = s_relay.sock->Read( buf, sizeof(buf), &from )) > 0)
+ {
+ if (ntohl(from.sin_addr.s_addr) != s_relay.ip || ntohs(from.sin_port) != s_relay.port
+ || len < 3 || buf[0] != 'Z' || buf[1] != 'R')
+ continue;
+ if (buf[2] == RELAY_WELCOME && len >= RELAY_WELCOME_SIZE)
+ {
+ const UnsignedInt vip = get32( buf + 11 );
+ memcpy( s_relay.session, buf + 3, RELAY_SESSION_BYTES );
+ // The lobby already announced the first one; a relay that forgot us and had given it away moves us
+ DEBUG_ASSERTLOG( !s_relay.vip || vip == s_relay.vip, ("Transport: the relay moved us from %d.%d.%d.%d to %d.%d.%d.%d, peers will not find us\n",
+ s_relay.vip >> 24, (s_relay.vip >> 16) & 0xff, (s_relay.vip >> 8) & 0xff, s_relay.vip & 0xff,
+ vip >> 24, (vip >> 16) & 0xff, (vip >> 8) & 0xff, vip & 0xff) );
+ if (!s_relay.vip)
+ {
+ s_relay.vip = vip;
+ s_relay.wantVip = vip; // every later HELLO asks for it back
+ }
+ }
+ else if (buf[2] == RELAY_DATA && len > RELAY_DATA_IN_HEADER && len - RELAY_DATA_IN_HEADER <= MAX_NETWORK_MESSAGE_LEN)
+ {
+ const UnsignedShort dstPort = get16( buf + 9 );
+ for (Int u = 0; u < RELAY_MAX_TRANSPORTS; ++u)
+ {
+ Transport *t = s_relay.users[u];
+ if (t && t->m_port == dstPort)
+ {
+ TransportMessage msg;
+ memcpy( &msg, buf + RELAY_DATA_IN_HEADER, len - RELAY_DATA_IN_HEADER );
+ t->receivePacket( msg, len - RELAY_DATA_IN_HEADER, get32( buf + 3 ), get16( buf + 7 ), now );
+ break;
+ }
+ }
+ }
+ }
+}
+
+/// Opens the relay socket and waits for a WELCOME (at most five seconds); s_relay.wantVip and authed are the caller's
+Bool Transport::connectRelay( const AsciiString &host, UnsignedShort relayPort )
+{
+ if (s_relay.failedAt && Clock_Milliseconds() - s_relay.failedAt < RELAY_RETRY_AFTER_MS)
+ return false;
+#if defined(_WIN32)
+ // the relay socket outlives every Transport, so it keeps winsock up by itself
+ if (!s_relay.wsaStarted)
+ {
+ WSADATA wsadata;
+ if (WSAStartup( MAKEWORD(2, 2), &wsadata ) != 0)
+ return false;
+ s_relay.wsaStarted = true;
+ }
+#endif
+ s_relay.ip = ResolveIP( host );
+ s_relay.port = relayPort;
+ if (s_relay.ip == 0 || s_relay.ip == INADDR_NONE || s_relay.port == 0)
+ {
+ DEBUG_LOG(("Transport: relay %s:%d does not resolve to an address and port\n", host.str(), relayPort));
+ s_relay.failedAt = Clock_Milliseconds();
+ return false;
+ }
+ if (!s_relay.sock)
+ {
+ s_relay.sock = NEW UDP();
+ if (s_relay.sock->Bind( (UnsignedInt)INADDR_ANY, 0 ) != 0)
+ {
+ DEBUG_LOG(("Transport: no socket for the relay (error %d)\n", lastSocketError()));
+ delete s_relay.sock;
+ s_relay.sock = NULL;
+ s_relay.failedAt = Clock_Milliseconds();
+ return false;
+ }
+ }
+ const UnsignedInt asked = s_relay.wantVip;
+ for (Int tries = 0; tries < RELAY_HELLO_TRIES && !s_relay.vip; ++tries)
+ {
+ relaySendHello();
+ for (Int wait = 0; wait < 10 && !s_relay.vip; ++wait)
+ {
+ std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
+ pumpRelay();
+ }
+ }
+ if (!s_relay.vip)
+ {
+ DEBUG_LOG(("Transport: no WELCOME from the relay at %d.%d.%d.%d:%d in five seconds\n",
+ s_relay.ip >> 24, (s_relay.ip >> 16) & 0xff, (s_relay.ip >> 8) & 0xff, s_relay.ip & 0xff, s_relay.port));
+ s_relay.failedAt = Clock_Milliseconds();
+ return false;
+ }
+ relaySendHello(); // answers the WELCOME with its session, after which the relay forwards to us
+ DEBUG_LOG(("Transport: the relay calls us %d.%d.%d.%d\n",
+ s_relay.vip >> 24, (s_relay.vip >> 16) & 0xff, (s_relay.vip >> 8) & 0xff, s_relay.vip & 0xff));
+ // a -netgame slot that did not get its address hears nobody, and the match never starts
+ DEBUG_ASSERTLOG( !asked || s_relay.vip == asked, ("Transport: asked the relay for %d.%d.%d.%d, which another session holds\n",
+ asked >> 24, (asked >> 16) & 0xff, (asked >> 8) & 0xff, asked & 0xff) );
+ return true;
+}
+
+/// -online: the HELLO_AUTH handshake with the ticket of the login that just succeeded
+Bool Transport::openOnlineRelay( void )
+{
+ AsciiString host;
+ UnsignedShort relayPort = 0;
+ if (!OnlineGetRelayTicket( s_relay.ticket ) || !OnlineGetRelayEndpoint( host, relayPort ))
+ return false;
+ closeOnlineRelay(); // a second login gets a new session from a new ticket
+ s_relay.authed = true;
+ s_relay.wantVip = 0;
+ s_relay.failedAt = 0; // a login is a person asking; do not hold the last failure against it
+ s_relay.nameLength = 0;
+ return connectRelay( host, relayPort );
+}
+
+/// -online: the relay keepalive while the lobby and staging room have no Transport to pump it
+void Transport::keepOnlineRelay( void )
+{
+ if (s_relay.authed)
+ pumpRelay();
+}
+
+/// -online: forgets the session, so the next login starts clean. Transports still attached keep their slot.
+void Transport::closeOnlineRelay( void )
+{
+ if (!s_relay.authed)
+ return;
+ for (Int u = 0; u < RELAY_MAX_TRANSPORTS; ++u)
+ {
+ if (s_relay.users[u])
+ return; // a match still runs on it
+ }
+ if (s_relay.sock)
+ {
+ delete s_relay.sock;
+ s_relay.sock = NULL;
+ }
+ memset( s_relay.session, 0, RELAY_SESSION_BYTES );
+ s_relay.vip = 0;
+ s_relay.wantVip = 0;
+ s_relay.authed = false;
+}
+
+/// Joins the relay socket, opening it and waiting for a WELCOME (at most five seconds) the first time
+Bool Transport::initRelayed( UnsignedInt ip, UnsignedShort port )
+{
+ if (!s_relay.vip)
+ {
+ if (s_relay.authed)
+ return false; // -online: the login's handshake failed or the session was closed
+ s_relay.wantVip = (ip >> 24) == 10 ? ip : 0;
+ relayTakeName();
+ if (!connectRelay( TheGlobalData->m_relayHost, TheGlobalData->m_relayPort ))
+ return false;
+ }
+
+ for (Int u = 0; u < RELAY_MAX_TRANSPORTS; ++u)
+ {
+ if (!s_relay.users[u])
+ {
+ s_relay.users[u] = this;
+ m_relayed = true;
+ resetQueues( port );
+ return true;
+ }
+ }
+ DEBUG_CRASH(("Transport: more than %d transports on the relay\n", RELAY_MAX_TRANSPORTS));
+ return false;
+}
+
+void Transport::detachRelay( void )
+{
+ for (Int u = 0; u < RELAY_MAX_TRANSPORTS; ++u)
+ {
+ if (s_relay.users[u] == this)
+ s_relay.users[u] = NULL;
+ }
+ m_relayed = false;
+}
+
+/// One queued message into a DATA envelope; returns what Write returns
+Int Transport::writeRelayed( TransportMessage &msg )
+{
+ if (!s_relay.sock)
+ return -1;
+ const Int len = msg.length + sizeof(TransportMessageHeader);
+ unsigned char buf[RELAY_DATA_OUT_HEADER + MAX_NETWORK_MESSAGE_LEN];
+ buf[0] = 'Z'; buf[1] = 'R'; buf[2] = RELAY_DATA;
+ memcpy( buf + 3, s_relay.session, RELAY_SESSION_BYTES );
+ put32( buf + 11, msg.addr );
+ put16( buf + 15, msg.port );
+ put16( buf + 17, m_port );
+ memcpy( buf + RELAY_DATA_OUT_HEADER, &msg, len );
+ return s_relay.sock->Write( buf, RELAY_DATA_OUT_HEADER + len, s_relay.ip, s_relay.port );
+}
+
//--------------------------------------------------------------------------
+ TransportRoute *TheTransportRoute = NULL;
+
Transport::Transport(void)
{
m_winsockInit = false;
@@@ -624,7 -276,7 +632,7 @@@ Bool Transport::update( void
}
Bool Transport::doSend() {
- if (!m_udpsock && !m_relayed)
- if (!m_udpsock && !TheTransportRoute)
++ if (!m_udpsock && !m_relayed && !TheTransportRoute)
{
DEBUG_LOG(("Transport::doSend() - m_udpSock is NULL!\n"));
return FALSE;
@@@ -654,8 -306,9 +662,10 @@@
{
int bytesSent = 0;
// Send this message
+ const UnsignedInt wireLen = m_outBuffer[i].length + sizeof(TransportMessageHeader);
- if ((bytesSent = m_udpsock ? m_udpsock->Write((unsigned char *)(&m_outBuffer[i]), wireLen, m_outBuffer[i].addr, m_outBuffer[i].port)
+ if ((bytesSent = m_relayed ? writeRelayed(m_outBuffer[i])
- : m_udpsock->Write((unsigned char *)(&m_outBuffer[i]), m_outBuffer[i].length + sizeof(TransportMessageHeader), m_outBuffer[i].addr, m_outBuffer[i].port)) > 0)
++ : m_udpsock ? m_udpsock->Write((unsigned char *)(&m_outBuffer[i]), wireLen, m_outBuffer[i].addr, m_outBuffer[i].port)
+ : TheTransportRoute->send((unsigned char *)(&m_outBuffer[i]), wireLen, m_outBuffer[i].addr, m_outBuffer[i].port)) > 0)
{
//DEBUG_LOG(("Sending %d bytes to %d:%d\n", m_outBuffer[i].length + sizeof(TransportMessageHeader), m_outBuffer[i].addr, m_outBuffer[i].port));
m_outgoingPackets[m_statisticsSlot]++;
@@@ -700,80 -353,9 +710,80 @@@
return retval;
}
+/// One datagram of len bytes in incomingMessage, from addr:port, into the inbox (or the latency simulator's)
+void Transport::receivePacket( TransportMessage &incomingMessage, Int len, UnsignedInt addr, UnsignedShort port, UnsignedInt now )
+{
+ unsigned char *buf = (unsigned char *)&incomingMessage;
+
+ // Packet loss simulation
+ if (m_usePacketLoss)
+ {
+ if ( linkSimPacketIsLost( TheGlobalData->m_packetLoss, GameClientRandomValue(1, 100) ) )
+ {
+ return;
+ }
+ }
+
+ // Decrypt the packet
+ decryptBuf(buf, len);
+
+ incomingMessage.length = len - sizeof(TransportMessageHeader);
+
+ if (len <= sizeof(TransportMessageHeader) || !isGeneralsPacket( &incomingMessage ))
+ {
+ m_unknownPackets[m_statisticsSlot]++;
+ m_unknownBytes[m_statisticsSlot] += len;
+ return;
+ }
+
+ // Something there; stick it somewhere
+ m_incomingPackets[m_statisticsSlot]++;
+ m_incomingBytes[m_statisticsSlot] += len;
+
+ for (int i=0; i<MAX_MESSAGES; ++i)
+ {
+ // Latency simulation
+ if (m_useLatency)
+ {
+ if (m_delayedInBuffer[i].message.length == 0)
+ {
+ // Empty slot; use it
+ m_delayedInBuffer[i].deliveryTime = linkSimDeliveryTime( now,
+ TheGlobalData->m_latencyAverage, TheGlobalData->m_latencyAmplitude,
+ TheGlobalData->m_latencyPeriod,
+ GameClientRandomValue(-TheGlobalData->m_latencyNoise, TheGlobalData->m_latencyNoise) );
+ m_delayedInBuffer[i].message.length = incomingMessage.length;
+ m_delayedInBuffer[i].message.addr = addr;
+ m_delayedInBuffer[i].message.port = port;
+ memcpy(&m_delayedInBuffer[i].message, buf, len);
+ break;
+ }
+ }
+ else
+ {
+ if (m_inBuffer[i].length == 0)
+ {
+ // Empty slot; use it
+ m_inBuffer[i].length = incomingMessage.length;
+ m_inBuffer[i].addr = addr;
+ m_inBuffer[i].port = port;
+ memcpy(&m_inBuffer[i], buf, len);
+ break;
+ }
+ }
+ }
+ //DEBUG_ASSERTCRASH(i<MAX_MESSAGES, ("Message lost!"));
+}
+
Bool Transport::doRecv()
{
+ if (m_relayed)
+ {
+ pumpRelay();
+ return TRUE;
+ }
+
- if (!m_udpsock)
+ if (!m_udpsock && !TheTransportRoute)
{
DEBUG_LOG(("Transport::doRecv() - m_udpSock is NULL!\n"));
return FALSE;
@@@ -788,9 -370,74 +798,9 @@@
TransportMessage incomingMessage;
unsigned char *buf = (unsigned char *)&incomingMessage;
int len = MAX_NETWORK_MESSAGE_LEN;
- while ( (len=m_udpsock->Read(buf, MAX_NETWORK_MESSAGE_LEN, &from)) > 0 )
-// DEBUG_LOG(("Transport::doRecv - checking\n"));
+ while ( (len=(m_udpsock ? m_udpsock->Read(buf, MAX_NETWORK_MESSAGE_LEN, &from) : TheTransportRoute->recv(buf, MAX_NETWORK_MESSAGE_LEN, &from))) > 0 )
{
- // Packet loss simulation
- if (m_usePacketLoss)
- {
- if ( linkSimPacketIsLost( TheGlobalData->m_packetLoss, GameClientRandomValue(1, 100) ) )
- {
- continue;
- }
- }
-
-// DEBUG_LOG(("Transport::doRecv - Got something! len = %d\n", len));
- // Decrypt the packet
-// DEBUG_LOG(("buffer = "));
-// for (Int munkee = 0; munkee < len; ++munkee) {
-// DEBUG_LOG(("%02x", *(buf + munkee)));
-// }
-// DEBUG_LOG(("\n"));
- decryptBuf(buf, len);
-
- incomingMessage.length = len - sizeof(TransportMessageHeader);
-
- if (len <= sizeof(TransportMessageHeader) || !isGeneralsPacket( &incomingMessage ))
- {
- m_unknownPackets[m_statisticsSlot]++;
- m_unknownBytes[m_statisticsSlot] += len;
- continue;
- }
-
- // Something there; stick it somewhere
-// DEBUG_LOG(("Saw %d bytes from %d:%d\n", len, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port)));
- m_incomingPackets[m_statisticsSlot]++;
- m_incomingBytes[m_statisticsSlot] += len;
-
- for (int i=0; i<MAX_MESSAGES; ++i)
- {
- // Latency simulation
- if (m_useLatency)
- {
- if (m_delayedInBuffer[i].message.length == 0)
- {
- // Empty slot; use it
- m_delayedInBuffer[i].deliveryTime = linkSimDeliveryTime( now,
- TheGlobalData->m_latencyAverage, TheGlobalData->m_latencyAmplitude,
- TheGlobalData->m_latencyPeriod,
- GameClientRandomValue(-TheGlobalData->m_latencyNoise, TheGlobalData->m_latencyNoise) );
- m_delayedInBuffer[i].message.length = incomingMessage.length;
- m_delayedInBuffer[i].message.addr = ntohl(from.sin_addr.s_addr);
- m_delayedInBuffer[i].message.port = ntohs(from.sin_port);
- memcpy(&m_delayedInBuffer[i].message, buf, len);
- break;
- }
- }
- else
- {
- if (m_inBuffer[i].length == 0)
- {
- // Empty slot; use it
- m_inBuffer[i].length = incomingMessage.length;
- m_inBuffer[i].addr = ntohl(from.sin_addr.s_addr);
- m_inBuffer[i].port = ntohs(from.sin_port);
- memcpy(&m_inBuffer[i], buf, len);
- break;
- }
- }
- }
- //DEBUG_ASSERTCRASH(i<MAX_MESSAGES, ("Message lost!"));
+ receivePacket( incomingMessage, len, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port), now );
}
if (len == -1) {