From 00841cd14df0887e07cb24fe4cf4fc17011cac59 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Thu, 24 Sep 2026 09:34:04 -0700 Subject: [PATCH 01/15] fix(net): Pad a one-byte base64 tail correctly Base64Encode emitted a one-byte tail as XXX= instead of XX==, because its padding test compared the consumed index against size + 1, which is never true. Any input whose length is 1 mod 3 therefore decoded to one byte too many. Found streaming replay chunks for live spectating, where the extra byte shifted every later offset and zeroed a byte of the replay header. --- .../GeneralsOnline/NGMP_Helpers.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp index 77223c06347..4c33f6377f7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp @@ -204,21 +204,23 @@ std::string Base64Encode(const std::vector& data) "0123456789+/"; std::string encoded; - size_t i = 0; - uint32_t octet_a, octet_b, octet_c, triple; + encoded.reserve((data.size() + 2) / 3 * 4); - while (i < data.size()) + // TheSuperHackers @bugfix bill-rich 24/09/2026 A one-byte tail was emitted as "XXX=" instead of "XX==": + // the old padding test compared the consumed index against size + 1, which can never be + // true, so every input whose length is 1 mod 3 decoded to one byte too many. + for (size_t i = 0; i < data.size(); i += 3) { - octet_a = i < data.size() ? data[i++] : 0; - octet_b = i < data.size() ? data[i++] : 0; - octet_c = i < data.size() ? data[i++] : 0; - - triple = (octet_a << 16) | (octet_b << 8) | octet_c; + const size_t remaining = data.size() - i; + const uint32_t octet_a = data[i]; + const uint32_t octet_b = remaining > 1 ? data[i + 1] : 0; + const uint32_t octet_c = remaining > 2 ? data[i + 2] : 0; + const uint32_t triple = (octet_a << 16) | (octet_b << 8) | octet_c; encoded += base64_chars[(triple >> 18) & 0x3F]; encoded += base64_chars[(triple >> 12) & 0x3F]; - encoded += (i >= data.size() + 1) ? '=' : base64_chars[(triple >> 6) & 0x3F]; - encoded += (i >= data.size()) ? '=' : base64_chars[triple & 0x3F]; + encoded += remaining > 1 ? base64_chars[(triple >> 6) & 0x3F] : '='; + encoded += remaining > 2 ? base64_chars[triple & 0x3F] : '='; } return encoded; From f04f0a0e19f1757346be7b512bdd5e45c1ae6bc3 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Thu, 24 Sep 2026 14:54:48 -0700 Subject: [PATCH 02/15] fix(net): Send a JSON content type on requests that carry a body Without a Content-Type libcurl labels the body application/x-www-form-urlencoded, so the service form-parses it and rejects anything past its form key limit: a large JSON payload reads as one enormous key and the request fails with 400 "form key length limit 2048 exceeded". Small bodies happened to survive because the parse succeeded and nothing read the result. Requests that set their own type, such as the S3 uploads, are left alone. --- .../GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp index 02786d7f3d9..8c4981a7ccb 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp @@ -273,6 +273,17 @@ void HTTPRequest::PlatformStartRequest() } } + // TheSuperHackers @bugfix bill-rich 24/09/2026 Say what the body is. Without a Content-Type + // libcurl sends application/x-www-form-urlencoded, and a service that form-parses on that + // header rejects any body large enough to exceed its form key limit, because the whole + // payload reads as one enormous key. Every request built here carries JSON unless the + // caller set a type of its own (the S3 uploads set theirs). + if ((m_httpVerb == EHTTPVerb::HTTP_VERB_POST || m_httpVerb == EHTTPVerb::HTTP_VERB_PUT || m_httpVerb == EHTTPVerb::HTTP_VERB_DELETE) + && m_mapHeaders.find("Content-Type") == m_mapHeaders.end()) + { + m_mapHeaders["Content-Type"] = "application/json"; + } + for (auto& kvPair : m_mapHeaders) { std::string strHeader = kvPair.first + ": " + kvPair.second; From b8c80a775a66189321db407ace64c46fea2b7063 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Tue, 15 Sep 2026 14:41:54 -0700 Subject: [PATCH 03/15] feat(lobby): Add the host bulk slot update Lets the host push side, color, start position and team for every occupied slot in one request (HOST_ACTION_BULK_SLOT_UPDATE, field 19, supported by Services since PR #13). Shared with the Random button change; whichever lands first carries it. --- .../OnlineServices_LobbyInterface.h | 2 + .../OnlineServices_LobbyInterface.cpp | 45 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index 5e89ed8d313..0f4a9eab5b8 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -226,6 +226,8 @@ class NGMP_OnlineServices_LobbyInterface void UpdateCurrentLobby_AITeam(int slot, int team); void UpdateCurrentLobby_AIStartPos(int slot, int startpos); + void UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game); + void UpdateCurrentLobbyMaxCameraHeight(uint16_t maxCameraHeight); void SetJoinability(ELobbyJoinability joinabilityFlag); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index 4b5b9da9cbc..00ce8d51bc7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -74,7 +74,8 @@ enum class ELobbyUpdateField AI_TEAM = 15, AI_START_POS = 16, MAX_CAMERA_HEIGHT = 17, - JOINABILITY = 18 + JOINABILITY = 18, + HOST_ACTION_BULK_SLOT_UPDATE = 19 }; void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers) @@ -493,6 +494,48 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ForceReady() }); } +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game) +{ + // reset autostart if host changes anything (because ready flag will reset too) +#if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) + ClearAutoReadyCountdown(); +#endif + if (TheNGMPGame && TheNGMPGame->IsCountdownStarted()) + TheNGMPGame->StopCountdown(); + + std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), m_CurrentLobby.lobbyID); + std::map mapHeaders; + + nlohmann::json j; + j["field"] = ELobbyUpdateField::HOST_ACTION_BULK_SLOT_UPDATE; + + nlohmann::json slotsArray = nlohmann::json::array(); + for (int i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *slot = game->getConstSlot(i); + if (slot && slot->isOccupied()) + { + nlohmann::json slotEntry; + slotEntry["slot_index"] = i; + slotEntry["side"] = slot->getPlayerTemplate(); + slotEntry["color"] = slot->getColor(); + slotEntry["start_pos"] = slot->getStartPos(); + slotEntry["team"] = slot->getTeamNumber(); + slotsArray.push_back(slotEntry); + } + } + j["slots"] = slotsArray; + std::string strPostData = j.dump(); + + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + { + if (!bSuccess || statusCode < 200 || statusCode >= 300) + { + DEBUG_LOG(("UpdateCurrentLobby_BulkSlotUpdate failed: success=%d, status=%d", bSuccess, statusCode)); + } + }); +} + void NGMP_OnlineServices_LobbyInterface::SendChatMessageToCurrentLobby(UnicodeString& strChatMsgUnicode, bool bIsAction) { std::shared_ptr pWS = NGMP_OnlineServicesManager::GetWebSocket();; From eb6c5cb938918978a625dae18f648c9470f6a5d1 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Tue, 15 Sep 2026 10:28:21 -0700 Subject: [PATCH 04/15] feat(resume): Resume a match from its replay with lockstep catch-up Adds RECORDERMODETYPE_RESUME_CATCHUP. When the lobby arms a replay, every client opens its own copy on game start and injects its recorded commands frame by frame while the live network game runs in lockstep at an uncapped rate, renders on a wall-clock cadence and skips CRC validation. The last 10 seconds before the handoff frame run at normal speed, then the simulation is held for a 10 second countdown, then control is handed back and the replay file is taken over for recording so the resumed match is one complete replay. Camera scrolling works throughout; selection, commands, control bar and hotkeys are inert until the countdown ends. LAN lobbies arm with the /resume chat command (or a ButtonResumeFromReplay if the layout has one): the last recorded replay is validated against the lobby roster, the lobby is aligned to the replay's slots and seed, and RF=/RHF= tokens carry the file and handoff frame to every client. --- .../GameEngine/Include/GameNetwork/GameInfo.h | 12 + .../Include/GameNetwork/NetworkDefs.h | 6 + .../Include/GameNetwork/NetworkInterface.h | 5 + Core/GameEngine/Source/Common/FramePacer.cpp | 9 + .../ControlBarCommandProcessing.cpp | 6 + .../GameClient/MessageStream/CommandXlat.cpp | 6 +- .../MessageStream/SelectionXlat.cpp | 4 +- .../Source/GameNetwork/ConnectionManager.cpp | 37 ++- .../Source/GameNetwork/DisconnectManager.cpp | 6 + .../Source/GameNetwork/FrameMetrics.cpp | 26 +- .../Source/GameNetwork/GameInfo.cpp | 23 ++ .../GameEngine/Source/GameNetwork/Network.cpp | 25 +- .../Code/GameEngine/Include/Common/Recorder.h | 32 +- .../GameEngine/Source/Common/GameEngine.cpp | 34 ++- .../GameEngine/Source/Common/Recorder.cpp | 283 +++++++++++++++++- .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 224 ++++++++++++++ .../GUI/GUICallbacks/Menus/ReplayMenu.cpp | 3 +- .../GameEngine/Source/GameClient/InGameUI.cpp | 2 +- .../Source/GameLogic/System/GameLogic.cpp | 8 +- 19 files changed, 721 insertions(+), 30 deletions(-) diff --git a/Core/GameEngine/Include/GameNetwork/GameInfo.h b/Core/GameEngine/Include/GameNetwork/GameInfo.h index 5483bbeba58..0289100e52d 100644 --- a/Core/GameEngine/Include/GameNetwork/GameInfo.h +++ b/Core/GameEngine/Include/GameNetwork/GameInfo.h @@ -220,6 +220,14 @@ class GameInfo void setCRCInterval( Int val ) { m_crcInterval = (val > 0 && val < 100) ? val : 100; } Int getCRCInterval() const { return m_crcInterval; } + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming. When non-empty, every client + // opens its own copy of this replay on game start and replays it in lockstep up + // to the handoff frame before live control resumes (see RecorderClass). + void setResumeReplayFile( AsciiString f ) { m_resumeReplayFile = f; } + AsciiString getResumeReplayFile() const { return m_resumeReplayFile; } + void setResumeHandoffFrame( UnsignedInt f ) { m_resumeHandoffFrame = f; } + UnsignedInt getResumeHandoffFrame() const { return m_resumeHandoffFrame; } + Bool haveWeSurrendered() { return m_surrendered; } void markAsSurrendered() { m_surrendered = TRUE; } @@ -254,6 +262,10 @@ class GameInfo Money m_startingCash; UnsignedShort m_superweaponRestriction; Bool m_oldFactionsOnly; // Only USA, China, GLA -- not USA Air Force General, GLA Toxic General, et al + + // resume-from-replay arming (appended last so existing member offsets are untouched) + AsciiString m_resumeReplayFile; + UnsignedInt m_resumeHandoffFrame; }; extern GameInfo *TheGameInfo; diff --git a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h index 6295493ea7d..314e566218d 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h @@ -43,6 +43,12 @@ static Int MIN_RUNAHEAD = 6; static constexpr const Int MIN_RUNAHEAD = 4; #endif +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup pins the run-ahead and the +// logic frame rate that ConnectionManager::updateRunAhead negotiates, so every +// peer derives the same short packet send interval while fast-forwarding. +static constexpr const Int CATCHUP_RUNAHEAD = 32; +static constexpr const Int CATCHUP_FRAME_RATE = 1000; + // FRAME_DATA_LENGTH needs to be MAX_FRAMES_AHEAD+1 because a player on a different // computer can send commands for a frame that is one beyond twice the max runahead. static constexpr const Int FRAME_DATA_LENGTH = (MAX_FRAMES_AHEAD + 1) * 2; diff --git a/Core/GameEngine/Include/GameNetwork/NetworkInterface.h b/Core/GameEngine/Include/GameNetwork/NetworkInterface.h index 606429450dd..5e98bac2cb6 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkInterface.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkInterface.h @@ -123,6 +123,11 @@ class NetworkInterface : public SubsystemInterface virtual void notifyOthersOfCurrentFrame() = 0; ///< Tells all the other players what frame we are on. virtual void notifyOthersOfNewFrame(UnsignedInt frame) = 0; ///< Tells all the other players that we are on a new frame. + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup: override the network's + // logic frame-rate cap so timeForNewFrame() lets frames advance faster than realtime. + // Returns the previous rate for restoration. + virtual Int setLogicFrameRate(Int fps) = 0; + virtual Int getExecutionFrame() = 0; ///< Returns the next valid frame for simultaneous command execution. #if defined(RTS_DEBUG) diff --git a/Core/GameEngine/Source/Common/FramePacer.cpp b/Core/GameEngine/Source/Common/FramePacer.cpp index d764c9c1414..c23067ddb63 100644 --- a/Core/GameEngine/Source/Common/FramePacer.cpp +++ b/Core/GameEngine/Source/Common/FramePacer.cpp @@ -24,6 +24,7 @@ #include "GameLogic/GameLogic.h" #include "GameLogic/ScriptEngine.h" +#include "Common/Recorder.h" #include "GameNetwork/NetworkDefs.h" #include "GameNetwork/NetworkInterface.h" @@ -109,6 +110,14 @@ Bool FramePacer::isActualFramesPerSecondLimitEnabled() const #endif } + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup runs one logic frame per + // render frame and fast-forwards many times faster than realtime, so the render + // cap has to get out of the way until the lead-in. + if (TheRecorder != nullptr && TheRecorder->isResumeCatchupMode() && !TheRecorder->isResumeCatchupLeadIn()) + { + allowFpsLimit = false; + } + allowFpsLimit &= TheGlobalData->m_useFpsLimit; allowFpsLimit &= isFramesPerSecondLimitEnabled(); diff --git a/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp index 5e2c41a3d48..7cb97c7f0bd 100644 --- a/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp +++ b/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp @@ -35,6 +35,7 @@ #include "Common/Money.h" #include "Common/Player.h" #include "Common/PlayerList.h" +#include "Common/Recorder.h" #include "Common/Science.h" #include "Common/SpecialPower.h" #include "Common/ThingTemplate.h" @@ -120,6 +121,11 @@ CBCommandStatus ControlBar::processCommandTransitionUI( GameWindow *control, Gad CBCommandStatus ControlBar::processCommandUI( GameWindow *control, GadgetGameMessage gadgetMessage ) { + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup: control bar buttons and + // their hotkeys (which re-dispatch into this path) are inert until control is handed back + if( TheRecorder && TheRecorder->isResumeInputBlocked() ) + return CBC_COMMAND_NOT_USED; + // get the command pointer from the control user data we put in the button const CommandButton *commandButton = (const CommandButton *)GadgetButtonGetData(control); if( !commandButton ) diff --git a/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp index 231a6f355b4..3418f9e7f18 100644 --- a/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp +++ b/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp @@ -2550,8 +2550,12 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage GameMessage::Type t = msg->getType(); GameMessageDisposition disp = KEEP_MESSAGE; // We want to always be able to get to the options menu even during no input times and a clear game data message should always go through + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup blocks every command the + // same way disabled input does (camera scrolling lives in LookAtTranslator and + // stays available); the options menu stays reachable so a stuck catchup can be left. + const Bool resumeBlocked = TheRecorder && TheRecorder->isResumeInputBlocked(); if (t != GameMessage::MSG_META_OPTIONS && t != GameMessage::MSG_CLEAR_GAME_DATA && - !TheInGameUI->getInputEnabled() && !isSystemMessage(msg)) + (!TheInGameUI->getInputEnabled() || resumeBlocked) && !isSystemMessage(msg)) { return DESTROY_MESSAGE; } diff --git a/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp index 9bea5b26d4d..a7df9caa4c0 100644 --- a/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp +++ b/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp @@ -54,6 +54,7 @@ #include "GameClient/Keyboard.h" #include "GameClient/SelectionInfo.h" #include "GameClient/SelectionXlat.h" +#include "Common/Recorder.h" #include "GameClient/TerrainVisual.h" @@ -350,7 +351,8 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa { GameMessageDisposition disp = KEEP_MESSAGE; - if( !TheInGameUI->getInputEnabled() ) + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup: no selecting until control is handed back + if( !TheInGameUI->getInputEnabled() || (TheRecorder && TheRecorder->isResumeInputBlocked()) ) { //Keep the message so the other translators (WindowXlat) can handle. if( m_dragSelecting ) diff --git a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp index f347db5a83f..ad4d4a0c689 100644 --- a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp @@ -1510,6 +1510,24 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS newRunAhead = clamp(minRunAheadForClamp, newRunAhead, MAX_FRAMES_AHEAD / 2); + // TheSuperHackers @feature bill-rich 15/09/2026 During resume-from-replay catchup Network::update() + // drops the realtime frame gate, so the only thing bounding how fast we + // replay is lockstep: a frame advances once every peer's commands for it have + // arrived. Throughput is (frames in flight) / (packet send interval), and + // processRunAheadCommand derives that interval from runAhead and frameRate. + // The values negotiated above are tuned for realtime play and are hostile + // here (a low-latency LAN bottoms out at MIN_RUNAHEAD, barely 2x realtime), + // so pin a deep pipeline and a short send interval instead. The lead-in + // (last seconds before handoff) falls through to the normal negotiation so + // run-ahead and frame rate re-converge before control is handed back. + const Bool pinCatchupRates = TheRecorder + && TheRecorder->isResumeCatchupMode() + && !TheRecorder->isResumeCatchupLeadIn(); + if (pinCatchupRates) { + newRunAhead = CATCHUP_RUNAHEAD; + minFps = CATCHUP_FRAME_RATE; + } + NetRunAheadCommandMsg* msg = newInstance(NetRunAheadCommandMsg); msg->setPlayerID(m_localSlot); if (DoesCommandRequireACommandID(msg->getNetCommandType())) { @@ -1582,14 +1600,17 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS // Let the player with the slowest FPS run a little faster than the other computers... // just in case they are able to. Then we might be able to run the game faster which would be good. - Int newMinFps = (minFps * 11) / 10; - if (newMinFps == minFps) { - newMinFps = minFps + 1; - } - - - if (newMinFps > TheNetwork->getFrameRate()) { - newMinFps = TheNetwork->getFrameRate(); // Cap FPS to network frame rate. + // During catchup every peer must derive the SAME packet send interval, so the + // slowest-player nudge and the network frame-rate cap are skipped. + Int newMinFps = minFps; + if (!pinCatchupRates) { + newMinFps = (minFps * 11) / 10; + if (newMinFps == minFps) { + newMinFps = minFps + 1; + } + if (newMinFps > TheNetwork->getFrameRate()) { + newMinFps = TheNetwork->getFrameRate(); // Cap FPS to network frame rate. + } } msg2->setRunAhead(newRunAhead); msg2->setFrameRate(newMinFps); diff --git a/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp b/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp index 9d2f1b58574..1a1543e5767 100644 --- a/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp @@ -98,6 +98,12 @@ void DisconnectManager::update(ConnectionManager *conMgr) { m_lastFrameTime = timeGetTime(); } + // TheSuperHackers @feature bill-rich 15/09/2026 The resume-from-replay freeze deliberately holds the + // logic frame for a countdown; that is not a stalled peer. + if (TheRecorder && TheRecorder->isResumeFreezeActive()) { + m_lastFrameTime = timeGetTime(); + } + // The game logic stalls on the frame we are currently waiting for commands on, // so we have to check for the current logic frame being one higher than // the last one we had the commands ready for. diff --git a/Core/GameEngine/Source/GameNetwork/FrameMetrics.cpp b/Core/GameEngine/Source/GameNetwork/FrameMetrics.cpp index 0de0dd2096c..aebe6d3eb1d 100644 --- a/Core/GameEngine/Source/GameNetwork/FrameMetrics.cpp +++ b/Core/GameEngine/Source/GameNetwork/FrameMetrics.cpp @@ -30,6 +30,7 @@ #include "GameNetwork/FrameMetrics.h" #include "GameClient/Display.h" +#include "Common/Recorder.h" #include "GameNetwork/networkutil.h" #include "../NGMP_include.h" #include "../NetworkMesh.h" @@ -145,16 +146,21 @@ void FrameMetrics::doPerFrameMetrics(UnsignedInt frame) { // Do the measurement of the fps. time_t curTime = timeGetTime(); if ((curTime - m_lastFpsTimeThing) >= 1000) { -// if ((m_fpsListIndex % 16) == 0) { -// DEBUG_LOG(("FrameMetrics::doPerFrameMetrics - adding %f to fps history. average before: %f ", m_fpsList[m_fpsListIndex], m_averageFps)); -// } - m_averageFps -= ((m_fpsList[m_fpsListIndex])) / TheGlobalData->m_networkFPSHistoryLength; // subtract out the old value from the average. - m_fpsList[m_fpsListIndex] = TheDisplay->getAverageFPS(); -// m_fpsList[m_fpsListIndex] = TheGameClient->getFrame() - m_fpsStartingFrame; - m_averageFps += ((Real)(m_fpsList[m_fpsListIndex])) / TheGlobalData->m_networkFPSHistoryLength; // add the new value to the average. -// DEBUG_LOG(("average after: %f", m_averageFps)); - ++m_fpsListIndex; - m_fpsListIndex %= TheGlobalData->m_networkFPSHistoryLength; + // TheSuperHackers @feature bill-rich 15/09/2026 This history is the input to + // ConnectionManager::updateRunAhead, i.e. how this machine tells the rest of + // the game how fast it can run. During resume-from-replay catchup the renderer + // is deliberately throttled while logic fast-forwards, so display FPS measures + // the throttle, not the machine; sampling it would collapse the run-ahead + // negotiation. Hold the history steady through catchup and resume sampling + // for real on handoff. + const Bool inCatchup = (TheRecorder != nullptr) && TheRecorder->isResumeCatchupMode(); + if (!inCatchup) { + m_averageFps -= ((m_fpsList[m_fpsListIndex])) / TheGlobalData->m_networkFPSHistoryLength; // subtract out the old value from the average. + m_fpsList[m_fpsListIndex] = TheDisplay->getAverageFPS(); + m_averageFps += ((Real)(m_fpsList[m_fpsListIndex])) / TheGlobalData->m_networkFPSHistoryLength; // add the new value to the average. + ++m_fpsListIndex; + m_fpsListIndex %= TheGlobalData->m_networkFPSHistoryLength; + } m_lastFpsTimeThing = curTime; } diff --git a/Core/GameEngine/Source/GameNetwork/GameInfo.cpp b/Core/GameEngine/Source/GameNetwork/GameInfo.cpp index d7bd46bd336..0196168240f 100644 --- a/Core/GameEngine/Source/GameNetwork/GameInfo.cpp +++ b/Core/GameEngine/Source/GameNetwork/GameInfo.cpp @@ -323,6 +323,8 @@ void GameInfo::reset() m_mapSize = 0; m_superweaponRestriction = 0; m_startingCash = TheGlobalData->m_defaultStartingCash; + m_resumeReplayFile.clear(); + m_resumeHandoffFrame = 0; for (Int i=0; igetResumeReplayFile().isEmpty()) + { + AsciiString resume; + resume.format("RF=%s;RHF=%u;", game->getResumeReplayFile().str(), game->getResumeHandoffFrame()); + optionsString.concat(resume); + } + DEBUG_ASSERTCRASH(!TheLAN || (optionsString.getLength() < m_lanMaxOptionsLength), ("WARNING: options string is longer than expected! Length is %d, but max is %d!", optionsString.getLength(), m_lanMaxOptionsLength)); @@ -1028,6 +1039,8 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options) Int useStats = TRUE; Money startingCash = TheGlobalData->m_defaultStartingCash; UnsignedShort restriction = 0; // Always the default + AsciiString resumeReplayFile; + UnsignedInt resumeHandoffFrame = 0; Bool sawMap = FALSE; Bool sawMapCRC = FALSE; @@ -1147,6 +1160,14 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options) oldFactionsOnly = ( val.compareNoCase( "Y" ) == 0 ); sawOldFactions = TRUE; } + else if (key.compare("RF") == 0) + { + resumeReplayFile = val; + } + else if (key.compare("RHF") == 0) + { + resumeHandoffFrame = (UnsignedInt)strtoul(val.str(), nullptr, 10); + } else if (key.getLength() == 1 && *key.str() == slotListID) { sawSlotlist = true; @@ -1515,6 +1536,8 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options) game->setSuperweaponRestriction(restriction); game->setStartingCash(startingCash); game->setOldFactionsOnly(oldFactionsOnly); + game->setResumeReplayFile(resumeReplayFile); + game->setResumeHandoffFrame(resumeHandoffFrame); return true; } diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index a149bca7179..888bcda04e1 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -179,6 +179,7 @@ class Network : public NetworkInterface virtual void notifyOthersOfCurrentFrame() override; ///< Tells all the other players what frame we are on. virtual void notifyOthersOfNewFrame(UnsignedInt frame) override; ///< Tells all the other players that we are on a new frame. + virtual Int setLogicFrameRate(Int fps) override; ///< Resume-from-replay catchup: override the per-frame timing rate; returns the previous rate. virtual Int getExecutionFrame() override; ///< Returns the next valid frame for simultaneous command execution. @@ -485,6 +486,13 @@ void Network::attachTransport(Transport* transport) { } Bool Network::isMessageTypeWithinNetworkRange(GameMessage::Type type) { + // TheSuperHackers @feature bill-rich 15/09/2026 During resume-from-replay catchup every peer injects + // the same commands from its own copy of the replay, so re-broadcasting them + // would double them on the receiver. Treat everything as non-transfer so it flows + // through processCommand instead, which also drives the per-frame tick forward. + if (TheRecorder && TheRecorder->isResumeCatchupMode()) { + return FALSE; + } return type > GameMessage::MSG_BEGIN_NETWORK_MESSAGES && type < GameMessage::MSG_END_NETWORK_MESSAGES; } @@ -778,10 +786,17 @@ void Network::update() endOfGameCheck(); } - if (AllCommandsReady(TheGameLogic->getFrame())) { // If all the commands are ready for the next frame... + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: the freeze after the handoff holds + // the simulation on this frame for a wall-clock countdown while the network keeps + // pumping, and catchup before it skips the realtime timing gate (timeForNewFrame) so + // frames advance as fast as lockstep allows. AllCommandsReady stays enforced either way. + const Bool resumeFrozen = TheRecorder && TheRecorder->updateResumeFreeze(); + const Bool inCatchup = TheRecorder && TheRecorder->isResumeCatchupMode(); + + if (!resumeFrozen && AllCommandsReady(TheGameLogic->getFrame())) { // If all the commands are ready for the next frame... m_conMgr->handleAllCommandsReady(); // DEBUG_LOG(("Network::update - frame %d is ready", TheGameLogic->getFrame())); - if (timeForNewFrame()) { // This needs to come after any other pre-frame execution checks as this changes the timing variables. + if (inCatchup || timeForNewFrame()) { // This needs to come after any other pre-frame execution checks as this changes the timing variables. RelayCommandsToCommandList(TheGameLogic->getFrame()); // Put the commands for the next frame on TheCommandList. m_frameDataReady = TRUE; // Tell the GameEngine to run the commands for the new frame. } @@ -1116,3 +1131,9 @@ void Network::notifyOthersOfNewFrame(UnsignedInt frame) { m_conMgr->notifyOthersOfNewFrame(frame); } } + +Int Network::setLogicFrameRate(Int fps) { + Int prev = m_frameRate; + m_frameRate = fps > 0 ? fps : 1; + return prev; +} diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h index fba73ad5ec3..6fe38ce855a 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h @@ -50,7 +50,8 @@ enum RecorderModeType CPP_11(: Int) { RECORDERMODETYPE_RECORD, RECORDERMODETYPE_PLAYBACK, RECORDERMODETYPE_SIMULATION_PLAYBACK, // Play back replay without any graphics - RECORDERMODETYPE_NONE // this is a valid state to be in on the shell map, or in saved games + RECORDERMODETYPE_NONE, // this is a valid state to be in on the shell map, or in saved games + RECORDERMODETYPE_RESUME_CATCHUP // Resume-from-replay: feed replay commands into a live network game until the handoff frame. }; class RecorderClass : public SubsystemInterface @@ -138,6 +139,26 @@ class RecorderClass : public SubsystemInterface RecorderModeType getMode(); ///< Returns the current operating mode. Bool isPlaybackMode() const { return m_mode == RECORDERMODETYPE_PLAYBACK || m_mode == RECORDERMODETYPE_SIMULATION_PLAYBACK; } + + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay. + // + // Every client opens its own copy of the same replay when the game starts and + // injects its recorded commands frame by frame while the live network game runs + // in lockstep at an uncapped rate (catchup). The last RESUME_LEADIN_SECONDS before + // the handoff frame run at normal speed (lead-in), then the simulation is held for + // RESUME_FREEZE_SECONDS of wall-clock time with a countdown (freeze), and finally + // control is handed back to the players. Camera scrolling works throughout; every + // other interaction is blocked until the freeze ends (see isResumeInputBlocked). + static const Int RESUME_LEADIN_SECONDS = 10; + static const Int RESUME_FREEZE_SECONDS = 10; + Bool isResumeCatchupMode() const { return m_mode == RECORDERMODETYPE_RESUME_CATCHUP; } + Bool isResumeCatchupLeadIn() const; ///< catchup, within the last RESUME_LEADIN_SECONDS before handoff + Bool isResumeFreezeActive() const { return m_resumeFreezeStartMs != 0; } ///< handoff reached, holding the sim with a countdown + Bool isResumeInputBlocked() const { return isResumeCatchupMode() || isResumeFreezeActive(); } + Bool updateResumeFreeze(); ///< pumped every engine frame by Network::update; TRUE while frames must not advance + Bool startResumeCatchup(AsciiString filename, UnsignedInt handoffFrame); + void updateResumeCatchup(); + Bool beginRecordingAfterResume(); ///< take the replay file over for recording so the resumed match is a complete replay void initControls(); ///< Show or Hide the Replay controls static AsciiString getReplayDir(); ///< Returns the directory that holds the replay files. @@ -198,6 +219,15 @@ class RecorderClass : public SubsystemInterface Int m_originalGameMode; // valid in replays UnsignedInt m_nextFrame; ///< The Frame that the next message is to be executed on. This can be -1. + + // resume-from-replay state (see the accessors above) + UnsignedInt m_resumeHandoffFrame; ///< frame at which replay injection stops and the freeze begins + Int m_resumeSavedFpsLimit; ///< render FPS limit to restore after catchup + Int m_resumeSavedNetFrameRate; ///< network logic frame rate to restore after catchup + Int m_resumeRecordPos; ///< byte offset just past the last replayed record; beginRecordingAfterResume truncates here + Bool m_resumeRatesRestored; ///< lead-in reached and the rate caps are back to normal + UnsignedInt m_resumeFreezeStartMs; ///< wall-clock start of the freeze, 0 when not frozen + Int m_resumeFreezeLastAnnounced; ///< last countdown second shown }; extern RecorderClass *TheRecorder; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp index 0c497745de0..06dac86fb70 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp @@ -937,7 +937,12 @@ Bool GameEngine::canUpdateRegularGameLogic(UnsignedInt logicTimeQueryFlags) const Bool useFastMode = TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame(); #endif - if (useFastMode || logicTimeScaleFps >= maxRenderFps) + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup fast-forwards by running + // one logic frame per render frame; the logic time scale must not throttle it. + const Bool inCatchup = TheRecorder && TheRecorder->isResumeCatchupMode() + && !TheRecorder->isResumeCatchupLeadIn(); + + if (useFastMode || inCatchup || logicTimeScaleFps >= maxRenderFps) { // Logic time scale is uncapped or larger equal Render FPS. Update straight away. return true; @@ -973,6 +978,28 @@ void GameEngine::update() { USE_PERF_TIMER(GameEngine_update) { + // TheSuperHackers @feature bill-rich 15/09/2026 During resume-from-replay catchup, render on a + // wall-clock cadence rather than once per logic frame: logic is fast-forwarding + // at many times realtime, so drawing every logic frame would burn the CPU on + // frames no one can perceive, while drawing at ~30 fps keeps the catchup + // watchable. Render rate is not what bounds catchup (lockstep is, see + // ConnectionManager::updateRunAhead) and FrameMetrics stops sampling display + // FPS during catchup, which is what makes it safe to throttle here. The lead-in + // renders every frame for a realtime preview before control is handed back. + Bool catchupSkipRender = TheRecorder && TheRecorder->isResumeCatchupMode() + && !TheRecorder->isResumeCatchupLeadIn(); + if (catchupSkipRender) + { + const UnsignedInt CATCHUP_RENDER_INTERVAL_MS = 33; + static UnsignedInt s_lastCatchupRenderMs = 0; + const UnsignedInt nowMs = timeGetTime(); + if (nowMs - s_lastCatchupRenderMs >= CATCHUP_RENDER_INTERVAL_MS) + { + s_lastCatchupRenderMs = nowMs; + catchupSkipRender = FALSE; + } + } + { // VERIFY CRC needs to be in this code block. Please to not pull TheGameLogic->update() inside this block. VERIFY_CRC @@ -995,7 +1022,10 @@ void GameEngine::update() /// @todo Move audio init, update, etc, into GameClient update TheAudio->UPDATE(); - TheGameClient->UPDATE(); + if (catchupSkipRender) + TheParticleSystemManager->update(); // let particles finish instead of piling up while frames are skipped + else + TheGameClient->UPDATE(); TheMessageStream->propagateMessages(); if (TheNetwork != nullptr) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index c53ffced7dc..6afbbd45c5e 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -31,6 +31,10 @@ #include "Common/Player.h" #include "Common/GlobalData.h" #include "Common/GameEngine.h" +#include "Common/FramePacer.h" +#include "GameNetwork/LANAPI.h" +#include "GameNetwork/NetworkDefs.h" +#include "GameNetwork/NetworkInterface.h" #include "GameClient/ClientInstance.h" #include "GameClient/GameWindow.h" #include "GameClient/GameWindowManager.h" @@ -383,6 +387,14 @@ void RecorderClass::init() { m_doingAnalysis = FALSE; m_playbackFrameCount = 0; + m_resumeHandoffFrame = 0; + m_resumeSavedFpsLimit = 0; + m_resumeSavedNetFrameRate = 0; + m_resumeRecordPos = 0; + m_resumeRatesRestored = FALSE; + m_resumeFreezeStartMs = 0; + m_resumeFreezeLastAnnounced = -1; + OptionPreferences optionPref; m_archiveReplays = optionPref.getArchiveReplaysEnabled(); } @@ -405,7 +417,10 @@ void RecorderClass::reset() { * Do the update for this frame. */ void RecorderClass::update() { - if (m_mode == RECORDERMODETYPE_RECORD || m_mode == RECORDERMODETYPE_NONE) { + if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) { + updateResumeCatchup(); + } + else if (m_mode == RECORDERMODETYPE_RECORD || m_mode == RECORDERMODETYPE_NONE) { updateRecord(); } else if (isPlaybackMode()) { @@ -489,7 +504,22 @@ void RecorderClass::updateRecord() if (msg->getArgumentCount() >= 4) maxFPS = msg->getArgument(3)->integer; - startRecording(diff, m_originalGameMode, rankPoints, maxFPS); + // TheSuperHackers @feature bill-rich 15/09/2026 If the lobby armed a resume-from-replay, switch into + // catchup instead of starting a fresh recording: catchup opens the replay for + // READ, while startRecording would open it for WRITE and truncate the very + // file we need to read from. Falls back to a normal recording if setup fails. + const GameInfo *armedGame = TheGameInfo; + if (armedGame == nullptr && TheLAN != nullptr) + armedGame = TheLAN->GetMyGame(); + const Bool armedResume = armedGame != nullptr && !armedGame->getResumeReplayFile().isEmpty(); + if (armedResume && startResumeCatchup(armedGame->getResumeReplayFile(), armedGame->getResumeHandoffFrame())) + { + DEBUG_LOG(("RecorderClass::updateRecord() - resume catchup armed to frame %u", armedGame->getResumeHandoffFrame())); + } + else + { + startRecording(diff, m_originalGameMode, rankPoints, maxFPS); + } } else if (msg->getType() == GameMessage::MSG_CLEAR_GAME_DATA) { if (m_file != nullptr) { @@ -1736,6 +1766,255 @@ Bool RecorderClass::isMultiplayer() return false; } +//------------------------------------------------------------------------------------------------- +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay. See Recorder.h for the phase overview. +//------------------------------------------------------------------------------------------------- + +Bool RecorderClass::isResumeCatchupLeadIn() const +{ + if (!isResumeCatchupMode()) + return FALSE; + const UnsignedInt leadInFrames = RESUME_LEADIN_SECONDS * LOGICFRAMES_PER_SECOND; + const UnsignedInt curFrame = TheGameLogic ? TheGameLogic->getFrame() : 0; + return m_resumeHandoffFrame >= leadInFrames && curFrame >= m_resumeHandoffFrame - leadInFrames; +} + +static UnicodeString formatGameTime(UnsignedInt frames) +{ + const UnsignedInt seconds = frames / LOGICFRAMES_PER_SECOND; + UnicodeString text; + text.format(L"%d:%02d", seconds / 60, seconds % 60); + return text; +} + +/** + * Open the given replay, skip its header, prime the first frame of commands and switch the + * recorder into RECORDERMODETYPE_RESUME_CATCHUP. While in catchup, update() calls + * updateResumeCatchup() instead of updateRecord()/updatePlayback(): the replay's commands are + * injected into TheCommandList each frame while the live network keeps running in lockstep. + */ +Bool RecorderClass::startResumeCatchup(AsciiString filename, UnsignedInt handoffFrame) +{ + if (m_file != nullptr) + { + m_file->close(); + m_file = nullptr; + } + m_mode = RECORDERMODETYPE_NONE; + + ReplayHeader header; + header.forPlayback = TRUE; + header.filename = filename; + if (!readReplayHeader(header)) + { + DEBUG_LOG(("RecorderClass::startResumeCatchup - readReplayHeader failed for %s", filename.str())); + return FALSE; + } + + // playbackFile consumes these four values between the header and the command stream; + // mirror it or readNextFrame reads the difficulty as a frame number. + Int difficulty = 0; + m_file->read(&difficulty, sizeof(difficulty)); + m_file->read(&m_originalGameMode, sizeof(m_originalGameMode)); + Int rankPoints = 0; + m_file->read(&rankPoints, sizeof(rankPoints)); + Int maxFPS = 0; + m_file->read(&maxFPS, sizeof(maxFPS)); + + m_mode = RECORDERMODETYPE_RESUME_CATCHUP; + m_resumeHandoffFrame = handoffFrame; + m_currentReplayFilename = filename; + m_resumeRatesRestored = FALSE; + m_resumeFreezeStartMs = 0; + m_resumeFreezeLastAnnounced = -1; + + // Everything up to here is header. beginRecordingAfterResume keeps the file up to + // m_resumeRecordPos and appends the live game after it. + m_resumeRecordPos = m_file->position(); + + readNextFrame(); + + // Nothing may be selected when catchup starts: selection is blocked from here on and + // a pre-existing selection would be a way to issue commands with the right mouse button. + if (TheInGameUI) + { + TheInGameUI->deselectAllDrawables(); + TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCatchupStart", + L"Resuming from replay: fast-forwarding to %ls", formatGameTime(handoffFrame).str())); + } + + // Two gates cap the logic rate: the render FPS limit and the network's own per-frame + // timing (Network::timeForNewFrame). Raise both; lockstep is unchanged, every frame + // still waits for every peer's commands, just without the realtime pacing. + if (TheFramePacer) + { + m_resumeSavedFpsLimit = TheFramePacer->getFramesPerSecondLimit(); + if (m_resumeSavedFpsLimit <= 0) + m_resumeSavedFpsLimit = LOGICFRAMES_PER_SECOND; // never restore a 0, FrameRateLimit::wait would spin forever + TheFramePacer->setFramesPerSecondLimit(1000); + } + if (TheNetwork) + { + m_resumeSavedNetFrameRate = TheNetwork->setLogicFrameRate(CATCHUP_FRAME_RATE); + } + + DEBUG_LOG(("RecorderClass::startResumeCatchup - catching up %s to frame %u", filename.str(), handoffFrame)); + return TRUE; +} + +/** + * Hand the replay file over from catchup (reading) to recording (writing). The armed file already + * holds the header plus every frame up to the handoff, so keep those bytes and append the live + * game to them: one complete replay of the whole match, and stopRecording() runs at the end with + * everything that hangs off it. Truncates after the last record actually replayed so the old + * tail (already-played frames, the old MSG_CLEAR_GAME_DATA) cannot follow the new commands. + */ +Bool RecorderClass::beginRecordingAfterResume() +{ + if (m_file == nullptr || m_resumeRecordPos <= 0) + return FALSE; + + // Replays are command logs, so the prefix is small; buffer it rather than truncate in place. + const Int prefixLen = m_resumeRecordPos; + char *prefix = NEW char[prefixLen]; + m_file->seek(0, File::seekMode::START); + const Int got = m_file->read(prefix, prefixLen); + m_file->close(); + m_file = nullptr; + + if (got != prefixLen) + { + DEBUG_LOG(("RecorderClass::beginRecordingAfterResume - short read of replay prefix (%d of %d)", got, prefixLen)); + delete [] prefix; + return FALSE; + } + + AsciiString fileName = getLastReplayFileName(); + fileName.concat(getReplayExtention()); + + AsciiString filepath = getReplayDir(); + TheFileSystem->createDirectory(filepath); + filepath.concat(fileName); + + // WRITE truncates, which is the truncate-at-prefix we want. + m_file = TheFileSystem->openFile(filepath.str(), File::WRITE | File::BINARY); + if (m_file == nullptr) + { + DEBUG_LOG(("RecorderClass::beginRecordingAfterResume - could not reopen %s for recording", filepath.str())); + delete [] prefix; + return FALSE; + } + + m_file->write(prefix, prefixLen); + delete [] prefix; + m_file->flush(); + + m_fileName = fileName; + m_mode = RECORDERMODETYPE_RECORD; + DEBUG_LOG(("RecorderClass::beginRecordingAfterResume - recording resumed game into %s from offset %d", fileName.str(), prefixLen)); + return TRUE; +} + +/** + * Per-frame update for RECORDERMODETYPE_RESUME_CATCHUP: inject the replay's recorded commands + * for the current logic frame, drop the rate caps for the lead-in, and start the freeze when + * the handoff frame is reached (or the replay runs out first). Unlike stopPlayback this does NOT + * call exitGame; the network session continues uninterrupted. + */ +void RecorderClass::updateResumeCatchup() +{ + const UnsignedInt curFrame = TheGameLogic ? TheGameLogic->getFrame() : 0; + + // Lead-in: back to realtime so players get a normal-speed look at the last seconds + // before the handoff. If the handoff is closer than that to the start, stay fast. + if (!m_resumeRatesRestored && isResumeCatchupLeadIn()) + { + m_resumeRatesRestored = TRUE; + if (TheFramePacer) + TheFramePacer->setFramesPerSecondLimit(m_resumeSavedFpsLimit); + if (TheNetwork) + TheNetwork->setLogicFrameRate(m_resumeSavedNetFrameRate); + if (TheInGameUI) + TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCatchupLeadIn", + L"Catching up: the last %d seconds play at normal speed", RESUME_LEADIN_SECONDS)); + } + + // NOTE: cullBadCommands() is intentionally skipped here. It strips every command in + // the network range from TheCommandList, which is exactly what appendNextCommand adds, + // and the live network layer writes into the same list each frame. Local input is + // blocked at its sources instead (isResumeInputBlocked). + + // Inject every command recorded for this frame, including the handoff frame itself: + // GameLogic's CRC validation resumes right after catchup ends and expects the CRC + // messages of that frame to be present. + while (m_nextFrame == curFrame && curFrame <= m_resumeHandoffFrame) + { + appendNextCommand(); + m_resumeRecordPos = m_file->position(); + readNextFrame(); + } + + if (curFrame >= m_resumeHandoffFrame || m_nextFrame == (UnsignedInt)-1) + { + // Take the replay file over for recording rather than dropping it (see above). + if (!beginRecordingAfterResume()) + { + DEBUG_LOG(("RecorderClass::updateResumeCatchup - could not take over the replay file for recording")); + if (m_file != nullptr) + { + m_file->close(); + m_file = nullptr; + } + m_mode = RECORDERMODETYPE_NONE; + } + m_currentReplayFilename.clear(); + + // Restore both rate caps in case the lead-in never happened. + if (TheFramePacer) + TheFramePacer->setFramesPerSecondLimit(m_resumeSavedFpsLimit); + if (TheNetwork) + TheNetwork->setLogicFrameRate(m_resumeSavedNetFrameRate); + + // Hold the simulation with a countdown before control comes back. Network::update + // polls updateResumeFreeze() and refuses to advance frames while it returns TRUE. + m_resumeFreezeStartMs = timeGetTime(); + if (m_resumeFreezeStartMs == 0) + m_resumeFreezeStartMs = 1; + m_resumeFreezeLastAnnounced = -1; + DEBUG_LOG(("RecorderClass::updateResumeCatchup - handoff at frame %u, freezing for %d s", curFrame, RESUME_FREEZE_SECONDS)); + } +} + +/** + * Pumped from Network::update() every engine frame (GameLogic, and with it the recorder's own + * update, does not run while frames are held). Shows the countdown and ends the freeze. + */ +Bool RecorderClass::updateResumeFreeze() +{ + if (m_resumeFreezeStartMs == 0) + return FALSE; + + const UnsignedInt elapsedMs = timeGetTime() - m_resumeFreezeStartMs; + const Int remaining = RESUME_FREEZE_SECONDS - (Int)(elapsedMs / 1000); + if (remaining > 0) + { + if (remaining != m_resumeFreezeLastAnnounced && TheInGameUI) + { + m_resumeFreezeLastAnnounced = remaining; + TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCountdown", + L"Resuming in %d", remaining)); + } + return TRUE; + } + + m_resumeFreezeStartMs = 0; + m_resumeFreezeLastAnnounced = -1; + if (TheInGameUI) + TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHandoffComplete", L"Control handed back. Go!")); + DEBUG_LOG(("RecorderClass::updateResumeFreeze - freeze over, live play resumes")); + return FALSE; +} + /** * Create a new recorder object. */ diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index 53cda5a2a2e..cbb8ba0855c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -59,6 +59,9 @@ #include "Common/MultiplayerSettings.h" #include "GameClient/GameText.h" #include "GameNetwork/GUIUtil.h" +#include "Common/Recorder.h" +#include "Common/Version.h" +#include "GameClient/MapUtil.h" extern char *LANnextScreen; @@ -112,6 +115,7 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID; static NameKeyType buttonStartID = NAMEKEY_INVALID; static NameKeyType buttonEmoteID = NAMEKEY_INVALID; static NameKeyType buttonSelectMapID = NAMEKEY_INVALID; +static NameKeyType buttonResumeFromReplayID = NAMEKEY_INVALID; static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID; static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID; static NameKeyType windowMapID = NAMEKEY_INVALID; @@ -120,6 +124,7 @@ static GameWindow *parentLanGameOptions = nullptr; static GameWindow *buttonBack = nullptr; static GameWindow *buttonStart = nullptr; static GameWindow *buttonSelectMap = nullptr; +static GameWindow *buttonResumeFromReplay = nullptr; // optional: only present in updated .wnd layouts static GameWindow *buttonEmote = nullptr; static GameWindow *textEntryChat = nullptr; static GameWindow *textEntryMapDisplay = nullptr; @@ -668,6 +673,205 @@ void lanUpdateSlotList() //------------------------------------------------------------------------------------------------- /** Initialize the Gadgets Options Menu */ //------------------------------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming (host only). +// +// The host arms the last recorded replay (00000000.rep); every client in the +// lobby is expected to hold its own recording of that same match under the same +// name. Arming aligns the lobby with the replay (slot order, factions, colors, +// start spots, teams and the replay's seed) and broadcasts the replay name plus +// the handoff frame in the game options (RF= / RHF=). On game start the recorder +// on every client replays that file in lockstep up to the handoff frame before +// live control resumes (see RecorderClass::startResumeCatchup). +// ----------------------------------------------------------------------------- + +extern Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); + +// The handoff sits this far before the end of the recording, so a client whose +// recording stopped a little earlier (the one that crashed) still has every frame +// the others will replay. +static const Int RESUME_HANDOFF_SLACK_SECONDS = 10; + +static Bool s_resumeArmed = FALSE; +static UnsignedInt s_resumeArmedHandoffFrame = 0; + +static void lanSystemChat(const UnicodeString &text) +{ + if (TheLAN) + TheLAN->OnChat(L"SYSTEM", TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM); +} + +// Every human in the replay must be in the lobby under the same name, the host +// must be the replay's slot-0 player, and nobody extra may be present. +static Bool validateResumeRoster(const ReplayGameInfo &replayInfo, LANGameInfo *lobby, UnicodeString &statusOut) +{ + Int i; + Int replayCount = 0; + Int lobbyCount = 0; + for (i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replayInfo.getConstSlot(i); + if (rs && rs->isHuman()) + ++replayCount; + const GameSlot *ls = lobby->getConstSlot(i); + if (ls && ls->isHuman()) + ++lobbyCount; + } + if (replayCount != lobbyCount) + { + statusOut = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCountMismatch", + L"Resume: the lobby has %d players but the replay has %d", lobbyCount, replayCount); + return FALSE; + } + + const GameSlot *replayHost = replayInfo.getConstSlot(0); + const GameSlot *lobbyHost = lobby->getConstSlot(0); + if (!replayHost || !lobbyHost || !replayHost->isHuman() || replayHost->getName().compare(lobbyHost->getName()) != 0) + { + statusOut = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeHostMismatch", + L"Resume: only %ls, the host of the recorded game, can resume it", replayHost ? replayHost->getName().str() : L"?"); + return FALSE; + } + + for (i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replayInfo.getConstSlot(i); + if (!rs || !rs->isHuman()) + continue; + Bool found = FALSE; + for (Int j = 0; j < MAX_SLOTS && !found; ++j) + { + const GameSlot *ls = lobby->getConstSlot(j); + found = ls && ls->isHuman() && ls->getName().compare(rs->getName()) == 0; + } + if (!found) + { + statusOut = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMissingPlayer", + L"Resume: %ls is not in the lobby", rs->getName().str()); + return FALSE; + } + } + return TRUE; +} + +// Put every human back into the slot they held in the replay and restore the +// recorded faction, color, start position and team. Recorded commands are indexed +// by slot position, so the lobby must line up with the recording exactly. Slot 0 is +// never swapped: the LAN protocol treats it as the host's slot and validation has +// already checked the host matches. Non-human slots are left alone: setState() has +// destructive side effects on LAN slot identity. +static void reorderLobbyForResume(const ReplayGameInfo &replayInfo, LANGameInfo *lobby) +{ + Int i; + for (i = 1; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replayInfo.getConstSlot(i); + if (!rs || !rs->isHuman()) + continue; + Int currentIdx = -1; + for (Int j = 1; j < MAX_SLOTS; ++j) + { + const GameSlot *ls = lobby->getConstSlot(j); + if (ls && ls->isHuman() && ls->getName().compare(rs->getName()) == 0) + { + currentIdx = j; + break; + } + } + if (currentIdx < 0 || currentIdx == i) + continue; + LANGameSlot saved = *lobby->getLANSlot(i); + lobby->setSlot(i, *lobby->getLANSlot(currentIdx)); + lobby->setSlot(currentIdx, saved); + } + for (i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replayInfo.getConstSlot(i); + LANGameSlot *ls = lobby->getLANSlot(i); + if (!rs || !rs->isHuman() || !ls || !ls->isHuman()) + continue; + ls->setColor(rs->getColor()); + ls->setPlayerTemplate(rs->getPlayerTemplate()); + ls->setStartPos(rs->getStartPos()); + ls->setTeamNumber(rs->getTeamNumber()); + } +} + +static void clearResumeArm() +{ + s_resumeArmed = FALSE; + s_resumeArmedHandoffFrame = 0; + if (TheLAN && TheLAN->GetMyGame()) + { + TheLAN->GetMyGame()->setResumeReplayFile(AsciiString::TheEmptyString); + TheLAN->GetMyGame()->setResumeHandoffFrame(0); + } +} + +// Validates the last recorded replay against the current lobby and arms it. +// Reports success or the reason for refusal in the lobby chat. +static void tryArmResumeFromReplay() +{ + if (!TheLAN || !TheLAN->GetMyGame() || !TheLAN->AmIHost()) + return; + + AsciiString replayName = TheRecorder->getLastReplayFileName(); + replayName.concat(TheRecorder->getReplayExtention()); + + RecorderClass::ReplayHeader header; + ReplayGameInfo info; + const MapMetaData *mapData = nullptr; + if (!readReplayMapInfo(replayName, header, info, mapData)) + { + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read")); + return; + } + if (header.versionNumber != TheVersion->getVersionNumber() + || header.exeCRC != TheGlobalData->m_exeCRC + || header.iniCRC != TheGlobalData->m_iniCRC) + { + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"Resume: the last replay was recorded with a different game version")); + return; + } + const UnsignedInt slackFrames = RESUME_HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; + if (header.frameCount <= slackFrames) + { + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"Resume: the last replay is too short to resume")); + return; + } + if (mapData == nullptr) + { + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMapMissing", L"Resume: the replay's map is not installed")); + return; + } + UnicodeString status; + if (!validateResumeRoster(info, TheLAN->GetMyGame(), status)) + { + lanSystemChat(status); + return; + } + + LANGameInfo *game = TheLAN->GetMyGame(); + reorderLobbyForResume(info, game); + game->setMap(info.getMap()); + game->setMapCRC(info.getMapCRC()); + game->setMapSize(info.getMapSize()); + game->setSeed(info.getSeed()); + game->setResumeReplayFile(replayName); + game->setResumeHandoffFrame(header.frameCount - slackFrames); + TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); + lanUpdateSlotList(); + + s_resumeArmed = TRUE; + s_resumeArmedHandoffFrame = header.frameCount - slackFrames; + + UnicodeString armed = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", + L"Resume armed: the next start replays %hs to %d:%02d, then hands control back", + replayName.str(), (s_resumeArmedHandoffFrame / LOGICFRAMES_PER_SECOND) / 60, (s_resumeArmedHandoffFrame / LOGICFRAMES_PER_SECOND) % 60); + TheLAN->RequestChat(armed, LANAPIInterface::LANCHAT_SYSTEM); +} + void InitLanGameGadgets() { //Initialize the gadget IDs @@ -679,6 +883,7 @@ void InitLanGameGadgets() listboxChatWindowLanGameID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ListboxChatWindowLanGame" ); buttonEmoteID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonEmote" ); buttonSelectMapID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonSelectMap" ); + buttonResumeFromReplayID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonResumeFromReplay" ); checkboxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:CheckboxLimitSuperweapons" ); comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ComboBoxStartingCash" ); windowMapID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:MapWindow" ); @@ -689,6 +894,9 @@ void InitLanGameGadgets() buttonEmote = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonEmoteID ); DEBUG_ASSERTCRASH(buttonEmote, ("Could not find the buttonEmote")); buttonSelectMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonSelectMapID ); + buttonResumeFromReplay = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonResumeFromReplayID ); // may be null + if (buttonResumeFromReplay) + buttonResumeFromReplay->winEnable( TheLAN && TheLAN->AmIHost() ); DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap")); buttonStart = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonStartID ); DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart")); @@ -790,6 +998,9 @@ void InitLanGameGadgets() void DeinitLanGameGadgets() { + // Disarm any pending resume so it cannot survive into a future lobby session. + clearResumeArm(); + buttonResumeFromReplay = nullptr; parentLanGameOptions = nullptr; buttonEmote = nullptr; buttonSelectMap = nullptr; @@ -1257,6 +1468,10 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m mapSelectLayout->bringForward(); } + else if ( controlID == buttonResumeFromReplayID ) + { + tryArmResumeFromReplay(); + } else if ( controlID == buttonStartID ) { if (TheLAN->AmIHost()) @@ -1381,6 +1596,15 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m txtInput.trim(); // Echo the user's input to the chat window if (!txtInput.isEmpty()) + // "/resume" arms resume-from-replay without needing a button in the layout + if (txtInput.compareNoCase(L"/resume") == 0) + { + if (TheLAN->AmIHost()) + tryArmResumeFromReplay(); + else + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHostOnly", L"Only the host can resume a game")); + } + else TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp index 4188d26ba91..60bfdc9e768 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp @@ -105,7 +105,8 @@ UnicodeString GetReplayFilenameFromListbox(GameWindow *listbox, Int index) //------------------------------------------------------------------------------------------------- -static Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData) +// TheSuperHackers @refactor bill-rich 15/09/2026 No longer static: the LAN lobby's resume-from-replay arming reads replay headers too. +Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData) { header.forPlayback = FALSE; header.filename = filename; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp index b833f4c59d1..629a9b734c3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp @@ -3292,7 +3292,7 @@ Coord2D InGameUI::getScrollAmount() //------------------------------------------------------------------------------------------------- void InGameUI::setGUICommand(const CommandButton* command) { - if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK) + if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK || TheRecorder->isResumeInputBlocked()) return; // sanity diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 1fa00d1b2e6..b0ce329ad51 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -2780,7 +2780,13 @@ void GameLogic::processCommandList(CommandList* list) logicMessageDispatcher(msg, NULL); } - if (m_shouldValidateCRCs && !TheNetwork->sawCRCMismatch()) + // TheSuperHackers @feature bill-rich 15/09/2026 Skip CRC validation while in resume-from-replay + // catchup: the CRC messages of that window come out of every client's own copy + // of the replay, not from the live peers. Validation resumes at handoff when + // the recorder leaves catchup mode. + const Bool inCatchup = (TheRecorder && TheRecorder->isResumeCatchupMode()); + + if (m_shouldValidateCRCs && !TheNetwork->sawCRCMismatch() && !inCatchup) { Bool sawCRCMismatch = FALSE; Int numPlayers = 0; From c8b64aec18c6a4422d2a660f332c48872e10824d Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Tue, 15 Sep 2026 10:35:05 -0700 Subject: [PATCH 05/15] feat(resume): Arm resume-from-replay in online lobbies The host types /resume in the online lobby chat to arm the last recorded replay (or /resume off to disarm). The replay is validated against the current game version and the lobby: the map must match and every human must already sit in the slot they held in the replay, since the service owns slot order; the host is told the first difference. The recorded faction, color, start position and team are restored through the bulk slot update and the replay's seed, file name and handoff frame are sent with the new HOST_ACTION_ARM_RESUME lobby field, which the companion Services change stores and serializes as ResumeReplayFile and ResumeHandoffFrame. Depends on the Random button branch for the bulk slot update. --- .../OnlineServices_LobbyInterface.h | 5 + .../GameEngine/Source/Common/Recorder.cpp | 14 +- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 127 +++++++++++++++++- .../GameNetwork/GeneralsOnline/NGMPGame.cpp | 4 + .../OnlineServices_LobbyInterface.cpp | 40 +++++- 5 files changed, 186 insertions(+), 4 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index 0f4a9eab5b8..8491d5cb5d8 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -72,6 +72,10 @@ struct LobbyEntry int rng_seed = -1; + // resume-from-replay arming (empty when not armed); see NGMPGame::setResumeReplayFile + std::string resume_replay_file; + uint32_t resume_handoff_frame = 0; + bool passworded = false; std::string password; @@ -227,6 +231,7 @@ class NGMP_OnlineServices_LobbyInterface void UpdateCurrentLobby_AIStartPos(int slot, int startpos); void UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game); + void UpdateCurrentLobby_ArmResume(const std::string& replayFile, uint32_t handoffFrame, int rngSeed); ///< empty file disarms void UpdateCurrentLobbyMaxCameraHeight(uint16_t maxCameraHeight); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index 6afbbd45c5e..dfb7ba56b75 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -35,6 +35,10 @@ #include "GameNetwork/LANAPI.h" #include "GameNetwork/NetworkDefs.h" #include "GameNetwork/NetworkInterface.h" +#if defined(GENERALS_ONLINE) +#include "GameNetwork/GeneralsOnline/NGMPGame.h" +extern NGMPGame* TheNGMPGame; +#endif #include "GameClient/ClientInstance.h" #include "GameClient/GameWindow.h" #include "GameClient/GameWindowManager.h" @@ -508,9 +512,15 @@ void RecorderClass::updateRecord() // catchup instead of starting a fresh recording: catchup opens the replay for // READ, while startRecording would open it for WRITE and truncate the very // file we need to read from. Falls back to a normal recording if setup fails. - const GameInfo *armedGame = TheGameInfo; - if (armedGame == nullptr && TheLAN != nullptr) + const GameInfo *armedGame = nullptr; + if (TheLAN != nullptr) armedGame = TheLAN->GetMyGame(); +#if defined(GENERALS_ONLINE) + else if (TheNGMPGame != nullptr) + armedGame = TheNGMPGame; +#endif + if (armedGame == nullptr) + armedGame = TheGameInfo; const Bool armedResume = armedGame != nullptr && !armedGame->getResumeReplayFile().isEmpty(); if (armedResume && startResumeCatchup(armedGame->getResumeReplayFile(), armedGame->getResumeHandoffFrame())) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index d8c0b2c2eba..9d67981bbdd 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -53,6 +53,8 @@ #include "GameClient/GadgetStaticText.h" #include "GameClient/GadgetCheckBox.h" #include "GameClient/MapUtil.h" +#include "Common/Recorder.h" +#include "Common/Version.h" #include "GameClient/EstablishConnectionsMenu.h" #include "GameClient/GameWindowTransitions.h" #include "GameNetwork/GameSpy/LobbyUtils.h" @@ -1596,6 +1598,124 @@ void WOLDisplaySlotList(void) //------------------------------------------------------------------------------------------------- /** Initialize the Gadgets Options Menu */ //------------------------------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming for online lobbies (host only). +// +// Same contract as the LAN lobby (LanGameOptionsMenu.cpp): the host arms the last +// recorded replay, every member is expected to hold their own recording of that +// match, and on game start the recorder replays it in lockstep up to the handoff +// frame before live control resumes. Online the slot order is owned by the +// service, so the lobby must already match the replay's slot order; the host is +// told exactly what differs instead of the lobby being reordered. +// ----------------------------------------------------------------------------- + +extern Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); + +static const Int WOL_RESUME_HANDOFF_SLACK_SECONDS = 10; + +static void wolLocalSystemChat(const UnicodeString &text) +{ + if (listboxGameSetupChat) + GadgetListBoxAddEntryText(listboxGameSetupChat, text, GameSpyColor[GSCOLOR_DEFAULT], -1, -1); +} + +static void wolTryArmResumeFromReplay(Bool disarm) +{ + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + if (pLobbyInterface == nullptr || pLobbyInterface->GetCurrentGame() == nullptr) + return; + if (!pLobbyInterface->IsHost()) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHostOnly", L"Only the host can resume a game")); + return; + } + NGMPGame *game = pLobbyInterface->GetCurrentGame(); + + if (disarm) + { + pLobbyInterface->UpdateCurrentLobby_ArmResume(std::string(), 0, game->getSeed()); + UnicodeString msg = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game"); + pLobbyInterface->SendAnnouncementMessageToCurrentLobby(msg, true); + return; + } + + AsciiString replayName = TheRecorder->getLastReplayFileName(); + replayName.concat(TheRecorder->getReplayExtention()); + + RecorderClass::ReplayHeader header; + ReplayGameInfo info; + const MapMetaData *mapData = nullptr; + if (!readReplayMapInfo(replayName, header, info, mapData)) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read")); + return; + } + if (header.versionNumber != TheVersion->getVersionNumber() + || header.exeCRC != TheGlobalData->m_exeCRC + || header.iniCRC != TheGlobalData->m_iniCRC) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"Resume: the last replay was recorded with a different game version")); + return; + } + const UnsignedInt slackFrames = WOL_RESUME_HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; + if (header.frameCount <= slackFrames) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"Resume: the last replay is too short to resume")); + return; + } + if (mapData == nullptr || game->getMap().compareNoCase(info.getMap()) != 0) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMapMismatch", + L"Resume: select the replay's map first (%hs)", info.getMap().str())); + return; + } + + // Every human must sit in the slot they held in the replay; slot order is the + // service's, so report the first difference instead of reordering. + for (Int i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = info.getConstSlot(i); + const GameSlot *ls = game->getConstSlot(i); + const Bool replayHuman = rs && rs->isHuman(); + const Bool lobbyHuman = ls && ls->isHuman(); + if (replayHuman != lobbyHuman || (replayHuman && rs->getName().compare(ls->getName()) != 0)) + { + UnicodeString msg; + if (replayHuman) + msg = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", + L"Resume: slot %d must be %ls (it was theirs in the replay)", i + 1, rs->getName().str()); + else + msg = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", + L"Resume: slot %d was not a player in the replay, close it or move %ls", i + 1, ls->getName().str()); + wolLocalSystemChat(msg); + return; + } + } + + // Restore the recorded faction, color, start position and team on every human + // slot, then arm. The service takes the replay's seed as the lobby seed. + for (Int i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = info.getConstSlot(i); + GameSlot *ls = game->getSlot(i); + if (!rs || !rs->isHuman() || !ls || !ls->isHuman()) + continue; + ls->setColor(rs->getColor()); + ls->setPlayerTemplate(rs->getPlayerTemplate()); + ls->setStartPos(rs->getStartPos()); + ls->setTeamNumber(rs->getTeamNumber()); + } + pLobbyInterface->UpdateCurrentLobby_BulkSlotUpdate(game); + const UnsignedInt handoff = header.frameCount - slackFrames; + pLobbyInterface->UpdateCurrentLobby_ArmResume(std::string(replayName.str()), handoff, info.getSeed()); + WOLDisplaySlotList(); + + UnicodeString armed = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", + L"Resume armed: the next start replays %hs to %d:%02d, then hands control back", + replayName.str(), (handoff / LOGICFRAMES_PER_SECOND) / 60, (handoff / LOGICFRAMES_PER_SECOND) % 60); + pLobbyInterface->SendAnnouncementMessageToCurrentLobby(armed, true); +} + void InitWOLGameGadgets() { ClearGSMessageBoxes(); @@ -4124,7 +4244,12 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg if (!txtInput.isEmpty()) { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); - if (pLobbyInterface != nullptr) + if (txtInput.compareNoCase(L"/resume") == 0 || txtInput.compareNoCase(L"/resume off") == 0) + { + // resume-from-replay arming lives behind a chat command so no layout change is needed + wolTryArmResumeFromReplay(txtInput.compareNoCase(L"/resume off") == 0); + } + else if (pLobbyInterface != nullptr) { pLobbyInterface->SendChatMessageToCurrentLobby(txtInput, false); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index 62f7b703cba..fe74aefbc6b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -115,6 +115,10 @@ void NGMPGame::SyncWithLobby(LobbyEntry& lobby) // rng seed setSeed(lobby.rng_seed); + // resume-from-replay arming (see RecorderClass::startResumeCatchup) + setResumeReplayFile(AsciiString(lobby.resume_replay_file.c_str())); + setResumeHandoffFrame(lobby.resume_handoff_frame); + // observers setAllowObservers(lobby.allow_observers); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index 00ce8d51bc7..db69b5c32b9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -75,7 +75,8 @@ enum class ELobbyUpdateField AI_START_POS = 16, MAX_CAMERA_HEIGHT = 17, JOINABILITY = 18, - HOST_ACTION_BULK_SLOT_UPDATE = 19 + HOST_ACTION_BULK_SLOT_UPDATE = 19, + HOST_ACTION_ARM_RESUME = 20 }; void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers) @@ -536,6 +537,38 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_BulkSlotUpdate(NGMPG }); } +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: arm (or, with an empty file, disarm) the +// replay every member holds a copy of. The service stores the file name and handoff +// frame on the lobby and takes the replay's seed as the lobby seed, so the next start +// replays that file in lockstep before live control resumes. +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ArmResume(const std::string& replayFile, uint32_t handoffFrame, int rngSeed) +{ + // reset autostart if host changes anything (because ready flag will reset too) +#if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) + ClearAutoReadyCountdown(); +#endif + if (TheNGMPGame && TheNGMPGame->IsCountdownStarted()) + TheNGMPGame->StopCountdown(); + + std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), m_CurrentLobby.lobbyID); + std::map mapHeaders; + + nlohmann::json j; + j["field"] = ELobbyUpdateField::HOST_ACTION_ARM_RESUME; + j["replay_file"] = replayFile; + j["handoff_frame"] = handoffFrame; + j["rng_seed"] = rngSeed; + std::string strPostData = j.dump(); + + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + { + if (!bSuccess || statusCode < 200 || statusCode >= 300) + { + DEBUG_LOG(("UpdateCurrentLobby_ArmResume failed: success=%d, status=%d", bSuccess, statusCode)); + } + }); +} + void NGMP_OnlineServices_LobbyInterface::SendChatMessageToCurrentLobby(UnicodeString& strChatMsgUnicode, bool bIsAction) { std::shared_ptr pWS = NGMP_OnlineServicesManager::GetWebSocket();; @@ -964,6 +997,11 @@ void NGMP_OnlineServices_LobbyInterface::UpdateRoomDataCache(std::function Date: Tue, 15 Sep 2026 11:06:43 -0700 Subject: [PATCH 06/15] fix(resume): Survive short recordings and log the resume milestones Running out of recorded frames during catch-up now ends the catch-up instead of the live game (readNextFrame no longer calls stopPlayback in that mode). Arming falls back to walking the replay's records for its last frame when the header count is 0, which is the case for every recording cut short by a crash, using the recorder's analysis mode. The catch-up start, lead-in, handoff, countdown ticks and handoff completion are written to the GeneralsOnline release log. Verified in a two-client LAN run under wine: both clients caught up 4500 frames in 6 seconds, played the 10 second lead-in, showed the same 10 second countdown and resumed live play on the same frame with the replay files continuing to record. --- .../Code/GameEngine/Include/Common/Recorder.h | 1 + .../GameEngine/Source/Common/Recorder.cpp | 65 ++++++++++++++++++- .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 10 ++- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 8 ++- 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h index 6fe38ce855a..14afd077976 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h @@ -159,6 +159,7 @@ class RecorderClass : public SubsystemInterface Bool startResumeCatchup(AsciiString filename, UnsignedInt handoffFrame); void updateResumeCatchup(); Bool beginRecordingAfterResume(); ///< take the replay file over for recording so the resumed match is a complete replay + UnsignedInt scanReplayLastFrame(AsciiString filename); ///< last frame number in a replay; walks the records, for recordings whose header was never finalized (crash) void initControls(); ///< Show or Hide the Replay controls static AsciiString getReplayDir(); ///< Returns the directory that holds the replay files. diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index dfb7ba56b75..ddecc7cdefc 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -37,7 +37,11 @@ #include "GameNetwork/NetworkInterface.h" #if defined(GENERALS_ONLINE) #include "GameNetwork/GeneralsOnline/NGMPGame.h" +#include "GameNetwork/GeneralsOnline/NGMP_include.h" extern NGMPGame* TheNGMPGame; +#define RESUME_LOG(...) NetworkLog(ELogVerbosity::LOG_RELEASE, __VA_ARGS__) +#else +#define RESUME_LOG(...) DEBUG_LOG((__VA_ARGS__)) #endif #include "GameClient/ClientInstance.h" #include "GameClient/GameWindow.h" @@ -1347,6 +1351,10 @@ void RecorderClass::readNextFrame() { if (bytesRead != sizeof(m_nextFrame)) { DEBUG_LOG(("RecorderClass::readNextFrame - read failed on frame %d", TheGameLogic->getFrame())); m_nextFrame = -1; + // Resume-from-replay catchup: running out of recorded frames ends the catchup + // (updateResumeCatchup hands off early), never the live game. + if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) + return; stopPlayback(); } } @@ -1868,10 +1876,59 @@ Bool RecorderClass::startResumeCatchup(AsciiString filename, UnsignedInt handoff m_resumeSavedNetFrameRate = TheNetwork->setLogicFrameRate(CATCHUP_FRAME_RATE); } - DEBUG_LOG(("RecorderClass::startResumeCatchup - catching up %s to frame %u", filename.str(), handoffFrame)); + RESUME_LOG("Resume: catching up %s to frame %u (lead-in %d s, freeze %d s)", filename.str(), handoffFrame, RESUME_LEADIN_SECONDS, RESUME_FREEZE_SECONDS); return TRUE; } +/** + * Last frame number recorded in a replay, found by walking its records. The header's frame + * count is only patched in when a recording ends normally, so a recording cut short by a crash + * (the very file a resume is for) reads 0 there. Uses the recorder's analysis mode, in which + * appendNextCommand parses and discards instead of feeding TheCommandList. Lobby use only: + * refuses to run while the recorder has a file open. + */ +UnsignedInt RecorderClass::scanReplayLastFrame(AsciiString filename) +{ + if (m_file != nullptr || m_mode != RECORDERMODETYPE_NONE) + return 0; + + ReplayHeader header; + header.forPlayback = TRUE; + header.filename = filename; + if (!readReplayHeader(header)) + return 0; + + // difficulty, original game mode, rank points, max FPS (see playbackFile) + Int skipped[4]; + m_file->read(skipped, sizeof(skipped)); + + const Bool savedAnalysis = m_doingAnalysis; + m_doingAnalysis = TRUE; + + UnsignedInt lastFrame = 0; + UnsignedInt frame = 0; + while (m_file != nullptr && m_file->read(&frame, sizeof(frame)) == sizeof(frame)) + { + if (frame < lastFrame) + break; // torn tail: frame numbers only ever grow + lastFrame = frame; + const Int before = m_file->position(); + appendNextCommand(); + if (m_file == nullptr || m_file->position() == before) + break; // nothing more could be read + } + + if (m_file != nullptr) + { + m_file->close(); + m_file = nullptr; + } + m_doingAnalysis = savedAnalysis; + m_nextFrame = (UnsignedInt)-1; + m_mode = RECORDERMODETYPE_NONE; + return lastFrame; +} + /** * Hand the replay file over from catchup (reading) to recording (writing). The armed file already * holds the header plus every frame up to the handoff, so keep those bytes and append the live @@ -1944,6 +2001,7 @@ void RecorderClass::updateResumeCatchup() TheFramePacer->setFramesPerSecondLimit(m_resumeSavedFpsLimit); if (TheNetwork) TheNetwork->setLogicFrameRate(m_resumeSavedNetFrameRate); + RESUME_LOG("Resume: lead-in reached at frame %u, back to realtime", curFrame); if (TheInGameUI) TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCatchupLeadIn", L"Catching up: the last %d seconds play at normal speed", RESUME_LEADIN_SECONDS)); @@ -1991,7 +2049,7 @@ void RecorderClass::updateResumeCatchup() if (m_resumeFreezeStartMs == 0) m_resumeFreezeStartMs = 1; m_resumeFreezeLastAnnounced = -1; - DEBUG_LOG(("RecorderClass::updateResumeCatchup - handoff at frame %u, freezing for %d s", curFrame, RESUME_FREEZE_SECONDS)); + RESUME_LOG("Resume: handoff at frame %u (next replay frame %u), freezing for %d s", curFrame, m_nextFrame, RESUME_FREEZE_SECONDS); } } @@ -2011,6 +2069,7 @@ Bool RecorderClass::updateResumeFreeze() if (remaining != m_resumeFreezeLastAnnounced && TheInGameUI) { m_resumeFreezeLastAnnounced = remaining; + RESUME_LOG("Resume: countdown %d", remaining); TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCountdown", L"Resuming in %d", remaining)); } @@ -2021,7 +2080,7 @@ Bool RecorderClass::updateResumeFreeze() m_resumeFreezeLastAnnounced = -1; if (TheInGameUI) TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHandoffComplete", L"Control handed back. Go!")); - DEBUG_LOG(("RecorderClass::updateResumeFreeze - freeze over, live play resumes")); + RESUME_LOG("Resume: freeze over at frame %u, live play resumes", TheGameLogic ? TheGameLogic->getFrame() : 0); return FALSE; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index cbb8ba0855c..040e272d413 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -834,8 +834,12 @@ static void tryArmResumeFromReplay() lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"Resume: the last replay was recorded with a different game version")); return; } + // A recording cut short by a crash never had its header frame count patched in. + UnsignedInt frameCount = header.frameCount; + if (frameCount == 0) + frameCount = TheRecorder->scanReplayLastFrame(replayName); const UnsignedInt slackFrames = RESUME_HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; - if (header.frameCount <= slackFrames) + if (frameCount <= slackFrames) { lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"Resume: the last replay is too short to resume")); return; @@ -859,12 +863,12 @@ static void tryArmResumeFromReplay() game->setMapSize(info.getMapSize()); game->setSeed(info.getSeed()); game->setResumeReplayFile(replayName); - game->setResumeHandoffFrame(header.frameCount - slackFrames); + game->setResumeHandoffFrame(frameCount - slackFrames); TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); lanUpdateSlotList(); s_resumeArmed = TRUE; - s_resumeArmedHandoffFrame = header.frameCount - slackFrames; + s_resumeArmedHandoffFrame = frameCount - slackFrames; UnicodeString armed = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", L"Resume armed: the next start replays %hs to %d:%02d, then hands control back", diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index 9d67981bbdd..d63265bc62f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -1657,8 +1657,12 @@ static void wolTryArmResumeFromReplay(Bool disarm) wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"Resume: the last replay was recorded with a different game version")); return; } + // A recording cut short by a crash never had its header frame count patched in. + UnsignedInt frameCount = header.frameCount; + if (frameCount == 0) + frameCount = TheRecorder->scanReplayLastFrame(replayName); const UnsignedInt slackFrames = WOL_RESUME_HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; - if (header.frameCount <= slackFrames) + if (frameCount <= slackFrames) { wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"Resume: the last replay is too short to resume")); return; @@ -1706,7 +1710,7 @@ static void wolTryArmResumeFromReplay(Bool disarm) ls->setTeamNumber(rs->getTeamNumber()); } pLobbyInterface->UpdateCurrentLobby_BulkSlotUpdate(game); - const UnsignedInt handoff = header.frameCount - slackFrames; + const UnsignedInt handoff = frameCount - slackFrames; pLobbyInterface->UpdateCurrentLobby_ArmResume(std::string(replayName.str()), handoff, info.getSeed()); WOLDisplaySlotList(); From ce974065e2e65f49701a059d50c7882b15edd19b Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Tue, 15 Sep 2026 12:15:53 -0700 Subject: [PATCH 07/15] feat(resume): Refuse to start an armed resume the lobby no longer matches Roster problems are now announced to the whole lobby instead of only the host, since the player who has to fix a name or a slot is usually not the host. When a resume is armed, the host's start re-reads the recording and refuses to start if any recorded player is missing from their slot or a stranger sits in one, telling the lobby which slot must hold whom and how to disarm. LAN gets /resume off to disarm. Verified with three clients under wine: a renamed player blocks arming with a lobby-wide message, and a player who leaves and rejoins under another name after arming blocks the start with the offending slot named on every client. The three-player resume itself restored the recorded slot order, factions and colors after the joiners came back in a different order with different preferences. --- .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 78 +++++++++++++++-- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 84 +++++++++++++++---- 2 files changed, 139 insertions(+), 23 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index 040e272d413..7e296749cbc 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -223,6 +223,8 @@ static void playerTooltip(GameWindow *window, setLANPlayerTooltip(player); } +extern Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); +static Bool armedResumeStillMatches(LANGameInfo *game); void StartPressed() { LANGameInfo *myGame = TheLAN->GetMyGame(); @@ -264,6 +266,12 @@ void StartPressed() return; } + // An armed resume only works if the lobby still matches the recording. + if (TheLAN->AmIHost() && !myGame->getResumeReplayFile().isEmpty() && !armedResumeStillMatches(myGame)) + { + return; + } + // Check for observer + AI players if (TheGlobalData->m_netMinPlayers && !numHumans) { @@ -696,10 +704,54 @@ static const Int RESUME_HANDOFF_SLACK_SECONDS = 10; static Bool s_resumeArmed = FALSE; static UnsignedInt s_resumeArmedHandoffFrame = 0; +// Everyone in the lobby sees resume messages: the player who has to fix +// something (wrong name, wrong slot) is usually not the host. static void lanSystemChat(const UnicodeString &text) { if (TheLAN) - TheLAN->OnChat(L"SYSTEM", TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM); + TheLAN->RequestChat(text, LANAPIInterface::LANCHAT_SYSTEM); +} + +// The lobby must line up with the recording slot for slot: every recorded human in +// the slot they held, under the same name, and nobody else in a recorded slot. +static Bool lobbySlotsMatchReplay(const ReplayGameInfo &replayInfo, const GameInfo *lobby, UnicodeString &why) +{ + for (Int i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replayInfo.getConstSlot(i); + const GameSlot *ls = lobby->getConstSlot(i); + const Bool replayHuman = rs && rs->isHuman(); + const Bool lobbyHuman = ls && ls->isHuman(); + if (replayHuman == lobbyHuman && (!replayHuman || rs->getName().compare(ls->getName()) == 0)) + continue; + if (replayHuman) + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", + L"Resume: slot %d must be %ls (it was theirs in the recording)", i + 1, rs->getName().str()); + else + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", + L"Resume: slot %d was not a player in the recording, close it or move %ls", i + 1, ls->getName().str()); + return FALSE; + } + return TRUE; +} + +// Called from StartPressed while a resume is armed. Re-reads the recording and refuses +// the start when the lobby has drifted from it since arming (someone left, rejoined +// under another name, or joined into a recorded slot). +static Bool armedResumeStillMatches(LANGameInfo *game) +{ + RecorderClass::ReplayHeader header; + ReplayGameInfo info; + const MapMetaData *mapData = nullptr; + UnicodeString why; + if (!readReplayMapInfo(game->getResumeReplayFile(), header, info, mapData)) + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read"); + else if (lobbySlotsMatchReplay(info, game, why)) + return TRUE; + lanSystemChat(why); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeStartRefused", + L"Resume is armed and the lobby no longer matches the recording. Fix it, or type /resume off to start a fresh game.")); + return FALSE; } // Every human in the replay must be in the lobby under the same name, the host @@ -809,6 +861,20 @@ static void clearResumeArm() } } +// "/resume off": disarm and tell the lobby the next start is a fresh game. +static void disarmResumeFromReplay() +{ + if (!TheLAN || !TheLAN->GetMyGame() || !TheLAN->AmIHost()) + return; + const Bool wasArmed = !TheLAN->GetMyGame()->getResumeReplayFile().isEmpty(); + clearResumeArm(); + if (wasArmed) + { + TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); + } +} + // Validates the last recorded replay against the current lobby and arms it. // Reports success or the reason for refusal in the lobby chat. static void tryArmResumeFromReplay() @@ -1601,12 +1667,14 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m // Echo the user's input to the chat window if (!txtInput.isEmpty()) // "/resume" arms resume-from-replay without needing a button in the layout - if (txtInput.compareNoCase(L"/resume") == 0) + if (txtInput.compareNoCase(L"/resume") == 0 || txtInput.compareNoCase(L"/resume off") == 0) { - if (TheLAN->AmIHost()) - tryArmResumeFromReplay(); + if (!TheLAN->AmIHost()) + TheLAN->OnChat(L"SYSTEM", TheLAN->GetLocalIP(), TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHostOnly", L"Only the host can resume a game"), LANAPI::LANCHAT_SYSTEM); + else if (txtInput.compareNoCase(L"/resume off") == 0) + disarmResumeFromReplay(); else - lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHostOnly", L"Only the host can resume a game")); + tryArmResumeFromReplay(); } else TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index d63265bc62f..c27907d9498 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -979,8 +979,16 @@ static void WOLLockSettings() } } +static Bool wolArmedResumeStillMatches(NGMPGame *game); static void StartPressed() { + // An armed resume only works if the lobby still matches the recording. + { + NGMP_OnlineServices_LobbyInterface* pResumeLobby = NGMP_OnlineServicesManager::GetInterface(); + NGMPGame *resumeGame = pResumeLobby ? pResumeLobby->GetCurrentGame() : nullptr; + if (resumeGame != nullptr && !resumeGame->getResumeReplayFile().isEmpty() && !wolArmedResumeStillMatches(resumeGame)) + return; + } Bool isReady = TRUE; Bool allHaveMap = TRUE; Int playerCount = 0; @@ -1619,6 +1627,59 @@ static void wolLocalSystemChat(const UnicodeString &text) GadgetListBoxAddEntryText(listboxGameSetupChat, text, GameSpyColor[GSCOLOR_DEFAULT], -1, -1); } +// Roster problems go to the whole lobby: the player who has to fix something is +// usually not the host. +static void wolLobbySystemChat(const UnicodeString &text) +{ + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + UnicodeString msg = text; + if (pLobbyInterface != nullptr) + pLobbyInterface->SendAnnouncementMessageToCurrentLobby(msg, true); + else + wolLocalSystemChat(text); +} + +// The lobby must line up with the recording slot for slot (the service owns slot +// order, so nothing here reorders anything). +static Bool wolLobbySlotsMatchReplay(const ReplayGameInfo &replayInfo, const GameInfo *lobby, UnicodeString &why) +{ + for (Int i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replayInfo.getConstSlot(i); + const GameSlot *ls = lobby->getConstSlot(i); + const Bool replayHuman = rs && rs->isHuman(); + const Bool lobbyHuman = ls && ls->isHuman(); + if (replayHuman == lobbyHuman && (!replayHuman || rs->getName().compare(ls->getName()) == 0)) + continue; + if (replayHuman) + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", + L"Resume: slot %d must be %ls (it was theirs in the recording)", i + 1, rs->getName().str()); + else + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", + L"Resume: slot %d was not a player in the recording, close it or move %ls", i + 1, ls->getName().str()); + return FALSE; + } + return TRUE; +} + +// Called on the host's start while a resume is armed: refuse when the lobby has +// drifted from the recording since arming. +static Bool wolArmedResumeStillMatches(NGMPGame *game) +{ + RecorderClass::ReplayHeader header; + ReplayGameInfo info; + const MapMetaData *mapData = nullptr; + UnicodeString why; + if (!readReplayMapInfo(game->getResumeReplayFile(), header, info, mapData)) + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read"); + else if (wolLobbySlotsMatchReplay(info, game, why)) + return TRUE; + wolLobbySystemChat(why); + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeStartRefused", + L"Resume is armed and the lobby no longer matches the recording. Fix it, or type /resume off to start a fresh game.")); + return FALSE; +} + static void wolTryArmResumeFromReplay(Bool disarm) { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); @@ -1675,25 +1736,12 @@ static void wolTryArmResumeFromReplay(Bool disarm) } // Every human must sit in the slot they held in the replay; slot order is the - // service's, so report the first difference instead of reordering. - for (Int i = 0; i < MAX_SLOTS; ++i) + // service's, so tell the lobby the first difference instead of reordering. + UnicodeString why; + if (!wolLobbySlotsMatchReplay(info, game, why)) { - const GameSlot *rs = info.getConstSlot(i); - const GameSlot *ls = game->getConstSlot(i); - const Bool replayHuman = rs && rs->isHuman(); - const Bool lobbyHuman = ls && ls->isHuman(); - if (replayHuman != lobbyHuman || (replayHuman && rs->getName().compare(ls->getName()) != 0)) - { - UnicodeString msg; - if (replayHuman) - msg = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", - L"Resume: slot %d must be %ls (it was theirs in the replay)", i + 1, rs->getName().str()); - else - msg = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", - L"Resume: slot %d was not a player in the replay, close it or move %ls", i + 1, ls->getName().str()); - wolLocalSystemChat(msg); - return; - } + wolLobbySystemChat(why); + return; } // Restore the recorded faction, color, start position and team on every human From 99b6106c7cf70de5b2d3267262a0270223b8d10a Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Tue, 15 Sep 2026 15:09:59 -0700 Subject: [PATCH 08/15] fix(resume): Register /resume with the online lobby's slash commands The online lobby routes every slash command through handleGameSetupSlashCommands, which answered /resume with Unknown command before the chat entry ever saw it. The command now lives there, with a /help line. --- .../GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index c27907d9498..660ebc8ce81 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -3807,10 +3807,20 @@ Bool handleGameSetupSlashCommands(UnicodeString uText) } #if defined(GENERALS_ONLINE) + else if (token == "resume") + { + // resume-from-replay arming lives behind a chat command so no layout change is needed + AsciiString arg; + remainder.nextToken(&arg); + arg.toLower(); + wolTryArmResumeFromReplay(arg == "off"); + return TRUE; // was a slash command + } else if (token == "help" || token == "commands") { const Color helpColor = GameMakeColor(127, 127, 127, 255); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/me - Send an emote."), helpColor, -1, -1); + GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/resume - Resume the last recorded match from its replay; /resume off disarms (host only)."), helpColor, -1, -1); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/friendsonly - Let only friends join (host only)."), helpColor, -1, -1); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/public - Let anyone join (host only)."), helpColor, -1, -1); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/setpassword - Set a lobby password (host only)."), helpColor, -1, -1); @@ -4296,12 +4306,7 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg if (!txtInput.isEmpty()) { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); - if (txtInput.compareNoCase(L"/resume") == 0 || txtInput.compareNoCase(L"/resume off") == 0) - { - // resume-from-replay arming lives behind a chat command so no layout change is needed - wolTryArmResumeFromReplay(txtInput.compareNoCase(L"/resume off") == 0); - } - else if (pLobbyInterface != nullptr) + if (pLobbyInterface != nullptr) { pLobbyInterface->SendChatMessageToCurrentLobby(txtInput, false); } From 1a5c8306620b99888f496d6f6b62b47d9c63bc34 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Thu, 24 Sep 2026 09:46:42 -0700 Subject: [PATCH 09/15] feat(resume): Resume from one shared replay pushed by the host Every client now replays the same file. /resume copies the host's last recording to Replays/Resume.rep (RecorderClass::getResumeReplayFileName), aligns the lobby with it and broadcasts only the handoff frame (RH= in the LAN options, ResumeHandoffFrame online; the file name is fixed, so RF= and replay_file are gone). The file is pushed to the guests before the game starts: on LAN over the map transfer path at OnGameStart (DoResumeReplayTransfer, with .rep admitted to the transfer whitelist behind a GENREP check and a Replays\ portable path), online by an upload to the service that must finish before the arm is sent, after which guests download it, report "Resume: replay downloaded" and flag themselves as holding it; the host cannot press start until every human does. The handoff is the host's scanReplayLastFrame(Resume.rep) minus a named slack, so there is no shorter-replay case any more. The resumed match records a brand new 00000000.rep from frame 0 like any other game: the recorder starts recording as usual, opens Resume.rep on a second handle, injects its commands frame by frame and writes them straight into the new recording, then keeps recording live after the handoff. The old truncate-the-source hand-over is gone. Guests validate their copy against the lobby (version, map, map CRC, seed, starting cash, superweapon limit, every slot's occupant, and that the recording reaches the handoff) when it arrives and again at game start, through one helper (GameNetwork/ResumeFromReplay). A mismatch backs out of the start the way a missing map does, and a source that ends before the handoff aborts the game instead of handing off locally; nothing falls back to recording a fresh match. Changing the map, starting cash or superweapon limit disarms on the client and on the service. Also: local MSG_LOGIC_CRC messages are dropped during catch-up and validation stays off for one run-ahead after the handoff, which removes the false "Not enough CRCs" on the handoff frame; the throttled render path still emits MSG_FRAME_TICK every logic frame so the network's per-frame bookkeeping keeps running; a torn replay record ends the usable data instead of being parsed as garbage; the dead FPS and logic-rate plumbing is removed (catch-up runs on the isResumeCatchupMode bypasses only); the recorder no longer reaches into LANAPI or NGMPGame; the arm is announced online only from the service's success reply. --- .../Include/GameNetwork/FileTransfer.h | 4 + .../GameEngine/Include/GameNetwork/GameInfo.h | 10 +- .../Include/GameNetwork/NetworkInterface.h | 5 - .../Source/GameNetwork/ConnectionManager.cpp | 17 +- .../Source/GameNetwork/FileTransfer.cpp | 39 +- .../Source/GameNetwork/GameInfo.cpp | 29 +- .../Source/GameNetwork/LANAPICallbacks.cpp | 33 ++ .../GameEngine/Source/GameNetwork/Network.cpp | 21 +- GeneralsMD/Code/GameEngine/CMakeLists.txt | 2 + .../Code/GameEngine/Include/Common/Recorder.h | 49 +- .../OnlineServices_LobbyInterface.h | 18 +- .../Include/GameNetwork/ResumeFromReplay.h | 85 +++ .../GameEngine/Source/Common/GameEngine.cpp | 13 +- .../GameEngine/Source/Common/Recorder.cpp | 485 ++++++++++-------- .../Common/System/SaveGame/GameState.cpp | 15 + .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 271 ++++------ .../GUI/GUICallbacks/Menus/ReplayMenu.cpp | 3 +- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 229 ++++++--- .../GameEngine/Source/GameClient/InGameUI.cpp | 1 + .../Source/GameLogic/System/GameLogic.cpp | 10 +- .../GameNetwork/GeneralsOnline/NGMPGame.cpp | 25 +- .../OnlineServices_LobbyInterface.cpp | 212 +++++++- .../Source/GameNetwork/ResumeFromReplay.cpp | 282 ++++++++++ 23 files changed, 1299 insertions(+), 559 deletions(-) create mode 100644 GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h create mode 100644 GeneralsMD/Code/GameEngine/Source/GameNetwork/ResumeFromReplay.cpp diff --git a/Core/GameEngine/Include/GameNetwork/FileTransfer.h b/Core/GameEngine/Include/GameNetwork/FileTransfer.h index 474599405f0..bf68e331154 100644 --- a/Core/GameEngine/Include/GameNetwork/FileTransfer.h +++ b/Core/GameEngine/Include/GameNetwork/FileTransfer.h @@ -46,3 +46,7 @@ AsciiString GetReadmeFromMap( AsciiString path ); // The meat of file (map) transfers Bool DoAnyMapTransfers(GameInfo *game); + +// TheSuperHackers @feature bill-rich 24/09/2026 Resume-from-replay: the host pushes the resume source +// (a replay file) to every human guest over the same transfer path at game start. +Bool DoResumeReplayTransfer(GameInfo *game, AsciiString path); diff --git a/Core/GameEngine/Include/GameNetwork/GameInfo.h b/Core/GameEngine/Include/GameNetwork/GameInfo.h index 0289100e52d..645f8524d91 100644 --- a/Core/GameEngine/Include/GameNetwork/GameInfo.h +++ b/Core/GameEngine/Include/GameNetwork/GameInfo.h @@ -220,13 +220,12 @@ class GameInfo void setCRCInterval( Int val ) { m_crcInterval = (val > 0 && val < 100) ? val : 100; } Int getCRCInterval() const { return m_crcInterval; } - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming. When non-empty, every client - // opens its own copy of this replay on game start and replays it in lockstep up - // to the handoff frame before live control resumes (see RecorderClass). - void setResumeReplayFile( AsciiString f ) { m_resumeReplayFile = f; } - AsciiString getResumeReplayFile() const { return m_resumeReplayFile; } + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming. When non-zero, every client + // replays its copy of the resume source (Resume.rep, pushed from the host) in lockstep + // up to this frame on game start before live control resumes (see ResumeFromReplay). void setResumeHandoffFrame( UnsignedInt f ) { m_resumeHandoffFrame = f; } UnsignedInt getResumeHandoffFrame() const { return m_resumeHandoffFrame; } + Bool isResumeArmed() const { return m_resumeHandoffFrame != 0; } Bool haveWeSurrendered() { return m_surrendered; } void markAsSurrendered() { m_surrendered = TRUE; } @@ -264,7 +263,6 @@ class GameInfo Bool m_oldFactionsOnly; // Only USA, China, GLA -- not USA Air Force General, GLA Toxic General, et al // resume-from-replay arming (appended last so existing member offsets are untouched) - AsciiString m_resumeReplayFile; UnsignedInt m_resumeHandoffFrame; }; diff --git a/Core/GameEngine/Include/GameNetwork/NetworkInterface.h b/Core/GameEngine/Include/GameNetwork/NetworkInterface.h index 5e98bac2cb6..606429450dd 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkInterface.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkInterface.h @@ -123,11 +123,6 @@ class NetworkInterface : public SubsystemInterface virtual void notifyOthersOfCurrentFrame() = 0; ///< Tells all the other players what frame we are on. virtual void notifyOthersOfNewFrame(UnsignedInt frame) = 0; ///< Tells all the other players that we are on a new frame. - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup: override the network's - // logic frame-rate cap so timeForNewFrame() lets frames advance faster than realtime. - // Returns the previous rate for restoration. - virtual Int setLogicFrameRate(Int fps) = 0; - virtual Int getExecutionFrame() = 0; ///< Returns the next valid frame for simultaneous command execution. #if defined(RTS_DEBUG) diff --git a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp index ad4d4a0c689..eed3640f324 100644 --- a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp @@ -67,7 +67,8 @@ static Bool hasValidTransferFileExtension(const AsciiString& filePath) "str", "wak", "tga", - "txt" + "txt", + "rep" // TheSuperHackers @feature bill-rich 24/09/2026 the resume-from-replay source (see ResumeFromReplay) }; const char* fileExt = strrchr(filePath.str(), '.'); @@ -99,6 +100,7 @@ enum TransferFileType TransferFileType_Txt, TransferFileType_Tga, TransferFileType_Wak, + TransferFileType_Rep, TransferFileType_Count }; @@ -116,6 +118,7 @@ static const TransferFileRule transferFileRules[TransferFileType_Count] = { ".txt", 1 * 1024 * 1024 }, { ".tga", 2 * 1024 * 1024 }, { ".wak", 128 * 1024 }, + { ".rep", 16 * 1024 * 1024 }, }; static TransferFileType getTransferFileType(const char* extension) @@ -173,6 +176,18 @@ static Bool hasValidTransferFileContent(const AsciiString& filePath, const Unsig break; } + case TransferFileType_Rep: + { + // a replay starts with the GENREP tag (see RecorderClass::startRecording) + static const char replayTag[] = "GENREP"; + if (dataSize < sizeof(replayTag) - 1 || memcmp(data, replayTag, sizeof(replayTag) - 1) != 0) + { + DEBUG_LOG(("Replay file '%s' does not start with GENREP.", filePath.str())); + return false; + } + break; + } + case TransferFileType_Tga: { if (dataSize < sizeof(TGAHeader) + sizeof(TGA2Footer)) diff --git a/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp b/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp index 5d9cc7dfe64..0cae0a576e4 100644 --- a/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp +++ b/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp @@ -82,7 +82,9 @@ static Bool doFileTransfer( AsciiString filename, MapTransferLoadScreen *ls, Int fileTransferPercent = 100; for (i=1; igetConstSlot(i)->isHuman() && !TheGameInfo->getConstSlot(i)->hasMap()) + // TheSuperHackers @refactor bill-rich 24/09/2026 Wait on the slots in the mask (the callers build it + // from the slots that lack the file), so the same loop serves the resume-from-replay transfer. + if (TheGameInfo->getConstSlot(i)->isHuman() && (mask & (1<getFileTransferProgress(i, filename); fileTransferPercent = min(fileTransferPercent, slotTransferPercent); @@ -281,3 +283,38 @@ Bool DoAnyMapTransfers(GameInfo *game) TheShell->showShell(); return ok; } + +//------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- + +// TheSuperHackers @feature bill-rich 24/09/2026 Push the resume-from-replay source from the host to every +// human guest. Every guest needs it (there is no "has file" state for replays), so the mask is +// every human slot but the host's; the file lands in the guest's replay directory under the same +// name (see GameState::portableMapPathToRealMapPath). +Bool DoResumeReplayTransfer(GameInfo *game, AsciiString path) +{ + TheGameInfo = game; + path.toLower(); // the transfer bookkeeping compares against the normalized (lower-case) real path + Int mask = 0; + Int i=0; + for (i=1; igetConstSlot(i)->isHuman()) + { + DEBUG_LOG(("Adding player %d to resume replay transfer mask", i)); + mask |= (1<hideShell(); + MapTransferLoadScreen *ls = NEW MapTransferLoadScreen; + ls->init(TheGameInfo); + Bool ok = doFileTransfer(path, ls, mask); + delete ls; + ls = nullptr; + if (!ok) + TheShell->showShell(); + return ok; +} diff --git a/Core/GameEngine/Source/GameNetwork/GameInfo.cpp b/Core/GameEngine/Source/GameNetwork/GameInfo.cpp index 0196168240f..c5fef7b1285 100644 --- a/Core/GameEngine/Source/GameNetwork/GameInfo.cpp +++ b/Core/GameEngine/Source/GameNetwork/GameInfo.cpp @@ -323,7 +323,6 @@ void GameInfo::reset() m_mapSize = 0; m_superweaponRestriction = 0; m_startingCash = TheGlobalData->m_defaultStartingCash; - m_resumeReplayFile.clear(); m_resumeHandoffFrame = 0; for (Int i=0; igetStartingCash().countMoney(), game->oldFactionsOnly() ? 'Y' : 'N' ); #endif + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay handoff frame. Only emitted when + // armed so unarmed games still round-trip bit-identically through the serializer, and + // emitted before the slot list so the slot-name truncation below accounts for it. + if (game->isResumeArmed()) + { + AsciiString resume; + resume.format("RH=%u;", game->getResumeHandoffFrame()); + optionsString.concat(resume); + } + //add player info for each slot optionsString.concat(slotListID); optionsString.concat('='); @@ -997,15 +1006,6 @@ AsciiString GameInfoToAsciiString( const GameInfo *game ) } optionsString.concat(';'); - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming. Only emitted when armed so - // unarmed games still round-trip bit-identically through the serializer. - if (!game->getResumeReplayFile().isEmpty()) - { - AsciiString resume; - resume.format("RF=%s;RHF=%u;", game->getResumeReplayFile().str(), game->getResumeHandoffFrame()); - optionsString.concat(resume); - } - DEBUG_ASSERTCRASH(!TheLAN || (optionsString.getLength() < m_lanMaxOptionsLength), ("WARNING: options string is longer than expected! Length is %d, but max is %d!", optionsString.getLength(), m_lanMaxOptionsLength)); @@ -1039,7 +1039,6 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options) Int useStats = TRUE; Money startingCash = TheGlobalData->m_defaultStartingCash; UnsignedShort restriction = 0; // Always the default - AsciiString resumeReplayFile; UnsignedInt resumeHandoffFrame = 0; Bool sawMap = FALSE; @@ -1160,12 +1159,9 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options) oldFactionsOnly = ( val.compareNoCase( "Y" ) == 0 ); sawOldFactions = TRUE; } - else if (key.compare("RF") == 0) - { - resumeReplayFile = val; - } - else if (key.compare("RHF") == 0) + else if (key.compare("RH") == 0) { + // resume-from-replay handoff frame (see GameInfoToAsciiString) resumeHandoffFrame = (UnsignedInt)strtoul(val.str(), nullptr, 10); } else if (key.getLength() == 1 && *key.str() == slotListID) @@ -1536,7 +1532,6 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options) game->setSuperweaponRestriction(restriction); game->setStartingCash(startingCash); game->setOldFactionsOnly(oldFactionsOnly); - game->setResumeReplayFile(resumeReplayFile); game->setResumeHandoffFrame(resumeHandoffFrame); return true; diff --git a/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp index 701ef3e987e..fd243546b2d 100644 --- a/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp +++ b/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp @@ -46,6 +46,7 @@ #include "GameNetwork/FileTransfer.h" #include "GameNetwork/LANAPICallbacks.h" #include "GameNetwork/networkutil.h" +#include "GameNetwork/ResumeFromReplay.h" LANAPI *TheLAN = nullptr; extern Bool LANbuttonPushed; @@ -243,6 +244,38 @@ void LANAPI::OnGameStart() return; } + // TheSuperHackers @feature bill-rich 24/09/2026 An armed resume-from-replay first pushes the host's + // resume source to every guest over the map transfer path, then every client checks its + // copy against the lobby and arms the recorder. Either failing backs out the same way as + // a missing map rather than start a fresh match that would desync everyone. + if (m_currentGame->isResumeArmed()) + { + UnicodeString resumeWhy; + Bool resumeOk = DoResumeReplayTransfer(m_currentGame, ResumeFromReplay::getSourceFilePath()); + if (!resumeOk) + resumeWhy = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTransferFailed", L"Resume aborted: the resume replay could not be transferred"); + else + resumeOk = ResumeFromReplay::prepareGameStart(m_currentGame, resumeWhy); + if (!resumeOk) + { + DEBUG_LOG(("Resume-from-replay transfer or validation failed. Bailing...")); + OnPlayerLeave(m_name); + removeGame(m_currentGame); + m_currentGame = nullptr; + m_inLobby = TRUE; + + delete TheNetwork; + TheNetwork = nullptr; + + OnChat(UnicodeString::TheEmptyString, 0, resumeWhy, LANCHAT_SYSTEM); + return; + } + } + else if (TheRecorder != nullptr) + { + TheRecorder->disarmResume(); + } + m_currentGame->startGame(0); // shutdown the top, but do not pop it off the stack diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index 888bcda04e1..5aecf9d719d 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -179,7 +179,6 @@ class Network : public NetworkInterface virtual void notifyOthersOfCurrentFrame() override; ///< Tells all the other players what frame we are on. virtual void notifyOthersOfNewFrame(UnsignedInt frame) override; ///< Tells all the other players that we are on a new frame. - virtual Int setLogicFrameRate(Int fps) override; ///< Resume-from-replay catchup: override the per-frame timing rate; returns the previous rate. virtual Int getExecutionFrame() override; ///< Returns the next valid frame for simultaneous command execution. @@ -500,11 +499,20 @@ Bool Network::isMessageTypeWithinNetworkRange(GameMessage::Type type) { * Take commands from TheCommandList and give them to the connection manager for transport. */ void Network::GetCommandsFromCommandList() { + // TheSuperHackers @feature bill-rich 24/09/2026 During resume-from-replay catchup the local CRCs + // are not exchanged (every peer is replaying the source's recorded CRC messages instead), + // and leaving one in TheCommandList would have it execute a frame later on its own: on + // the handoff frame that is a lone CRC with validation back on, a false "Not enough CRCs". + const Bool inCatchup = TheRecorder && TheRecorder->isResumeCatchupMode(); GameMessage* msg = TheCommandList->getFirstMessage(); GameMessage* next = NULL; while (msg != NULL) { next = msg->next(); - if (isMessageTypeWithinNetworkRange(msg->getType())) { // Is this something we should be sending to the other players? + if (inCatchup && msg->getType() == GameMessage::MSG_LOGIC_CRC) { + TheCommandList->removeMessage(msg); + deleteInstance(msg); + } + else if (isMessageTypeWithinNetworkRange(msg->getType())) { // Is this something we should be sending to the other players? if (m_localStatus == NETLOCALSTATUS_INGAME) { m_conMgr->sendLocalGameMessage(msg, getExecutionFrame()); } @@ -639,7 +647,8 @@ void Network::RelayCommandsToCommandList(UnsignedInt frame) { if (isMessageTypeWithinNetworkRange(gmsg->getGameMessageType())) { //DEBUG_LOG(("Network::RelayCommandsToCommandList - appending command %d of type %s to command list on frame %d", msg->getCommand()->getID(), gmsg->getCommandAsString(), TheGameLogic->getFrame())); TheCommandList->appendMessage(gmsg->constructGameMessage()); - } else { + } else if (!(TheRecorder && TheRecorder->isResumeCatchupMode())) { + // (during resume-from-replay catchup every type is non-transfer, so this would log every message) DEBUG_LOG(("Network::RelayCommandsToCommandList - rejecting game message from player %d of type %s, which is not a network type.", gmsg->getPlayerID(), GameMessage::getCommandTypeAsString(gmsg->getGameMessageType()))); } @@ -1131,9 +1140,3 @@ void Network::notifyOthersOfNewFrame(UnsignedInt frame) { m_conMgr->notifyOthersOfNewFrame(frame); } } - -Int Network::setLogicFrameRate(Int fps) { - Int prev = m_frameRate; - m_frameRate = fps > 0 ? fps : 1; - return prev; -} diff --git a/GeneralsMD/Code/GameEngine/CMakeLists.txt b/GeneralsMD/Code/GameEngine/CMakeLists.txt index a84c0935e98..de158132fa8 100644 --- a/GeneralsMD/Code/GameEngine/CMakeLists.txt +++ b/GeneralsMD/Code/GameEngine/CMakeLists.txt @@ -529,6 +529,7 @@ set(GAMEENGINE_SRC # Include/GameNetwork/GameSpyOverlay.h # Include/GameNetwork/GameSpyThread.h Include/GameNetwork/GUIUtil.h + Include/GameNetwork/ResumeFromReplay.h # Include/GameNetwork/IPEnumeration.h # Include/GameNetwork/LANAPI.h # Include/GameNetwork/LANAPICallbacks.h @@ -1115,6 +1116,7 @@ set(GAMEENGINE_SRC # Source/GameNetwork/GameSpy/Thread/ThreadUtils.cpp # Source/GameNetwork/GameSpyOverlay.cpp Source/GameNetwork/GUIUtil.cpp + Source/GameNetwork/ResumeFromReplay.cpp # Source/GameNetwork/IPEnumeration.cpp # Source/GameNetwork/LANAPI.cpp # Source/GameNetwork/LANAPICallbacks.cpp diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h index 14afd077976..7b0b18f6c32 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h @@ -142,24 +142,29 @@ class RecorderClass : public SubsystemInterface // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay. // - // Every client opens its own copy of the same replay when the game starts and - // injects its recorded commands frame by frame while the live network game runs - // in lockstep at an uncapped rate (catchup). The last RESUME_LEADIN_SECONDS before - // the handoff frame run at normal speed (lead-in), then the simulation is held for - // RESUME_FREEZE_SECONDS of wall-clock time with a countdown (freeze), and finally - // control is handed back to the players. Camera scrolling works throughout; every - // other interaction is blocked until the freeze ends (see isResumeInputBlocked). + // The lobby's start path validates this client's copy of the resume source (Resume.rep, + // see ResumeFromReplay) and arms the recorder. On the next MSG_NEW_GAME a brand new + // recording of the resumed match is started as for any other game, and the source's + // commands are injected into TheCommandList frame by frame while the live network game + // runs in lockstep at an uncapped rate (catchup); every injected command is written to the + // new recording as it goes, so the new replay holds the whole match. The last + // RESUME_LEADIN_SECONDS before the handoff frame run at normal speed (lead-in), then the + // simulation is held for RESUME_FREEZE_SECONDS of wall-clock time with a countdown (freeze), + // and finally control is handed back to the players. Camera scrolling works throughout; + // every other interaction is blocked until the freeze ends (see isResumeInputBlocked). static const Int RESUME_LEADIN_SECONDS = 10; static const Int RESUME_FREEZE_SECONDS = 10; + static AsciiString getResumeReplayFileName(); ///< name (without extension) of the resume source every client replays + void armResumeForNextGame(UnsignedInt handoffFrame, UnsignedInt sourceLastFrame); ///< validated by ResumeFromReplay::prepareGameStart + void disarmResume(); + Bool isResumeArmed() const { return m_resumeArmedHandoffFrame != 0; } Bool isResumeCatchupMode() const { return m_mode == RECORDERMODETYPE_RESUME_CATCHUP; } Bool isResumeCatchupLeadIn() const; ///< catchup, within the last RESUME_LEADIN_SECONDS before handoff Bool isResumeFreezeActive() const { return m_resumeFreezeStartMs != 0; } ///< handoff reached, holding the sim with a countdown Bool isResumeInputBlocked() const { return isResumeCatchupMode() || isResumeFreezeActive(); } + Bool isResumeCRCValidationSuppressed() const; ///< catchup, and the run-ahead window after the handoff Bool updateResumeFreeze(); ///< pumped every engine frame by Network::update; TRUE while frames must not advance - Bool startResumeCatchup(AsciiString filename, UnsignedInt handoffFrame); - void updateResumeCatchup(); - Bool beginRecordingAfterResume(); ///< take the replay file over for recording so the resumed match is a complete replay - UnsignedInt scanReplayLastFrame(AsciiString filename); ///< last frame number in a replay; walks the records, for recordings whose header was never finalized (crash) + UnsignedInt scanReplayLastFrame(AsciiString filename); ///< last frame with a complete record; walks the records, for recordings whose header was never finalized (crash) or whose tail is torn void initControls(); ///< Show or Hide the Replay controls static AsciiString getReplayDir(); ///< Returns the directory that holds the replay files. @@ -191,9 +196,9 @@ class RecorderClass : public SubsystemInterface AsciiString readAsciiString(); ///< Read the next string from m_file using ascii characters. UnicodeString readUnicodeString(); ///< Read the next string from m_file using unicode characters. void readNextFrame(); ///< Read the next frame number to execute a command on. - void appendNextCommand(); ///< Read the next GameMessage and append it to TheCommandList. + Bool appendNextCommand(); ///< Read the next GameMessage and append it to TheCommandList. FALSE on a torn record. void writeArgument(GameMessageArgumentDataType type, const GameMessageArgumentType arg); - void readArgument(GameMessageArgumentDataType type, GameMessage *msg); + Bool readArgument(GameMessageArgumentDataType type, GameMessage *msg); ///< FALSE on a short read. struct CullBadCommandsResult { @@ -222,13 +227,21 @@ class RecorderClass : public SubsystemInterface UnsignedInt m_nextFrame; ///< The Frame that the next message is to be executed on. This can be -1. // resume-from-replay state (see the accessors above) - UnsignedInt m_resumeHandoffFrame; ///< frame at which replay injection stops and the freeze begins - Int m_resumeSavedFpsLimit; ///< render FPS limit to restore after catchup - Int m_resumeSavedNetFrameRate; ///< network logic frame rate to restore after catchup - Int m_resumeRecordPos; ///< byte offset just past the last replayed record; beginRecordingAfterResume truncates here - Bool m_resumeRatesRestored; ///< lead-in reached and the rate caps are back to normal + File* m_resumeSourceFile; ///< the resume source (Resume.rep) being read during catchup; m_file is the new recording + UnsignedInt m_resumeArmedHandoffFrame; ///< handoff frame for the next MSG_NEW_GAME, 0 when not armed + UnsignedInt m_resumeArmedSourceLastFrame; ///< last complete frame of the resume source, from scanReplayLastFrame + UnsignedInt m_resumeHandoffFrame; ///< frame at which injection stops and the freeze begins; stays set after the handoff for the CRC window + UnsignedInt m_resumeSourceLastFrame; ///< injection never reads past this frame, so a torn tail cannot be replayed + Bool m_resumeLeadInAnnounced; ///< the lead-in message has been shown UnsignedInt m_resumeFreezeStartMs; ///< wall-clock start of the freeze, 0 when not frozen Int m_resumeFreezeLastAnnounced; ///< last countdown second shown + + Bool startResumeCatchup(); ///< open the resume source and switch to catchup; the recording is already started + void updateResumeCatchup(); ///< inject the source's commands for this frame, hand off at the handoff frame + void injectResumeCommands(UnsignedInt curFrame); ///< read the source's records for curFrame into TheCommandList + void endResumeCatchup(); ///< close the source and leave catchup without handing off + void abortResume(const UnicodeString &why); ///< leave the game: the source cannot be replayed to the handoff + void clearResumeState(); }; extern RecorderClass *TheRecorder; diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index 8491d5cb5d8..39d2afb1f5e 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -9,7 +9,9 @@ #include "GameClient/InGameUI.h" #include "GameLogic/VictoryConditions.h" #include +#include #include +#include extern NGMPGame* TheNGMPGame; @@ -24,6 +26,7 @@ struct LobbyMemberEntry : public NetworkMemberBase int team = -1; int startpos = -1; bool has_map = false; + bool has_resume_replay = false; // TheSuperHackers @feature bill-rich 24/09/2026 holds a usable copy of the resume-from-replay source uint16_t m_SlotIndex = 999999; uint16_t m_SlotState = SlotState::SLOT_OPEN; @@ -72,8 +75,7 @@ struct LobbyEntry int rng_seed = -1; - // resume-from-replay arming (empty when not armed); see NGMPGame::setResumeReplayFile - std::string resume_replay_file; + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (0 when not armed); see ResumeFromReplay uint32_t resume_handoff_frame = 0; bool passworded = false; @@ -231,7 +233,14 @@ class NGMP_OnlineServices_LobbyInterface void UpdateCurrentLobby_AIStartPos(int slot, int startpos); void UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game); - void UpdateCurrentLobby_ArmResume(const std::string& replayFile, uint32_t handoffFrame, int rngSeed); ///< empty file disarms + + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay (see ResumeFromReplay). The host uploads + // the resume source, then arms with the handoff frame and the replay's seed (handoff 0 disarms); + // guests download the source when the arm reaches them and flag themselves as holding it. + void UpdateCurrentLobby_ArmResume(uint32_t handoffFrame, int rngSeed, std::function onComplete); + void UpdateCurrentLobby_HasResumeReplay(bool bHasResumeReplay); + void UploadResumeReplay(const AsciiString& path, std::function onComplete); + void DownloadResumeReplay(const AsciiString& path, std::function onComplete); void UpdateCurrentLobbyMaxCameraHeight(uint16_t maxCameraHeight); @@ -538,6 +547,9 @@ class NGMP_OnlineServices_LobbyInterface } private: + void SendResumeReplayChunk(int64_t lobbyID, std::shared_ptr> data, size_t offset, std::function onComplete); + void FetchResumeReplayChunk(int64_t lobbyID, AsciiString path, std::shared_ptr> data, std::function onComplete); + std::function m_cb_CreateLobbyPendingCallback = nullptr; std::function m_callbackJoinedLobby = nullptr; diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h new file mode 100644 index 00000000000..7dd8cdd2efb --- /dev/null +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h @@ -0,0 +1,85 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2025 Electronic Arts Inc. +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +// TheSuperHackers @feature bill-rich 24/09/2026 Resume-from-replay: the arming and validation +// shared by the LAN lobby, the online lobby and the game start path. +// +// After a match dies, the same players resume it from the host's recording. The host arms it +// in the lobby (/resume): its own last recording (00000000.rep) is copied to Resume.rep, the +// lobby is aligned with the recording (slots, map, seed) and the handoff frame is broadcast in +// the game options. That one file is then pushed to every guest (the map transfer path on LAN, +// an upload to the service online), each guest validates its copy against the lobby, and on +// game start RecorderClass replays Resume.rep in lockstep up to the handoff frame while +// recording a brand new 00000000.rep of the resumed match. + +#pragma once + +#include "Common/Recorder.h" + +class GameInfo; +class MapMetaData; + +/// Reads a replay's header and game info without opening it for playback. Defined in ReplayMenu.cpp. +Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); + +namespace ResumeFromReplay +{ + /// The handoff sits this far before the end of the recording, so the last seconds before + /// the match died (which every player has seen play out) are not replayed as if new. + constexpr Int HANDOFF_SLACK_SECONDS = 10; + + /// What a client knows about its copy of the resume source (Resume.rep). + struct SourceReplay + { + RecorderClass::ReplayHeader header; + ReplayGameInfo game; + const MapMetaData *mapData = nullptr; + UnsignedInt lastFrame = 0; ///< last frame with a complete record; the header's count is 0 for a recording cut short by a crash + }; + + AsciiString getSourceFileName(); ///< "Resume.rep" + AsciiString getSourceFilePath(); ///< full path of the resume source in the replay directory + UnicodeString formatGameTime(UnsignedInt frames); ///< m:ss + + /// Host: copies the last recording to Resume.rep, reads it back, checks the version and computes the + /// handoff frame. The reason for a refusal is returned in why (without a "Resume:" prefix). + Bool prepareHostSource(SourceReplay &out, UnsignedInt &handoffFrame, UnicodeString &why); + + /// Reads this client's Resume.rep: header, version check and the last complete frame. + Bool readSource(SourceReplay &out, UnicodeString &why); + + /// Compares the source recording against the lobby: map, map CRC, seed, starting cash, superweapon + /// restriction, every slot's occupant, and (when handoffFrame != 0) that the recording reaches it. + Bool sourceMatchesGame(const SourceReplay &replay, const GameInfo *game, UnsignedInt handoffFrame, UnicodeString &why); + + /// Host arming: every human in the recording is in the lobby under the same name, the host is + /// the recording's slot-0 player and nobody extra is present (slot order is checked separately). + Bool validateRoster(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why); + + /// Every recorded human in the slot they held, under the same name, and nobody else in a recorded slot. + Bool slotsMatch(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why); + + /// Guest: after its copy of Resume.rep arrived, whether it matches the lobby, with one chat line + /// for everyone either way. + Bool guestSourceReport(const GameInfo *lobby, UnicodeString &report); + + /// Game start (LAN OnGameStart / NGMPGame::startGame), before MSG_NEW_GAME: when the lobby is armed, + /// validates this client's Resume.rep against it and arms the recorder. Returns FALSE with the + /// reason when the start must be abandoned; the recorder is never left armed in that case. + Bool prepareGameStart(const GameInfo *game, UnicodeString &why); +} diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp index 06dac86fb70..7436dfc2bcf 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp @@ -968,6 +968,10 @@ Bool GameEngine::canUpdateRegularGameLogic(UnsignedInt logicTimeQueryFlags) extern NGMPGame* TheNGMPGame; #endif +// TheSuperHackers @feature bill-rich 15/09/2026 Wall-clock cadence of the render passes during +// resume-from-replay catchup (about 30 fps), see GameEngine::update. +static constexpr const UnsignedInt CATCHUP_RENDER_INTERVAL_MS = 33; + /// ----------------------------------------------------------------------------------------------- DECLARE_PERF_TIMER(GameEngine_update) @@ -990,7 +994,6 @@ void GameEngine::update() && !TheRecorder->isResumeCatchupLeadIn(); if (catchupSkipRender) { - const UnsignedInt CATCHUP_RENDER_INTERVAL_MS = 33; static UnsignedInt s_lastCatchupRenderMs = 0; const UnsignedInt nowMs = timeGetTime(); if (nowMs - s_lastCatchupRenderMs >= CATCHUP_RENDER_INTERVAL_MS) @@ -1023,7 +1026,15 @@ void GameEngine::update() TheAudio->UPDATE(); if (catchupSkipRender) + { TheParticleSystemManager->update(); // let particles finish instead of piling up while frames are skipped + + // The frame tick is the client update's first act (GameClient::update) and the + // network relies on one per logic frame: Network::processCommand drives the + // per-frame command counts off it and switches PREGAME to INGAME on frame 1. + GameMessage *frameMsg = TheMessageStream->appendMessage( GameMessage::MSG_FRAME_TICK ); + frameMsg->appendTimestampArgument( TheGameClient->getFrame() ); + } else TheGameClient->UPDATE(); TheMessageStream->propagateMessages(); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index ddecc7cdefc..6410636ff55 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -31,18 +31,9 @@ #include "Common/Player.h" #include "Common/GlobalData.h" #include "Common/GameEngine.h" -#include "Common/FramePacer.h" -#include "GameNetwork/LANAPI.h" #include "GameNetwork/NetworkDefs.h" #include "GameNetwork/NetworkInterface.h" -#if defined(GENERALS_ONLINE) -#include "GameNetwork/GeneralsOnline/NGMPGame.h" -#include "GameNetwork/GeneralsOnline/NGMP_include.h" -extern NGMPGame* TheNGMPGame; -#define RESUME_LOG(...) NetworkLog(ELogVerbosity::LOG_RELEASE, __VA_ARGS__) -#else -#define RESUME_LOG(...) DEBUG_LOG((__VA_ARGS__)) -#endif +#include "GameNetwork/ResumeFromReplay.h" #include "GameClient/ClientInstance.h" #include "GameClient/GameWindow.h" #include "GameClient/GameWindowManager.h" @@ -64,6 +55,13 @@ extern NGMPGame* TheNGMPGame; extern NGMPGame* TheNGMPGame; +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay milestones go to the release log online. +#if defined(GENERALS_ONLINE) +#define RESUME_LOG(...) NetworkLog(ELogVerbosity::LOG_RELEASE, __VA_ARGS__) +#else +#define RESUME_LOG(...) DEBUG_LOG((__VA_ARGS__)) +#endif + constexpr const char s_genrep[] = "GENREP"; constexpr const UnsignedInt replayBufferBytes = 8192; @@ -71,6 +69,7 @@ Int REPLAY_CRC_INTERVAL = 100; const char* replayExtention = ".rep"; const char* lastReplayFileName = "00000000"; // a name the user is unlikely to ever type, but won't cause panic & confusion +const char* resumeReplayFileName = "Resume"; // the resume-from-replay source every client replays (see ResumeFromReplay) // TheSuperHackers @tweak helmutbuhler 25/04/2025 // The replay header contains two time fields; startTime and endTime of type time_t. @@ -356,6 +355,7 @@ RecorderClass::RecorderClass() m_originalGameMode = GAME_NONE; m_mode = RECORDERMODETYPE_RECORD; m_file = nullptr; + m_resumeSourceFile = nullptr; m_fileName.clear(); m_currentFilePosition = 0; m_doingAnalysis = FALSE; @@ -395,13 +395,7 @@ void RecorderClass::init() { m_doingAnalysis = FALSE; m_playbackFrameCount = 0; - m_resumeHandoffFrame = 0; - m_resumeSavedFpsLimit = 0; - m_resumeSavedNetFrameRate = 0; - m_resumeRecordPos = 0; - m_resumeRatesRestored = FALSE; - m_resumeFreezeStartMs = 0; - m_resumeFreezeLastAnnounced = -1; + clearResumeState(); OptionPreferences optionPref; m_archiveReplays = optionPref.getArchiveReplaysEnabled(); @@ -426,7 +420,12 @@ void RecorderClass::reset() { */ void RecorderClass::update() { if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) { + // TheSuperHackers @feature bill-rich 15/09/2026 Inject the resume source's commands for this + // frame, then record them like any other frame: the new recording is a normal replay of + // the resumed match from frame 0. The handoff (or an abort) switches the mode inside. updateResumeCatchup(); + if (m_mode != RECORDERMODETYPE_NONE) + updateRecord(); } else if (m_mode == RECORDERMODETYPE_RECORD || m_mode == RECORDERMODETYPE_NONE) { updateRecord(); @@ -512,27 +511,22 @@ void RecorderClass::updateRecord() if (msg->getArgumentCount() >= 4) maxFPS = msg->getArgument(3)->integer; - // TheSuperHackers @feature bill-rich 15/09/2026 If the lobby armed a resume-from-replay, switch into - // catchup instead of starting a fresh recording: catchup opens the replay for - // READ, while startRecording would open it for WRITE and truncate the very - // file we need to read from. Falls back to a normal recording if setup fails. - const GameInfo *armedGame = nullptr; - if (TheLAN != nullptr) - armedGame = TheLAN->GetMyGame(); -#if defined(GENERALS_ONLINE) - else if (TheNGMPGame != nullptr) - armedGame = TheNGMPGame; -#endif - if (armedGame == nullptr) - armedGame = TheGameInfo; - const Bool armedResume = armedGame != nullptr && !armedGame->getResumeReplayFile().isEmpty(); - if (armedResume && startResumeCatchup(armedGame->getResumeReplayFile(), armedGame->getResumeHandoffFrame())) + // TheSuperHackers @feature bill-rich 15/09/2026 The new recording starts as for any game. + // When the lobby's start path armed a resume-from-replay (ResumeFromReplay::prepareGameStart + // validated this client's copy of the source), the source is then replayed into it. + // startRecording resets the recorder, so the arming is carried across by hand. A source + // that cannot be opened leaves the game: a client that silently recorded a fresh match + // would desync everyone else. + const UnsignedInt armedHandoffFrame = m_resumeArmedHandoffFrame; + const UnsignedInt armedSourceLastFrame = m_resumeArmedSourceLastFrame; + startRecording(diff, m_originalGameMode, rankPoints, maxFPS); + if (armedHandoffFrame != 0) { - DEBUG_LOG(("RecorderClass::updateRecord() - resume catchup armed to frame %u", armedGame->getResumeHandoffFrame())); - } - else - { - startRecording(diff, m_originalGameMode, rankPoints, maxFPS); + armResumeForNextGame(armedHandoffFrame, armedSourceLastFrame); + if (startResumeCatchup()) + DEBUG_LOG(("RecorderClass::updateRecord() - resume catchup to frame %u", armedHandoffFrame)); + else + abortResume(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSourceUnreadable", L"Resume aborted: the resume replay could not be opened")); } } else if (msg->getType() == GameMessage::MSG_CLEAR_GAME_DATA) { @@ -543,6 +537,7 @@ void RecorderClass::updateRecord() needFlush = FALSE; } m_fileName.clear(); + clearResumeState(); } else { if (m_file != nullptr) { @@ -1351,8 +1346,8 @@ void RecorderClass::readNextFrame() { if (bytesRead != sizeof(m_nextFrame)) { DEBUG_LOG(("RecorderClass::readNextFrame - read failed on frame %d", TheGameLogic->getFrame())); m_nextFrame = -1; - // Resume-from-replay catchup: running out of recorded frames ends the catchup - // (updateResumeCatchup hands off early), never the live game. + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup: running out of + // records is handled by updateResumeCatchup (which never ends the live game here). if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) return; stopPlayback(); @@ -1361,16 +1356,21 @@ void RecorderClass::readNextFrame() { /** * This reads the next command from the replay file and appends it to TheCommandList. + * TheSuperHackers @feature bill-rich 24/09/2026 Returns FALSE when the record is incomplete (a + * recording cut short by a crash ends in a torn record); the torn record is discarded and + * m_nextFrame is set to -1 so the callers treat it as the end of the usable data. */ -void RecorderClass::appendNextCommand() { +Bool RecorderClass::appendNextCommand() { GameMessage::Type type; Int bytesRead = m_file->read(&type, sizeof(type)); if (bytesRead != sizeof(type)) { DEBUG_LOG(("RecorderClass::appendNextCommand - read failed on frame %d", m_nextFrame/*TheGameLogic->getFrame()*/)); - return; + m_nextFrame = -1; + return FALSE; } GameMessage* msg = newInstance(GameMessage)(type); + Bool complete = TRUE; #ifdef DEBUG_LOGGING AsciiString commandName = msg->getCommandAsString(); @@ -1385,7 +1385,8 @@ void RecorderClass::appendNextCommand() { #endif // DEBUG_LOGGING Int playerIndex = -1; - m_file->read(&playerIndex, sizeof(playerIndex)); + if (m_file->read(&playerIndex, sizeof(playerIndex)) != sizeof(playerIndex)) + complete = FALSE; msg->friend_setPlayerIndex(playerIndex); // don't debug log this if we're debugging sync errors, as it will cause diff problems between a game and it's replay... @@ -1404,14 +1405,17 @@ void RecorderClass::appendNextCommand() { UnsignedByte numTypes = 0; Int totalArgs = 0; - m_file->read(&numTypes, sizeof(numTypes)); + if (complete && m_file->read(&numTypes, sizeof(numTypes)) != sizeof(numTypes)) + complete = FALSE; GameMessageParser* parser = newInstance(GameMessageParser)(); - for (UnsignedByte i = 0; i < numTypes; ++i) { + for (UnsignedByte i = 0; complete && i < numTypes; ++i) { UnsignedByte type = (UnsignedByte)ARGUMENTDATATYPE_UNKNOWN; - m_file->read(&type, sizeof(type)); UnsignedByte numArgs = 0; - m_file->read(&numArgs, sizeof(numArgs)); + if (m_file->read(&type, sizeof(type)) != sizeof(type) || m_file->read(&numArgs, sizeof(numArgs)) != sizeof(numArgs)) { + complete = FALSE; + break; + } parser->addArgType((GameMessageArgumentDataType)type, numArgs); totalArgs += numArgs; } @@ -1423,14 +1427,20 @@ void RecorderClass::appendNextCommand() { lasttype = parserArgType->getType(); argsLeftForType = parserArgType->getArgCount(); } - for (Int j = 0; j < totalArgs; ++j) { - readArgument(lasttype, msg); + for (Int j = 0; complete && j < totalArgs; ++j) { + if (!readArgument(lasttype, msg)) { + complete = FALSE; + break; + } --argsLeftForType; if (argsLeftForType == 0) { DEBUG_ASSERTCRASH(parserArgType != nullptr, ("parserArgType was null when it shouldn't have been.")); if (parserArgType == nullptr) { - return; + deleteInstance(msg); + deleteInstance(parser); + m_nextFrame = -1; + return FALSE; } parserArgType = parserArgType->getNext(); @@ -1442,6 +1452,15 @@ void RecorderClass::appendNextCommand() { } } + if (!complete) + { + DEBUG_LOG(("RecorderClass::appendNextCommand - torn record on frame %d, treating it as the end of the replay", m_nextFrame)); + deleteInstance(msg); + deleteInstance(parser); + m_nextFrame = -1; + return FALSE; + } + if (type != GameMessage::MSG_BEGIN_NETWORK_MESSAGES && type != GameMessage::MSG_CLEAR_GAME_DATA && !m_doingAnalysis) { TheCommandList->appendMessage(msg); @@ -1454,13 +1473,16 @@ void RecorderClass::appendNextCommand() { deleteInstance(parser); parser = nullptr; + return TRUE; } -void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage *msg) { +/// Reads one argument of the given type; FALSE on a short read. +Bool RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage *msg) { switch (type) { case ARGUMENTDATATYPE_INTEGER: { Int theint; - m_file->read(&theint, sizeof(theint)); + if (m_file->read(&theint, sizeof(theint)) != sizeof(theint)) + return FALSE; msg->appendIntegerArgument(theint); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1472,7 +1494,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_REAL: { Real thereal; - m_file->read(&thereal, sizeof(thereal)); + if (m_file->read(&thereal, sizeof(thereal)) != sizeof(thereal)) + return FALSE; msg->appendRealArgument(thereal); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1484,7 +1507,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_BOOLEAN: { Bool thebool; - m_file->read(&thebool, sizeof(thebool)); + if (m_file->read(&thebool, sizeof(thebool)) != sizeof(thebool)) + return FALSE; msg->appendBooleanArgument(thebool); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1496,7 +1520,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_OBJECTID: { ObjectID theid; - m_file->read(&theid, sizeof(theid)); + if (m_file->read(&theid, sizeof(theid)) != sizeof(theid)) + return FALSE; msg->appendObjectIDArgument(theid); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1508,7 +1533,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_DRAWABLEID: { DrawableID theid; - m_file->read(&theid, sizeof(theid)); + if (m_file->read(&theid, sizeof(theid)) != sizeof(theid)) + return FALSE; msg->appendDrawableIDArgument(theid); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1520,7 +1546,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_TEAMID: { UnsignedInt theid; - m_file->read(&theid, sizeof(theid)); + if (m_file->read(&theid, sizeof(theid)) != sizeof(theid)) + return FALSE; msg->appendTeamIDArgument(theid); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1532,7 +1559,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_LOCATION: { Coord3D loc; - m_file->read(&loc, sizeof(loc)); + if (m_file->read(&loc, sizeof(loc)) != sizeof(loc)) + return FALSE; msg->appendLocationArgument(loc); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1545,7 +1573,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_PIXEL: { ICoord2D pixel; - m_file->read(&pixel, sizeof(pixel)); + if (m_file->read(&pixel, sizeof(pixel)) != sizeof(pixel)) + return FALSE; msg->appendPixelArgument(pixel); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1557,7 +1586,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_PIXELREGION: { IRegion2D reg; - m_file->read(®, sizeof(reg)); + if (m_file->read(®, sizeof(reg)) != sizeof(reg)) + return FALSE; msg->appendPixelRegionArgument(reg); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1569,7 +1599,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_TIMESTAMP: { // Not to be confused with Terrance Stamp... Kneel before Zod!!! UnsignedInt stamp; - m_file->read(&stamp, sizeof(stamp)); + if (m_file->read(&stamp, sizeof(stamp)) != sizeof(stamp)) + return FALSE; msg->appendTimestampArgument(stamp); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1581,7 +1612,8 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * } case ARGUMENTDATATYPE_WIDECHAR: { WideChar theid; - m_file->read(&theid, sizeof(theid)); + if (m_file->read(&theid, sizeof(theid)) != sizeof(theid)) + return FALSE; msg->appendWideCharArgument(theid); #ifdef DEBUG_LOGGING if (m_doingAnalysis) @@ -1594,6 +1626,7 @@ void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage * default: break; } + return TRUE; } /** @@ -1788,6 +1821,41 @@ Bool RecorderClass::isMultiplayer() // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay. See Recorder.h for the phase overview. //------------------------------------------------------------------------------------------------- +AsciiString RecorderClass::getResumeReplayFileName() +{ + return AsciiString(resumeReplayFileName); +} + +void RecorderClass::clearResumeState() +{ + if (m_resumeSourceFile != nullptr) + { + m_resumeSourceFile->close(); + m_resumeSourceFile = nullptr; + } + m_resumeArmedHandoffFrame = 0; + m_resumeArmedSourceLastFrame = 0; + m_resumeHandoffFrame = 0; + m_resumeSourceLastFrame = 0; + m_resumeLeadInAnnounced = FALSE; + m_resumeFreezeStartMs = 0; + m_resumeFreezeLastAnnounced = -1; + if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) + m_mode = RECORDERMODETYPE_NONE; +} + +void RecorderClass::armResumeForNextGame(UnsignedInt handoffFrame, UnsignedInt sourceLastFrame) +{ + m_resumeArmedHandoffFrame = handoffFrame; + m_resumeArmedSourceLastFrame = sourceLastFrame; +} + +void RecorderClass::disarmResume() +{ + m_resumeArmedHandoffFrame = 0; + m_resumeArmedSourceLastFrame = 0; +} + Bool RecorderClass::isResumeCatchupLeadIn() const { if (!isResumeCatchupMode()) @@ -1797,60 +1865,79 @@ Bool RecorderClass::isResumeCatchupLeadIn() const return m_resumeHandoffFrame >= leadInFrames && curFrame >= m_resumeHandoffFrame - leadInFrames; } -static UnicodeString formatGameTime(UnsignedInt frames) +/** + * CRC validation is off during catchup (the CRC messages of that window come out of the resume + * source, not from the live peers) and stays off for one full run-ahead after the handoff: a CRC + * generated on frame F is compared on F plus the run-ahead, and every set that could still be + * compared before that was generated while the peers were not exchanging any. + */ +Bool RecorderClass::isResumeCRCValidationSuppressed() const { - const UnsignedInt seconds = frames / LOGICFRAMES_PER_SECOND; - UnicodeString text; - text.format(L"%d:%02d", seconds / 60, seconds % 60); - return text; + if (isResumeCatchupMode()) + return TRUE; + if (m_resumeHandoffFrame == 0 || TheGameLogic == nullptr) + return FALSE; + return TheGameLogic->getFrame() <= m_resumeHandoffFrame + MAX_FRAMES_AHEAD; } /** - * Open the given replay, skip its header, prime the first frame of commands and switch the - * recorder into RECORDERMODETYPE_RESUME_CATCHUP. While in catchup, update() calls - * updateResumeCatchup() instead of updateRecord()/updatePlayback(): the replay's commands are - * injected into TheCommandList each frame while the live network keeps running in lockstep. + * Open the resume source (Resume.rep), skip its header, prime the first frame of commands and + * switch the recorder into RECORDERMODETYPE_RESUME_CATCHUP. startRecording has already opened the + * new recording in m_file and written its header for the live game; the source is read through a + * second handle. While in catchup, update() injects the source's commands into TheCommandList each + * frame and records them, while the live network keeps running in lockstep. */ -Bool RecorderClass::startResumeCatchup(AsciiString filename, UnsignedInt handoffFrame) +Bool RecorderClass::startResumeCatchup() { - if (m_file != nullptr) - { - m_file->close(); - m_file = nullptr; - } - m_mode = RECORDERMODETYPE_NONE; + if (m_file == nullptr || m_resumeArmedHandoffFrame == 0) + return FALSE; + // The read helpers (readReplayHeader, readNextFrame, appendNextCommand) work on m_file: + // point it at the source for the duration and put the recording back afterwards. + File *recordFile = m_file; + m_file = nullptr; ReplayHeader header; header.forPlayback = TRUE; - header.filename = filename; - if (!readReplayHeader(header)) + header.filename = ResumeFromReplay::getSourceFileName(); + const Bool headerOk = readReplayHeader(header); + m_resumeSourceFile = m_file; + m_file = recordFile; + if (!headerOk || m_resumeSourceFile == nullptr) { - DEBUG_LOG(("RecorderClass::startResumeCatchup - readReplayHeader failed for %s", filename.str())); + DEBUG_LOG(("RecorderClass::startResumeCatchup - readReplayHeader failed for %s", header.filename.str())); + if (m_resumeSourceFile != nullptr) + { + m_resumeSourceFile->close(); + m_resumeSourceFile = nullptr; + } return FALSE; } - // playbackFile consumes these four values between the header and the command stream; - // mirror it or readNextFrame reads the difficulty as a frame number. - Int difficulty = 0; - m_file->read(&difficulty, sizeof(difficulty)); - m_file->read(&m_originalGameMode, sizeof(m_originalGameMode)); - Int rankPoints = 0; - m_file->read(&rankPoints, sizeof(rankPoints)); - Int maxFPS = 0; - m_file->read(&maxFPS, sizeof(maxFPS)); + // playbackFile consumes these four values between the header and the command stream + // (difficulty, original game mode, rank points, max FPS); mirror it or readNextFrame reads + // the difficulty as a frame number. + Int skipped[4]; + if (m_resumeSourceFile->read(skipped, sizeof(skipped)) != sizeof(skipped)) + { + m_resumeSourceFile->close(); + m_resumeSourceFile = nullptr; + return FALSE; + } m_mode = RECORDERMODETYPE_RESUME_CATCHUP; - m_resumeHandoffFrame = handoffFrame; - m_currentReplayFilename = filename; - m_resumeRatesRestored = FALSE; + m_resumeHandoffFrame = m_resumeArmedHandoffFrame; + m_resumeSourceLastFrame = m_resumeArmedSourceLastFrame; + m_resumeArmedHandoffFrame = 0; + m_resumeArmedSourceLastFrame = 0; + m_resumeLeadInAnnounced = FALSE; m_resumeFreezeStartMs = 0; m_resumeFreezeLastAnnounced = -1; - // Everything up to here is header. beginRecordingAfterResume keeps the file up to - // m_resumeRecordPos and appends the live game after it. - m_resumeRecordPos = m_file->position(); - + // Prime the first record's frame number (in catchup mode, readNextFrame never ends the game). + m_file = m_resumeSourceFile; readNextFrame(); + m_resumeSourceFile = m_file; + m_file = recordFile; // Nothing may be selected when catchup starts: selection is blocked from here on and // a pre-existing selection would be a way to issue commands with the right mouse button. @@ -1858,38 +1945,27 @@ Bool RecorderClass::startResumeCatchup(AsciiString filename, UnsignedInt handoff { TheInGameUI->deselectAllDrawables(); TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCatchupStart", - L"Resuming from replay: fast-forwarding to %ls", formatGameTime(handoffFrame).str())); + L"Resuming from replay: fast-forwarding to %ls", ResumeFromReplay::formatGameTime(m_resumeHandoffFrame).str())); } - // Two gates cap the logic rate: the render FPS limit and the network's own per-frame - // timing (Network::timeForNewFrame). Raise both; lockstep is unchanged, every frame - // still waits for every peer's commands, just without the realtime pacing. - if (TheFramePacer) - { - m_resumeSavedFpsLimit = TheFramePacer->getFramesPerSecondLimit(); - if (m_resumeSavedFpsLimit <= 0) - m_resumeSavedFpsLimit = LOGICFRAMES_PER_SECOND; // never restore a 0, FrameRateLimit::wait would spin forever - TheFramePacer->setFramesPerSecondLimit(1000); - } - if (TheNetwork) - { - m_resumeSavedNetFrameRate = TheNetwork->setLogicFrameRate(CATCHUP_FRAME_RATE); - } - - RESUME_LOG("Resume: catching up %s to frame %u (lead-in %d s, freeze %d s)", filename.str(), handoffFrame, RESUME_LEADIN_SECONDS, RESUME_FREEZE_SECONDS); + // The realtime pacing is bypassed for the duration by the catchup checks in FramePacer, + // GameEngine and Network (isResumeCatchupMode); lockstep is unchanged, every frame still + // waits for every peer's commands. + RESUME_LOG("Resume: catching up %s to frame %u (source ends at frame %u, lead-in %d s, freeze %d s)", + header.filename.str(), m_resumeHandoffFrame, m_resumeSourceLastFrame, RESUME_LEADIN_SECONDS, RESUME_FREEZE_SECONDS); return TRUE; } /** - * Last frame number recorded in a replay, found by walking its records. The header's frame + * Last frame with a complete record in a replay, found by walking its records. The header's frame * count is only patched in when a recording ends normally, so a recording cut short by a crash - * (the very file a resume is for) reads 0 there. Uses the recorder's analysis mode, in which - * appendNextCommand parses and discards instead of feeding TheCommandList. Lobby use only: - * refuses to run while the recorder has a file open. + * (the very file a resume is for) reads 0 there, and its last record is usually torn. Uses the + * recorder's analysis mode, in which appendNextCommand parses and discards instead of feeding + * TheCommandList. Lobby use only: refuses to run while the recorder has a file open. */ UnsignedInt RecorderClass::scanReplayLastFrame(AsciiString filename) { - if (m_file != nullptr || m_mode != RECORDERMODETYPE_NONE) + if (m_file != nullptr || isPlaybackMode() || isResumeCatchupMode()) return 0; ReplayHeader header; @@ -1900,107 +1976,104 @@ UnsignedInt RecorderClass::scanReplayLastFrame(AsciiString filename) // difficulty, original game mode, rank points, max FPS (see playbackFile) Int skipped[4]; - m_file->read(skipped, sizeof(skipped)); + if (m_file->read(skipped, sizeof(skipped)) != sizeof(skipped)) + { + m_file->close(); + m_file = nullptr; + return 0; + } const Bool savedAnalysis = m_doingAnalysis; m_doingAnalysis = TRUE; UnsignedInt lastFrame = 0; UnsignedInt frame = 0; - while (m_file != nullptr && m_file->read(&frame, sizeof(frame)) == sizeof(frame)) + while (m_file->read(&frame, sizeof(frame)) == sizeof(frame)) { if (frame < lastFrame) break; // torn tail: frame numbers only ever grow + m_nextFrame = frame; + if (!appendNextCommand()) + break; // torn record: everything before it is usable lastFrame = frame; - const Int before = m_file->position(); - appendNextCommand(); - if (m_file == nullptr || m_file->position() == before) - break; // nothing more could be read } - if (m_file != nullptr) - { - m_file->close(); - m_file = nullptr; - } + m_file->close(); + m_file = nullptr; m_doingAnalysis = savedAnalysis; m_nextFrame = (UnsignedInt)-1; - m_mode = RECORDERMODETYPE_NONE; return lastFrame; } /** - * Hand the replay file over from catchup (reading) to recording (writing). The armed file already - * holds the header plus every frame up to the handoff, so keep those bytes and append the live - * game to them: one complete replay of the whole match, and stopRecording() runs at the end with - * everything that hangs off it. Truncates after the last record actually replayed so the old - * tail (already-played frames, the old MSG_CLEAR_GAME_DATA) cannot follow the new commands. + * Read the source's records for curFrame into TheCommandList. Never reads past the last complete + * frame found by scanReplayLastFrame, so a torn tail cannot be replayed, and never past the handoff. */ -Bool RecorderClass::beginRecordingAfterResume() +void RecorderClass::injectResumeCommands(UnsignedInt curFrame) { - if (m_file == nullptr || m_resumeRecordPos <= 0) - return FALSE; - - // Replays are command logs, so the prefix is small; buffer it rather than truncate in place. - const Int prefixLen = m_resumeRecordPos; - char *prefix = NEW char[prefixLen]; - m_file->seek(0, File::seekMode::START); - const Int got = m_file->read(prefix, prefixLen); - m_file->close(); - m_file = nullptr; - - if (got != prefixLen) + File *recordFile = m_file; + m_file = m_resumeSourceFile; + while (m_nextFrame == curFrame && m_nextFrame <= m_resumeSourceLastFrame && curFrame <= m_resumeHandoffFrame) { - DEBUG_LOG(("RecorderClass::beginRecordingAfterResume - short read of replay prefix (%d of %d)", got, prefixLen)); - delete [] prefix; - return FALSE; + if (!appendNextCommand()) + break; // torn record: appendNextCommand marked the end of the usable data + readNextFrame(); + if (m_nextFrame != (UnsignedInt)-1 && m_nextFrame < curFrame) + m_nextFrame = (UnsignedInt)-1; // regression: the file is not the one that was scanned } + m_resumeSourceFile = m_file; + m_file = recordFile; +} - AsciiString fileName = getLastReplayFileName(); - fileName.concat(getReplayExtention()); - - AsciiString filepath = getReplayDir(); - TheFileSystem->createDirectory(filepath); - filepath.concat(fileName); - - // WRITE truncates, which is the truncate-at-prefix we want. - m_file = TheFileSystem->openFile(filepath.str(), File::WRITE | File::BINARY); - if (m_file == nullptr) +/** + * Close the source and leave catchup. The recording of the resumed match goes on in m_file. + */ +void RecorderClass::endResumeCatchup() +{ + if (m_resumeSourceFile != nullptr) { - DEBUG_LOG(("RecorderClass::beginRecordingAfterResume - could not reopen %s for recording", filepath.str())); - delete [] prefix; - return FALSE; + m_resumeSourceFile->close(); + m_resumeSourceFile = nullptr; } + m_nextFrame = (UnsignedInt)-1; + m_resumeSourceLastFrame = 0; + if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) + m_mode = RECORDERMODETYPE_RECORD; +} - m_file->write(prefix, prefixLen); - delete [] prefix; - m_file->flush(); - - m_fileName = fileName; - m_mode = RECORDERMODETYPE_RECORD; - DEBUG_LOG(("RecorderClass::beginRecordingAfterResume - recording resumed game into %s from offset %d", fileName.str(), prefixLen)); - return TRUE; +/** + * The source cannot be replayed to the handoff on this client. Every client validated its copy + * against the handoff before starting, so this is not a shorter-replay case a local handoff could + * paper over (that would desync the peers): tell the player and leave the game, never fall back + * to playing on. + */ +void RecorderClass::abortResume(const UnicodeString &why) +{ + RESUME_LOG("Resume: aborted at frame %u: %ls", TheGameLogic ? TheGameLogic->getFrame() : 0, why.str()); + endResumeCatchup(); + m_resumeHandoffFrame = 0; + m_resumeFreezeStartMs = 0; + if (TheInGameUI) + TheInGameUI->message(why); + if (TheGameLogic) + TheGameLogic->exitGame(); } /** - * Per-frame update for RECORDERMODETYPE_RESUME_CATCHUP: inject the replay's recorded commands - * for the current logic frame, drop the rate caps for the lead-in, and start the freeze when - * the handoff frame is reached (or the replay runs out first). Unlike stopPlayback this does NOT - * call exitGame; the network session continues uninterrupted. + * Per-frame update for RECORDERMODETYPE_RESUME_CATCHUP: inject the source's commands for the + * current logic frame, announce the lead-in, and start the freeze when the handoff frame is reached. + * Unlike stopPlayback this does NOT call exitGame at the handoff; the network session continues. */ void RecorderClass::updateResumeCatchup() { const UnsignedInt curFrame = TheGameLogic ? TheGameLogic->getFrame() : 0; - // Lead-in: back to realtime so players get a normal-speed look at the last seconds - // before the handoff. If the handoff is closer than that to the start, stay fast. - if (!m_resumeRatesRestored && isResumeCatchupLeadIn()) + // Lead-in: the pacing bypasses switch off (isResumeCatchupLeadIn) so players get a + // normal-speed look at the last seconds before the handoff. If the handoff is closer than + // that to the start, it stays fast. + if (!m_resumeLeadInAnnounced && isResumeCatchupLeadIn()) { - m_resumeRatesRestored = TRUE; - if (TheFramePacer) - TheFramePacer->setFramesPerSecondLimit(m_resumeSavedFpsLimit); - if (TheNetwork) - TheNetwork->setLogicFrameRate(m_resumeSavedNetFrameRate); + m_resumeLeadInAnnounced = TRUE; RESUME_LOG("Resume: lead-in reached at frame %u, back to realtime", curFrame); if (TheInGameUI) TheInGameUI->message(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCatchupLeadIn", @@ -2012,36 +2085,12 @@ void RecorderClass::updateResumeCatchup() // and the live network layer writes into the same list each frame. Local input is // blocked at its sources instead (isResumeInputBlocked). - // Inject every command recorded for this frame, including the handoff frame itself: - // GameLogic's CRC validation resumes right after catchup ends and expects the CRC - // messages of that frame to be present. - while (m_nextFrame == curFrame && curFrame <= m_resumeHandoffFrame) - { - appendNextCommand(); - m_resumeRecordPos = m_file->position(); - readNextFrame(); - } + // Inject every command recorded for this frame, including the handoff frame itself. + injectResumeCommands(curFrame); - if (curFrame >= m_resumeHandoffFrame || m_nextFrame == (UnsignedInt)-1) + if (curFrame >= m_resumeHandoffFrame) { - // Take the replay file over for recording rather than dropping it (see above). - if (!beginRecordingAfterResume()) - { - DEBUG_LOG(("RecorderClass::updateResumeCatchup - could not take over the replay file for recording")); - if (m_file != nullptr) - { - m_file->close(); - m_file = nullptr; - } - m_mode = RECORDERMODETYPE_NONE; - } - m_currentReplayFilename.clear(); - - // Restore both rate caps in case the lead-in never happened. - if (TheFramePacer) - TheFramePacer->setFramesPerSecondLimit(m_resumeSavedFpsLimit); - if (TheNetwork) - TheNetwork->setLogicFrameRate(m_resumeSavedNetFrameRate); + endResumeCatchup(); // Hold the simulation with a countdown before control comes back. Network::update // polls updateResumeFreeze() and refuses to advance frames while it returns TRUE. @@ -2049,7 +2098,17 @@ void RecorderClass::updateResumeCatchup() if (m_resumeFreezeStartMs == 0) m_resumeFreezeStartMs = 1; m_resumeFreezeLastAnnounced = -1; - RESUME_LOG("Resume: handoff at frame %u (next replay frame %u), freezing for %d s", curFrame, m_nextFrame, RESUME_FREEZE_SECONDS); + RESUME_LOG("Resume: handoff at frame %u, freezing for %d s", curFrame, RESUME_FREEZE_SECONDS); + return; + } + + // The source's records ended before the last complete frame the scan found: the file is + // not the one that was validated. A local handoff here would desync the peers. + if (m_nextFrame == (UnsignedInt)-1 && curFrame < m_resumeSourceLastFrame) + { + abortResume(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSourceEnded", + L"Resume aborted: the replay ended at %ls, before the handoff at %ls", + ResumeFromReplay::formatGameTime(curFrame).str(), ResumeFromReplay::formatGameTime(m_resumeHandoffFrame).str())); } } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp index 6649a0c9f65..224b5aa037c 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp @@ -33,6 +33,7 @@ #include "Common/FileSystem.h" #include "Common/GameEngine.h" #include "Common/GameState.h" +#include "Common/Recorder.h" #include "Common/GameStateMap.h" #include "Common/LatchRestore.h" #include "Common/MapObject.h" @@ -863,6 +864,7 @@ static AsciiString getMapLeafAndDirName(const AsciiString& in) const char* PORTABLE_SAVE = "Save\\"; const char* PORTABLE_MAPS = "Maps\\"; const char* PORTABLE_USER_MAPS = "UserData\\Maps\\"; +const char* PORTABLE_REPLAYS = "Replays\\"; // TheSuperHackers @feature bill-rich 24/09/2026 the resume-from-replay source travels the map transfer path // ------------------------------------------------------------------------------------------------ AsciiString GameState::realMapPathToPortableMapPath(const AsciiString& in) const @@ -883,6 +885,12 @@ AsciiString GameState::realMapPathToPortableMapPath(const AsciiString& in) const prefix = PORTABLE_USER_MAPS; prefix.concat(getMapLeafAndDirName(in)); } + else if (in.startsWithNoCase(RecorderClass::getReplayDir())) + { + // the replay dir ends with "\\" + prefix = PORTABLE_REPLAYS; + prefix.concat(getMapLeafName(in)); + } else { DEBUG_CRASH(("Map file was not found in any of the expected directories; this is impossible")); @@ -923,6 +931,13 @@ AsciiString GameState::portableMapPathToRealMapPath(const AsciiString& in) const containingBasePath = prefix; prefix.concat(getMapLeafAndDirName(in)); } + else if (in.startsWithNoCase(PORTABLE_REPLAYS)) + { + // the replay dir ends with "\\"; only the leaf name travels, so nothing can escape it + prefix = RecorderClass::getReplayDir(); + containingBasePath = prefix; + prefix.concat(getMapLeafName(in)); + } else { DEBUG_CRASH(("Map file was not found in any of the expected directories; this is impossible")); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index 7e296749cbc..bf8054553c2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -59,9 +59,8 @@ #include "Common/MultiplayerSettings.h" #include "GameClient/GameText.h" #include "GameNetwork/GUIUtil.h" -#include "Common/Recorder.h" -#include "Common/Version.h" #include "GameClient/MapUtil.h" +#include "GameNetwork/ResumeFromReplay.h" extern char *LANnextScreen; @@ -115,7 +114,6 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID; static NameKeyType buttonStartID = NAMEKEY_INVALID; static NameKeyType buttonEmoteID = NAMEKEY_INVALID; static NameKeyType buttonSelectMapID = NAMEKEY_INVALID; -static NameKeyType buttonResumeFromReplayID = NAMEKEY_INVALID; static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID; static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID; static NameKeyType windowMapID = NAMEKEY_INVALID; @@ -124,7 +122,6 @@ static GameWindow *parentLanGameOptions = nullptr; static GameWindow *buttonBack = nullptr; static GameWindow *buttonStart = nullptr; static GameWindow *buttonSelectMap = nullptr; -static GameWindow *buttonResumeFromReplay = nullptr; // optional: only present in updated .wnd layouts static GameWindow *buttonEmote = nullptr; static GameWindow *textEntryChat = nullptr; static GameWindow *textEntryMapDisplay = nullptr; @@ -223,8 +220,9 @@ static void playerTooltip(GameWindow *window, setLANPlayerTooltip(player); } -extern Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); -static Bool armedResumeStillMatches(LANGameInfo *game); +static Bool lanArmedResumeStillMatches(LANGameInfo *game); +static void lanDisarmResumeForSettingsChange(); +static void lanCheckResumeArmChange(LANGameInfo *game); void StartPressed() { LANGameInfo *myGame = TheLAN->GetMyGame(); @@ -266,8 +264,8 @@ void StartPressed() return; } - // An armed resume only works if the lobby still matches the recording. - if (TheLAN->AmIHost() && !myGame->getResumeReplayFile().isEmpty() && !armedResumeStillMatches(myGame)) + // TheSuperHackers @feature bill-rich 15/09/2026 An armed resume-from-replay only works if the lobby still matches the recording. + if (TheLAN->AmIHost() && myGame->isResumeArmed() && !lanArmedResumeStillMatches(myGame)) { return; } @@ -630,6 +628,7 @@ static void handleStartingCashSelection() { if (!s_isIniting) { + lanDisarmResumeForSettingsChange(); // send around the new data TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); lanUpdateSlotList(); // Update the accepted button UI @@ -660,6 +659,7 @@ static void handleLimitSuperweaponsClick() { if (!s_isIniting) { + lanDisarmResumeForSettingsChange(); // send around a new slotlist TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); lanUpdateSlotList(); // Update the accepted button UI @@ -685,24 +685,15 @@ void lanUpdateSlotList() // ----------------------------------------------------------------------------- // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming (host only). // -// The host arms the last recorded replay (00000000.rep); every client in the -// lobby is expected to hold its own recording of that same match under the same -// name. Arming aligns the lobby with the replay (slot order, factions, colors, -// start spots, teams and the replay's seed) and broadcasts the replay name plus -// the handoff frame in the game options (RF= / RHF=). On game start the recorder -// on every client replays that file in lockstep up to the handoff frame before -// live control resumes (see RecorderClass::startResumeCatchup). +// /resume copies the host's last recording to Resume.rep (ResumeFromReplay::prepareHostSource), +// aligns the lobby with it (slot order, factions, colors, start spots, teams, map, seed, +// starting cash and superweapon limit) and broadcasts the handoff frame in the game options +// (RH=). The file itself is pushed to every guest over the map transfer path when the game +// starts (LANAPI::OnGameStart), where every client validates its copy against the lobby +// before the recorder replays it in lockstep (see RecorderClass). // ----------------------------------------------------------------------------- -extern Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); - -// The handoff sits this far before the end of the recording, so a client whose -// recording stopped a little earlier (the one that crashed) still has every frame -// the others will replay. -static const Int RESUME_HANDOFF_SLACK_SECONDS = 10; - -static Bool s_resumeArmed = FALSE; -static UnsignedInt s_resumeArmedHandoffFrame = 0; +static UnsignedInt s_lanLastSeenResumeHandoff = 0; ///< the arm the last game options carried, to notice changes // Everyone in the lobby sees resume messages: the player who has to fix // something (wrong name, wrong slot) is usually not the host. @@ -712,101 +703,27 @@ static void lanSystemChat(const UnicodeString &text) TheLAN->RequestChat(text, LANAPIInterface::LANCHAT_SYSTEM); } -// The lobby must line up with the recording slot for slot: every recorded human in -// the slot they held, under the same name, and nobody else in a recorded slot. -static Bool lobbySlotsMatchReplay(const ReplayGameInfo &replayInfo, const GameInfo *lobby, UnicodeString &why) +static void lanLocalSystemChat(const UnicodeString &text) { - for (Int i = 0; i < MAX_SLOTS; ++i) - { - const GameSlot *rs = replayInfo.getConstSlot(i); - const GameSlot *ls = lobby->getConstSlot(i); - const Bool replayHuman = rs && rs->isHuman(); - const Bool lobbyHuman = ls && ls->isHuman(); - if (replayHuman == lobbyHuman && (!replayHuman || rs->getName().compare(ls->getName()) == 0)) - continue; - if (replayHuman) - why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", - L"Resume: slot %d must be %ls (it was theirs in the recording)", i + 1, rs->getName().str()); - else - why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", - L"Resume: slot %d was not a player in the recording, close it or move %ls", i + 1, ls->getName().str()); - return FALSE; - } - return TRUE; + if (TheLAN) + TheLAN->OnChat(L"SYSTEM", TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM); } -// Called from StartPressed while a resume is armed. Re-reads the recording and refuses -// the start when the lobby has drifted from it since arming (someone left, rejoined -// under another name, or joined into a recorded slot). -static Bool armedResumeStillMatches(LANGameInfo *game) +// Called from StartPressed while a resume is armed. Re-reads the resume source and refuses +// the start when the lobby has drifted from it since arming (someone left, rejoined under +// another name, joined into a recorded slot, or a setting changed). +static Bool lanArmedResumeStillMatches(LANGameInfo *game) { - RecorderClass::ReplayHeader header; - ReplayGameInfo info; - const MapMetaData *mapData = nullptr; + ResumeFromReplay::SourceReplay replay; UnicodeString why; - if (!readReplayMapInfo(game->getResumeReplayFile(), header, info, mapData)) - why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read"); - else if (lobbySlotsMatchReplay(info, game, why)) + if (ResumeFromReplay::readSource(replay, why) + && ResumeFromReplay::sourceMatchesGame(replay, game, game->getResumeHandoffFrame(), why)) return TRUE; - lanSystemChat(why); - lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeStartRefused", - L"Resume is armed and the lobby no longer matches the recording. Fix it, or type /resume off to start a fresh game.")); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeStartRefused", + L"Resume is armed and the lobby no longer matches the recording (%ls). Fix it, or type /resume off to start a fresh game.", why.str())); return FALSE; } -// Every human in the replay must be in the lobby under the same name, the host -// must be the replay's slot-0 player, and nobody extra may be present. -static Bool validateResumeRoster(const ReplayGameInfo &replayInfo, LANGameInfo *lobby, UnicodeString &statusOut) -{ - Int i; - Int replayCount = 0; - Int lobbyCount = 0; - for (i = 0; i < MAX_SLOTS; ++i) - { - const GameSlot *rs = replayInfo.getConstSlot(i); - if (rs && rs->isHuman()) - ++replayCount; - const GameSlot *ls = lobby->getConstSlot(i); - if (ls && ls->isHuman()) - ++lobbyCount; - } - if (replayCount != lobbyCount) - { - statusOut = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCountMismatch", - L"Resume: the lobby has %d players but the replay has %d", lobbyCount, replayCount); - return FALSE; - } - - const GameSlot *replayHost = replayInfo.getConstSlot(0); - const GameSlot *lobbyHost = lobby->getConstSlot(0); - if (!replayHost || !lobbyHost || !replayHost->isHuman() || replayHost->getName().compare(lobbyHost->getName()) != 0) - { - statusOut = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeHostMismatch", - L"Resume: only %ls, the host of the recorded game, can resume it", replayHost ? replayHost->getName().str() : L"?"); - return FALSE; - } - - for (i = 0; i < MAX_SLOTS; ++i) - { - const GameSlot *rs = replayInfo.getConstSlot(i); - if (!rs || !rs->isHuman()) - continue; - Bool found = FALSE; - for (Int j = 0; j < MAX_SLOTS && !found; ++j) - { - const GameSlot *ls = lobby->getConstSlot(j); - found = ls && ls->isHuman() && ls->getName().compare(rs->getName()) == 0; - } - if (!found) - { - statusOut = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMissingPlayer", - L"Resume: %ls is not in the lobby", rs->getName().str()); - return FALSE; - } - } - return TRUE; -} - // Put every human back into the slot they held in the replay and restore the // recorded faction, color, start position and team. Recorded commands are indexed // by slot position, so the lobby must line up with the recording exactly. Slot 0 is @@ -850,15 +767,11 @@ static void reorderLobbyForResume(const ReplayGameInfo &replayInfo, LANGameInfo } } -static void clearResumeArm() +static void lanClearResumeArm() { - s_resumeArmed = FALSE; - s_resumeArmedHandoffFrame = 0; if (TheLAN && TheLAN->GetMyGame()) - { - TheLAN->GetMyGame()->setResumeReplayFile(AsciiString::TheEmptyString); TheLAN->GetMyGame()->setResumeHandoffFrame(0); - } + s_lanLastSeenResumeHandoff = 0; } // "/resume off": disarm and tell the lobby the next start is a fresh game. @@ -866,8 +779,8 @@ static void disarmResumeFromReplay() { if (!TheLAN || !TheLAN->GetMyGame() || !TheLAN->AmIHost()) return; - const Bool wasArmed = !TheLAN->GetMyGame()->getResumeReplayFile().isEmpty(); - clearResumeArm(); + const Bool wasArmed = TheLAN->GetMyGame()->isResumeArmed(); + lanClearResumeArm(); if (wasArmed) { TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); @@ -875,71 +788,76 @@ static void disarmResumeFromReplay() } } -// Validates the last recorded replay against the current lobby and arms it. -// Reports success or the reason for refusal in the lobby chat. -static void tryArmResumeFromReplay() +// A host change to a setting the recording fixes (map, starting cash, superweapon limit) +// disarms; the caller sends the game options right after. +static void lanDisarmResumeForSettingsChange() { - if (!TheLAN || !TheLAN->GetMyGame() || !TheLAN->AmIHost()) + if (!TheLAN || !TheLAN->GetMyGame() || !TheLAN->AmIHost() || !TheLAN->GetMyGame()->isResumeArmed()) return; + lanClearResumeArm(); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmedSettings", L"Resume disarmed: the game settings changed")); +} - AsciiString replayName = TheRecorder->getLastReplayFileName(); - replayName.concat(TheRecorder->getReplayExtention()); - - RecorderClass::ReplayHeader header; - ReplayGameInfo info; - const MapMetaData *mapData = nullptr; - if (!readReplayMapInfo(replayName, header, info, mapData)) - { - lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read")); +// Guests: the arm arrives in the host's game options (RH=). The file itself is sent when the +// game starts, so all a guest can do here is say so, and note a disarm. +static void lanCheckResumeArmChange(LANGameInfo *game) +{ + if (!TheLAN || !game || TheLAN->AmIHost()) return; - } - if (header.versionNumber != TheVersion->getVersionNumber() - || header.exeCRC != TheGlobalData->m_exeCRC - || header.iniCRC != TheGlobalData->m_iniCRC) - { - lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"Resume: the last replay was recorded with a different game version")); + const UnsignedInt handoff = game->getResumeHandoffFrame(); + if (handoff == s_lanLastSeenResumeHandoff) return; - } - // A recording cut short by a crash never had its header frame count patched in. - UnsignedInt frameCount = header.frameCount; - if (frameCount == 0) - frameCount = TheRecorder->scanReplayLastFrame(replayName); - const UnsignedInt slackFrames = RESUME_HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; - if (frameCount <= slackFrames) - { - lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"Resume: the last replay is too short to resume")); + s_lanLastSeenResumeHandoff = handoff; + if (handoff != 0) + lanLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmedGuest", + L"Resume armed by the host: the replay is sent when the game starts and replays to %ls", ResumeFromReplay::formatGameTime(handoff).str())); + else + lanLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); +} + +// Copies the last recorded replay to the resume source, validates it against the current +// lobby, aligns the lobby with it and arms. Reports success or the reason for refusal in +// the lobby chat. +static void tryArmResumeFromReplay() +{ + if (!TheLAN || !TheLAN->GetMyGame() || !TheLAN->AmIHost()) return; - } - if (mapData == nullptr) + LANGameInfo *game = TheLAN->GetMyGame(); + + ResumeFromReplay::SourceReplay replay; + UnsignedInt handoff = 0; + UnicodeString why; + if (!ResumeFromReplay::prepareHostSource(replay, handoff, why) + || !ResumeFromReplay::validateRoster(replay.game, game, why)) { - lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMapMissing", L"Resume: the replay's map is not installed")); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); return; } - UnicodeString status; - if (!validateResumeRoster(info, TheLAN->GetMyGame(), status)) + + reorderLobbyForResume(replay.game, game); + game->setMap(replay.game.getMap()); + game->setMapCRC(replay.game.getMapCRC()); + game->setMapSize(replay.game.getMapSize()); + game->setSeed(replay.game.getSeed()); + game->setStartingCash(replay.game.getStartingCash()); + game->setSuperweaponRestriction(replay.game.getSuperweaponRestriction()); + game->setResumeHandoffFrame(handoff); + + // The options travel in one LAN packet; refuse to arm rather than let the field be cut off. + AsciiString options = GenerateGameOptionsString(); + if (options.getLength() >= m_lanMaxOptionsLength) { - lanSystemChat(status); + lanClearResumeArm(); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeOptionsTooLong", L"Resume: the game options are too long to carry the resume, shorten the player names")); return; } - - LANGameInfo *game = TheLAN->GetMyGame(); - reorderLobbyForResume(info, game); - game->setMap(info.getMap()); - game->setMapCRC(info.getMapCRC()); - game->setMapSize(info.getMapSize()); - game->setSeed(info.getSeed()); - game->setResumeReplayFile(replayName); - game->setResumeHandoffFrame(frameCount - slackFrames); - TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); + TheLAN->RequestGameOptions(options, true); lanUpdateSlotList(); + updateGameOptions(); + s_lanLastSeenResumeHandoff = handoff; - s_resumeArmed = TRUE; - s_resumeArmedHandoffFrame = frameCount - slackFrames; - - UnicodeString armed = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", - L"Resume armed: the next start replays %hs to %d:%02d, then hands control back", - replayName.str(), (s_resumeArmedHandoffFrame / LOGICFRAMES_PER_SECOND) / 60, (s_resumeArmedHandoffFrame / LOGICFRAMES_PER_SECOND) % 60); - TheLAN->RequestChat(armed, LANAPIInterface::LANCHAT_SYSTEM); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", + L"Resume armed: the next start replays the last match to %ls, then hands control back", ResumeFromReplay::formatGameTime(handoff).str())); } void InitLanGameGadgets() @@ -953,7 +871,6 @@ void InitLanGameGadgets() listboxChatWindowLanGameID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ListboxChatWindowLanGame" ); buttonEmoteID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonEmote" ); buttonSelectMapID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonSelectMap" ); - buttonResumeFromReplayID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonResumeFromReplay" ); checkboxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:CheckboxLimitSuperweapons" ); comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ComboBoxStartingCash" ); windowMapID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:MapWindow" ); @@ -964,9 +881,6 @@ void InitLanGameGadgets() buttonEmote = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonEmoteID ); DEBUG_ASSERTCRASH(buttonEmote, ("Could not find the buttonEmote")); buttonSelectMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonSelectMapID ); - buttonResumeFromReplay = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonResumeFromReplayID ); // may be null - if (buttonResumeFromReplay) - buttonResumeFromReplay->winEnable( TheLAN && TheLAN->AmIHost() ); DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap")); buttonStart = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonStartID ); DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart")); @@ -1069,8 +983,7 @@ void InitLanGameGadgets() void DeinitLanGameGadgets() { // Disarm any pending resume so it cannot survive into a future lobby session. - clearResumeArm(); - buttonResumeFromReplay = nullptr; + lanClearResumeArm(); parentLanGameOptions = nullptr; buttonEmote = nullptr; buttonSelectMap = nullptr; @@ -1221,6 +1134,7 @@ void updateGameOptions() { LANGameInfo *theGame = TheLAN->GetMyGame(); UnicodeString mapDisplayName; + lanCheckResumeArmChange(theGame); if (theGame && AreSlotListUpdatesEnabled()) { const GameSlot *localSlot = theGame->getConstSlot(theGame->getLocalSlotNum()); @@ -1538,10 +1452,6 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m mapSelectLayout->bringForward(); } - else if ( controlID == buttonResumeFromReplayID ) - { - tryArmResumeFromReplay(); - } else if ( controlID == buttonStartID ) { if (TheLAN->AmIHost()) @@ -1666,7 +1576,7 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m txtInput.trim(); // Echo the user's input to the chat window if (!txtInput.isEmpty()) - // "/resume" arms resume-from-replay without needing a button in the layout + // TheSuperHackers @feature bill-rich 15/09/2026 "/resume" arms resume-from-replay, "/resume off" disarms if (txtInput.compareNoCase(L"/resume") == 0 || txtInput.compareNoCase(L"/resume off") == 0) { if (!TheLAN->AmIHost()) @@ -1704,6 +1614,7 @@ void PostToLanGameOptions( PostToLanGameType post ) { LANGameInfo *game = TheLAN->GetMyGame(); game->resetAccepted(); + lanDisarmResumeForSettingsChange(); // a new map is not the recording's updateGameOptions(); lanUpdateSlotList(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp index 60bfdc9e768..ce6d0a767e9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp @@ -45,6 +45,7 @@ #include "GameClient/GameWindowManager.h" #include "GameClient/MessageBox.h" #include "GameClient/MapUtil.h" +#include "GameNetwork/ResumeFromReplay.h" #include "GameClient/Mouse.h" #include "GameClient/GameText.h" #include "GameClient/GameWindowTransitions.h" @@ -105,7 +106,7 @@ UnicodeString GetReplayFilenameFromListbox(GameWindow *listbox, Int index) //------------------------------------------------------------------------------------------------- -// TheSuperHackers @refactor bill-rich 15/09/2026 No longer static: the LAN lobby's resume-from-replay arming reads replay headers too. +// TheSuperHackers @refactor bill-rich 15/09/2026 No longer static: resume-from-replay reads replay headers too (declared in ResumeFromReplay.h). Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData) { header.forPlayback = FALSE; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index 660ebc8ce81..16c0f9f06d5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -53,8 +53,7 @@ #include "GameClient/GadgetStaticText.h" #include "GameClient/GadgetCheckBox.h" #include "GameClient/MapUtil.h" -#include "Common/Recorder.h" -#include "Common/Version.h" +#include "GameNetwork/ResumeFromReplay.h" #include "GameClient/EstablishConnectionsMenu.h" #include "GameClient/GameWindowTransitions.h" #include "GameNetwork/GameSpy/LobbyUtils.h" @@ -980,13 +979,15 @@ static void WOLLockSettings() } static Bool wolArmedResumeStillMatches(NGMPGame *game); +static void wolCheckResumeArmChange(); static void StartPressed() { - // An armed resume only works if the lobby still matches the recording. + // TheSuperHackers @feature bill-rich 15/09/2026 An armed resume-from-replay only works if the lobby still + // matches the recording and every human holds the resume source. { NGMP_OnlineServices_LobbyInterface* pResumeLobby = NGMP_OnlineServicesManager::GetInterface(); NGMPGame *resumeGame = pResumeLobby ? pResumeLobby->GetCurrentGame() : nullptr; - if (resumeGame != nullptr && !resumeGame->getResumeReplayFile().isEmpty() && !wolArmedResumeStillMatches(resumeGame)) + if (resumeGame != nullptr && resumeGame->isResumeArmed() && !wolArmedResumeStillMatches(resumeGame)) return; } Bool isReady = TRUE; @@ -1609,17 +1610,18 @@ void WOLDisplaySlotList(void) // ----------------------------------------------------------------------------- // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming for online lobbies (host only). // -// Same contract as the LAN lobby (LanGameOptionsMenu.cpp): the host arms the last -// recorded replay, every member is expected to hold their own recording of that -// match, and on game start the recorder replays it in lockstep up to the handoff -// frame before live control resumes. Online the slot order is owned by the -// service, so the lobby must already match the replay's slot order; the host is -// told exactly what differs instead of the lobby being reordered. +// Same contract as the LAN lobby (LanGameOptionsMenu.cpp): /resume copies the host's last +// recording to Resume.rep and aligns the lobby with it. Online the file is uploaded to the +// service first and the arm (handoff frame plus the replay's seed) is sent only once the +// upload finished; guests download the file when the arm reaches them, report in chat +// whether it matches and flag themselves as holding it, and the host cannot start until +// every human holds it. Slot order is owned by the service, so the lobby must already +// match the replay's slot order; the host is told what differs instead of the lobby +// being reordered. // ----------------------------------------------------------------------------- -extern Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData); - -static const Int WOL_RESUME_HANDOFF_SLACK_SECONDS = 10; +static UnsignedInt s_wolLastSeenResumeHandoff = 0; ///< the arm the last lobby update carried, to notice changes +static Bool s_wolResumeArmInProgress = FALSE; ///< an upload plus arm is under way static void wolLocalSystemChat(const UnicodeString &text) { @@ -1639,45 +1641,35 @@ static void wolLobbySystemChat(const UnicodeString &text) wolLocalSystemChat(text); } -// The lobby must line up with the recording slot for slot (the service owns slot -// order, so nothing here reorders anything). -static Bool wolLobbySlotsMatchReplay(const ReplayGameInfo &replayInfo, const GameInfo *lobby, UnicodeString &why) +// Called on the host's start while a resume is armed: refuse when the lobby has drifted +// from the recording since arming, or when a human does not hold the resume source yet. +static Bool wolArmedResumeStillMatches(NGMPGame *game) { - for (Int i = 0; i < MAX_SLOTS; ++i) + ResumeFromReplay::SourceReplay replay; + UnicodeString why; + if (!ResumeFromReplay::readSource(replay, why) + || !ResumeFromReplay::sourceMatchesGame(replay, game, game->getResumeHandoffFrame(), why)) { - const GameSlot *rs = replayInfo.getConstSlot(i); - const GameSlot *ls = lobby->getConstSlot(i); - const Bool replayHuman = rs && rs->isHuman(); - const Bool lobbyHuman = ls && ls->isHuman(); - if (replayHuman == lobbyHuman && (!replayHuman || rs->getName().compare(ls->getName()) == 0)) - continue; - if (replayHuman) - why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", - L"Resume: slot %d must be %ls (it was theirs in the recording)", i + 1, rs->getName().str()); - else - why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", - L"Resume: slot %d was not a player in the recording, close it or move %ls", i + 1, ls->getName().str()); + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeStartRefused", + L"Resume is armed and the lobby no longer matches the recording (%ls). Fix it, or type /resume off to start a fresh game.", why.str())); return FALSE; } - return TRUE; -} -// Called on the host's start while a resume is armed: refuse when the lobby has -// drifted from the recording since arming. -static Bool wolArmedResumeStillMatches(NGMPGame *game) -{ - RecorderClass::ReplayHeader header; - ReplayGameInfo info; - const MapMetaData *mapData = nullptr; - UnicodeString why; - if (!readReplayMapInfo(game->getResumeReplayFile(), header, info, mapData)) - why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read"); - else if (wolLobbySlotsMatchReplay(info, game, why)) - return TRUE; - wolLobbySystemChat(why); - wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeStartRefused", - L"Resume is armed and the lobby no longer matches the recording. Fix it, or type /resume off to start a fresh game.")); - return FALSE; + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + if (pLobbyInterface != nullptr) + { + for (const LobbyMemberEntry &member : pLobbyInterface->GetCurrentLobby().members) + { + if (member.IsHuman() && !member.has_resume_replay) + { + UnicodeString name(from_utf8(member.display_name).c_str()); + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeWaitingForDownload", + L"Resume: waiting for %ls to download the replay", name.str())); + return FALSE; + } + } + } + return TRUE; } static void wolTryArmResumeFromReplay(Bool disarm) @@ -1694,61 +1686,64 @@ static void wolTryArmResumeFromReplay(Bool disarm) if (disarm) { - pLobbyInterface->UpdateCurrentLobby_ArmResume(std::string(), 0, game->getSeed()); - UnicodeString msg = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game"); - pLobbyInterface->SendAnnouncementMessageToCurrentLobby(msg, true); + pLobbyInterface->UpdateCurrentLobby_ArmResume(0, game->getSeed(), [](bool bSuccess) + { + if (bSuccess) + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); + else + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmRefused", L"Resume: the service refused the request")); + }); + return; + } + if (s_wolResumeArmInProgress) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploadInProgress", L"Resume: the replay is still being uploaded")); return; } - AsciiString replayName = TheRecorder->getLastReplayFileName(); - replayName.concat(TheRecorder->getReplayExtention()); - - RecorderClass::ReplayHeader header; - ReplayGameInfo info; - const MapMetaData *mapData = nullptr; - if (!readReplayMapInfo(replayName, header, info, mapData)) + ResumeFromReplay::SourceReplay replay; + UnsignedInt handoff = 0; + UnicodeString why; + if (!ResumeFromReplay::prepareHostSource(replay, handoff, why)) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"Resume: the last replay could not be read")); + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); return; } - if (header.versionNumber != TheVersion->getVersionNumber() - || header.exeCRC != TheGlobalData->m_exeCRC - || header.iniCRC != TheGlobalData->m_iniCRC) + const ReplayGameInfo &rg = replay.game; + + // The service owns the map, cash and superweapon settings (and clears an arm when they + // change), so they must already match the recording rather than be set here. + if (game->getMap().compareNoCase(rg.getMap()) != 0) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"Resume: the last replay was recorded with a different game version")); + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMapMismatchOnline", + L"Resume: select the replay's map first (%hs)", rg.getMap().str())); return; } - // A recording cut short by a crash never had its header frame count patched in. - UnsignedInt frameCount = header.frameCount; - if (frameCount == 0) - frameCount = TheRecorder->scanReplayLastFrame(replayName); - const UnsignedInt slackFrames = WOL_RESUME_HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; - if (frameCount <= slackFrames) + if (game->getStartingCash().countMoney() != rg.getStartingCash().countMoney()) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"Resume: the last replay is too short to resume")); + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCashMismatchOnline", + L"Resume: set the starting cash to %u first", rg.getStartingCash().countMoney())); return; } - if (mapData == nullptr || game->getMap().compareNoCase(info.getMap()) != 0) + if (game->getSuperweaponRestriction() != rg.getSuperweaponRestriction()) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMapMismatch", - L"Resume: select the replay's map first (%hs)", info.getMap().str())); + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSuperweaponMismatchOnline", + L"Resume: set the superweapon limit to match the recording first")); return; } // Every human must sit in the slot they held in the replay; slot order is the // service's, so tell the lobby the first difference instead of reordering. - UnicodeString why; - if (!wolLobbySlotsMatchReplay(info, game, why)) + if (!ResumeFromReplay::validateRoster(rg, game, why) || !ResumeFromReplay::slotsMatch(rg, game, why)) { - wolLobbySystemChat(why); + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); return; } - // Restore the recorded faction, color, start position and team on every human - // slot, then arm. The service takes the replay's seed as the lobby seed. + // Restore the recorded faction, color, start position and team on every human slot. for (Int i = 0; i < MAX_SLOTS; ++i) { - const GameSlot *rs = info.getConstSlot(i); + const GameSlot *rs = rg.getConstSlot(i); GameSlot *ls = game->getSlot(i); if (!rs || !rs->isHuman() || !ls || !ls->isHuman()) continue; @@ -1758,19 +1753,82 @@ static void wolTryArmResumeFromReplay(Bool disarm) ls->setTeamNumber(rs->getTeamNumber()); } pLobbyInterface->UpdateCurrentLobby_BulkSlotUpdate(game); - const UnsignedInt handoff = frameCount - slackFrames; - pLobbyInterface->UpdateCurrentLobby_ArmResume(std::string(replayName.str()), handoff, info.getSeed()); WOLDisplaySlotList(); - UnicodeString armed = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", - L"Resume armed: the next start replays %hs to %d:%02d, then hands control back", - replayName.str(), (handoff / LOGICFRAMES_PER_SECOND) / 60, (handoff / LOGICFRAMES_PER_SECOND) % 60); - pLobbyInterface->SendAnnouncementMessageToCurrentLobby(armed, true); + // Upload the source, then arm; the arm is announced only once the service accepted it. + const UnsignedInt handoffFrame = handoff; + const Int seed = rg.getSeed(); + s_wolResumeArmInProgress = TRUE; + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploading", L"Resume: uploading the replay to the service...")); + pLobbyInterface->UploadResumeReplay(ResumeFromReplay::getSourceFilePath(), [handoffFrame, seed](bool bUploaded) + { + NGMP_OnlineServices_LobbyInterface* pLobby = NGMP_OnlineServicesManager::GetInterface(); + if (!bUploaded || pLobby == nullptr) + { + s_wolResumeArmInProgress = FALSE; + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploadFailed", L"Resume: the replay upload failed, not armed")); + return; + } + pLobby->UpdateCurrentLobby_ArmResume(handoffFrame, seed, [handoffFrame](bool bArmed) + { + s_wolResumeArmInProgress = FALSE; + NGMP_OnlineServices_LobbyInterface* pLobby2 = NGMP_OnlineServicesManager::GetInterface(); + if (!bArmed || pLobby2 == nullptr) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmRefused", L"Resume: the service refused the request")); + return; + } + s_wolLastSeenResumeHandoff = handoffFrame; + pLobby2->UpdateCurrentLobby_HasResumeReplay(true); // the host holds the source by definition + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", + L"Resume armed: the next start replays the last match to %ls, then hands control back", ResumeFromReplay::formatGameTime(handoffFrame).str())); + }); + }); +} + +// Every lobby update: a guest that sees the arm appear downloads the source, tells the +// lobby whether its copy matches and flags itself; everyone notes a disarm. +static void wolCheckResumeArmChange() +{ + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + NGMPGame *game = pLobbyInterface == nullptr ? nullptr : pLobbyInterface->GetCurrentGame(); + if (game == nullptr) + return; + const UnsignedInt handoff = game->getResumeHandoffFrame(); + if (handoff == s_wolLastSeenResumeHandoff) + return; + s_wolLastSeenResumeHandoff = handoff; + if (handoff == 0) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); + return; + } + if (pLobbyInterface->IsHost()) + return; // the host announced it and holds the source + + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDownloading", L"Resume: downloading the replay from the service...")); + pLobbyInterface->DownloadResumeReplay(ResumeFromReplay::getSourceFilePath(), [](bool bDownloaded) + { + NGMP_OnlineServices_LobbyInterface* pLobby = NGMP_OnlineServicesManager::GetInterface(); + NGMPGame *lobbyGame = pLobby == nullptr ? nullptr : pLobby->GetCurrentGame(); + if (pLobby == nullptr || lobbyGame == nullptr) + return; + UnicodeString report; + Bool usable = FALSE; + if (!bDownloaded) + report = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDownloadFailed", L"Resume: the replay download failed"); + else + usable = ResumeFromReplay::guestSourceReport(lobbyGame, report); + pLobby->SendChatMessageToCurrentLobby(report, false); + pLobby->UpdateCurrentLobby_HasResumeReplay(usable); + }); } void InitWOLGameGadgets() { ClearGSMessageBoxes(); + s_wolLastSeenResumeHandoff = 0; + s_wolResumeArmInProgress = FALSE; NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); NGMPGame* theGameInfo = pLobbyInterface == nullptr ? nullptr : pLobbyInterface->GetCurrentGame(); @@ -2177,6 +2235,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) { WOLDisplaySlotList(); WOLDisplayGameOptions(); + wolCheckResumeArmChange(); // TheSuperHackers @feature bill-rich 24/09/2026 resume-from-replay arm arrived or left }); pLobbyInterface->RegisterForGameStartPacket([]() @@ -3809,7 +3868,7 @@ Bool handleGameSetupSlashCommands(UnicodeString uText) #if defined(GENERALS_ONLINE) else if (token == "resume") { - // resume-from-replay arming lives behind a chat command so no layout change is needed + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming lives behind a chat command so no layout change is needed AsciiString arg; remainder.nextToken(&arg); arg.toLower(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp index 629a9b734c3..01205acccc0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp @@ -3292,6 +3292,7 @@ Coord2D InGameUI::getScrollAmount() //------------------------------------------------------------------------------------------------- void InGameUI::setGUICommand(const CommandButton* command) { + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup: no GUI commands until control is handed back if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK || TheRecorder->isResumeInputBlocked()) return; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index b0ce329ad51..4429ad5eeb1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -2781,12 +2781,12 @@ void GameLogic::processCommandList(CommandList* list) } // TheSuperHackers @feature bill-rich 15/09/2026 Skip CRC validation while in resume-from-replay - // catchup: the CRC messages of that window come out of every client's own copy - // of the replay, not from the live peers. Validation resumes at handoff when - // the recorder leaves catchup mode. - const Bool inCatchup = (TheRecorder && TheRecorder->isResumeCatchupMode()); + // catchup (the CRC messages of that window come out of the resume source, not from the + // live peers) and for one run-ahead after the handoff, until the first set the peers + // exchanged live can have arrived. + const Bool resumeSuppressed = (TheRecorder && TheRecorder->isResumeCRCValidationSuppressed()); - if (m_shouldValidateCRCs && !TheNetwork->sawCRCMismatch() && !inCatchup) + if (m_shouldValidateCRCs && !TheNetwork->sawCRCMismatch() && !resumeSuppressed) { Bool sawCRCMismatch = FALSE; Int numPlayers = 0; diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index fe74aefbc6b..da8f8b3f4a9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -9,6 +9,7 @@ #include "Common/RandomValue.h" #include "GameNetwork/GeneralsOnline/NGMP_interfaces.h" #include "GameNetwork/NetworkInterface.h" +#include "GameNetwork/ResumeFromReplay.h" #include "Common/GlobalData.h" #include "GameClient/View.h" #include "../NextGenMP_defines.h" @@ -115,8 +116,7 @@ void NGMPGame::SyncWithLobby(LobbyEntry& lobby) // rng seed setSeed(lobby.rng_seed); - // resume-from-replay arming (see RecorderClass::startResumeCatchup) - setResumeReplayFile(AsciiString(lobby.resume_replay_file.c_str())); + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (see ResumeFromReplay) setResumeHandoffFrame(lobby.resume_handoff_frame); // observers @@ -514,6 +514,27 @@ void NGMPGame::launchGame(void) return; } + // TheSuperHackers @feature bill-rich 24/09/2026 An armed resume-from-replay needs this client's copy + // of the resume source to match the lobby; when it does not, back out the same way as for a + // missing map rather than start a fresh match that would desync everyone. + UnicodeString resumeWhy; + if (!ResumeFromReplay::prepareGameStart(this, resumeWhy)) + { + DEBUG_LOG(("Resume-from-replay validation failed. Bailing...\n")); + if (TheNetwork != NULL) { + delete TheNetwork; + TheNetwork = NULL; + } + NGMP_OnlineServices_LobbyInterface* pResumeLobby = NGMP_OnlineServicesManager::GetInterface(); + if (pResumeLobby != nullptr) + pResumeLobby->SendAnnouncementMessageToCurrentLobby(resumeWhy, true); + GSMessageBoxOk(TheGameText->fetch("GUI:Error"), resumeWhy); + + void PopBackToLobby(void); + PopBackToLobby(); + return; + } + // Force camera to update from config TheTacticalView->setDefaultView(DEG_TO_RADF(TheGlobalData->m_cameraPitch), DEG_TO_RADF(TheGlobalData->m_cameraYaw), diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index db69b5c32b9..e3f424ec5d7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -76,9 +76,50 @@ enum class ELobbyUpdateField MAX_CAMERA_HEIGHT = 17, JOINABILITY = 18, HOST_ACTION_BULK_SLOT_UPDATE = 19, - HOST_ACTION_ARM_RESUME = 20 + HOST_ACTION_ARM_RESUME = 20, // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (see ResumeFromReplay) + LOCAL_PLAYER_HAS_RESUME_REPLAY = 21 // TheSuperHackers @feature bill-rich 24/09/2026 this member holds a usable copy of the resume source }; +std::string Base64Encode(const std::vector& data); +std::vector Base64Decode(const std::string& encodedData); + +namespace +{ + // Resume-from-replay source transfer: replays are command logs, a long match is a few MB. + const size_t RESUME_REPLAY_CHUNK_BYTES = 256 * 1024; + const size_t RESUME_REPLAY_MAX_BYTES = 16 * 1024 * 1024; + + std::vector ReadWholeFile(const char* path) + { + std::vector bytes; + FILE* fp = fopen(path, "rb"); + if (fp == nullptr) + return bytes; + if (fseek(fp, 0, SEEK_END) == 0) + { + const long len = ftell(fp); + if (len > 0 && fseek(fp, 0, SEEK_SET) == 0) + { + bytes.resize((size_t)len); + const size_t n = fread(bytes.data(), 1, bytes.size(), fp); + bytes.resize(n); + } + } + fclose(fp); + return bytes; + } + + bool WriteWholeFile(const char* path, const std::vector& bytes) + { + FILE* fp = fopen(path, "wb"); + if (fp == nullptr) + return false; + const size_t n = fwrite(bytes.data(), 1, bytes.size(), fp); + fclose(fp); + return n == bytes.size(); + } +} + void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers) { // reset autostart if host changes anything (because ready flag will reset too) @@ -537,11 +578,13 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_BulkSlotUpdate(NGMPG }); } -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: arm (or, with an empty file, disarm) the -// replay every member holds a copy of. The service stores the file name and handoff -// frame on the lobby and takes the replay's seed as the lobby seed, so the next start -// replays that file in lockstep before live control resumes. -void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ArmResume(const std::string& replayFile, uint32_t handoffFrame, int rngSeed) +// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: arm (handoff 0 disarms) the resume source +// the host uploaded. The service stores the handoff frame on the lobby and takes the replay's seed +// as the lobby seed, so the next start replays that file in lockstep before live control resumes. +// The caller announces the arm only from the success callback: the service refuses an arm without +// an uploaded source or with a bad frame, and a lobby that announced an arm it does not hold +// would start a fresh match on every guest. +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ArmResume(uint32_t handoffFrame, int rngSeed, std::function onComplete) { // reset autostart if host changes anything (because ready flag will reset too) #if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) @@ -555,17 +598,162 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ArmResume(const std: nlohmann::json j; j["field"] = ELobbyUpdateField::HOST_ACTION_ARM_RESUME; - j["replay_file"] = replayFile; j["handoff_frame"] = handoffFrame; j["rng_seed"] = rngSeed; std::string strPostData = j.dump(); - NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [onComplete](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + { + bool bArmed = bSuccess && statusCode >= 200 && statusCode < 300; + if (bArmed) + { + try + { + nlohmann::json jResp = nlohmann::json::parse(strBody); + bArmed = jResp.value("success", false); + } + catch (...) + { + bArmed = false; + } + } + if (!bArmed) + { + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_ArmResume failed: success=%d, status=%d", bSuccess, statusCode); + } + if (onComplete != nullptr) + { + onComplete(bArmed); + } + }); +} + +// TheSuperHackers @feature bill-rich 24/09/2026 Whether this member holds a usable copy of the resume source; +// the host's start is refused until every human does (the way has_map gates the map). +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_HasResumeReplay(bool bHasResumeReplay) +{ + std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), m_CurrentLobby.lobbyID); + std::map mapHeaders; + + nlohmann::json j; + j["field"] = ELobbyUpdateField::LOCAL_PLAYER_HAS_RESUME_REPLAY; + j["has_resume_replay"] = bHasResumeReplay; + std::string strPostData = j.dump(); + + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) { if (!bSuccess || statusCode < 200 || statusCode >= 300) { - DEBUG_LOG(("UpdateCurrentLobby_ArmResume failed: success=%d, status=%d", bSuccess, statusCode)); + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_HasResumeReplay failed: success=%d, status=%d", bSuccess, statusCode); + } + }); +} + +// TheSuperHackers @feature bill-rich 24/09/2026 Host: push the resume source to the service in chunks (the +// service keeps it in memory with the lobby). The first chunk (offset 0) replaces whatever the lobby held. +void NGMP_OnlineServices_LobbyInterface::UploadResumeReplay(const AsciiString& path, std::function onComplete) +{ + std::vector bytes = ReadWholeFile(path.str()); + if (bytes.empty() || bytes.size() > RESUME_REPLAY_MAX_BYTES) + { + NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: %s is empty or too large (%u bytes)", path.str(), (unsigned)bytes.size()); + if (onComplete != nullptr) + onComplete(false); + return; + } + NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: uploading %s (%u bytes)", path.str(), (unsigned)bytes.size()); + SendResumeReplayChunk(m_CurrentLobby.lobbyID, std::make_shared>(std::move(bytes)), 0, onComplete); +} + +void NGMP_OnlineServices_LobbyInterface::SendResumeReplayChunk(int64_t lobbyID, std::shared_ptr> data, size_t offset, std::function onComplete) +{ + if (offset >= data->size()) + { + if (onComplete != nullptr) + onComplete(true); + return; + } + const size_t remaining = data->size() - offset; + const size_t len = remaining < RESUME_REPLAY_CHUNK_BYTES ? remaining : RESUME_REPLAY_CHUNK_BYTES; // (std::min collides with the Windows min macro here) + std::vector chunk(data->begin() + offset, data->begin() + offset + len); + + std::string strURI = std::format("{}/{}/resume_replay", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), lobbyID); + std::map mapHeaders; + + nlohmann::json j; + j["offset"] = offset; + j["total"] = data->size(); + j["data"] = Base64Encode(chunk); + std::string strPostData = j.dump(); + + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [this, lobbyID, data, offset, len, onComplete](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + { + if (!bSuccess || statusCode != 200 || m_CurrentLobby.lobbyID != lobbyID) + { + NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: chunk at %u failed (success=%d, status=%d)", (unsigned)offset, bSuccess, statusCode); + if (onComplete != nullptr) + onComplete(false); + return; + } + SendResumeReplayChunk(lobbyID, data, offset + len, onComplete); + }); +} + +// TheSuperHackers @feature bill-rich 24/09/2026 Guest: pull the resume source back from the service into the +// replay directory, in the chunks the service serves. +void NGMP_OnlineServices_LobbyInterface::DownloadResumeReplay(const AsciiString& path, std::function onComplete) +{ + NetworkLog(ELogVerbosity::LOG_RELEASE, "DownloadResumeReplay: downloading to %s", path.str()); + FetchResumeReplayChunk(m_CurrentLobby.lobbyID, path, std::make_shared>(), onComplete); +} + +void NGMP_OnlineServices_LobbyInterface::FetchResumeReplayChunk(int64_t lobbyID, AsciiString path, std::shared_ptr> data, std::function onComplete) +{ + std::string strURI = std::format("{}/{}/resume_replay?from={}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), lobbyID, data->size()); + std::map mapHeaders; + + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendGETRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, [this, lobbyID, path, data, onComplete](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + { + bool bDone = false; + bool bOK = false; + if (bSuccess && statusCode == 200 && m_CurrentLobby.lobbyID == lobbyID) + { + try + { + nlohmann::json jResp = nlohmann::json::parse(strBody); + const int64_t total = jResp.value("total", (int64_t)0); + const std::string strData = jResp.value("data", std::string()); + if (jResp.value("success", false) && total > 0 && (int64_t)total <= (int64_t)RESUME_REPLAY_MAX_BYTES) + { + if (!strData.empty()) + { + std::vector bytes = Base64Decode(strData); + data->insert(data->end(), bytes.begin(), bytes.end()); + } + if ((int64_t)data->size() < total && !strData.empty()) + { + FetchResumeReplayChunk(lobbyID, path, data, onComplete); + return; // more to come + } + bDone = true; + bOK = (int64_t)data->size() == total && WriteWholeFile(path.str(), *data); + } + } + catch (...) + { + bOK = false; + } + } + if (!bOK) + { + NetworkLog(ELogVerbosity::LOG_RELEASE, "DownloadResumeReplay: failed at %u bytes (success=%d, status=%d, done=%d)", (unsigned)data->size(), bSuccess, statusCode, bDone); + } + else + { + NetworkLog(ELogVerbosity::LOG_RELEASE, "DownloadResumeReplay: wrote %u bytes to %s", (unsigned)data->size(), path.str()); } + if (onComplete != nullptr) + onComplete(bOK); }); } @@ -997,9 +1185,7 @@ void NGMP_OnlineServices_LobbyInterface::UpdateRoomDataCache(std::function. +*/ + +// TheSuperHackers @feature bill-rich 24/09/2026 Resume-from-replay arming and validation. See the header. + +#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine + +#include "GameNetwork/ResumeFromReplay.h" + +#include "Common/GlobalData.h" +#include "Common/Version.h" +#include "GameClient/GameText.h" +#include "GameClient/MapUtil.h" +#include "GameNetwork/GameInfo.h" + +namespace ResumeFromReplay +{ + +AsciiString getSourceFileName() +{ + AsciiString name = RecorderClass::getResumeReplayFileName(); + name.concat(RecorderClass::getReplayExtention()); + return name; +} + +AsciiString getSourceFilePath() +{ + AsciiString path = RecorderClass::getReplayDir(); + path.concat(getSourceFileName()); + return path; +} + +UnicodeString formatGameTime(UnsignedInt frames) +{ + const UnsignedInt seconds = frames / LOGICFRAMES_PER_SECOND; + UnicodeString text; + text.format(L"%u:%02u", seconds / 60, seconds % 60); + return text; +} + +Bool readSource(SourceReplay &out, UnicodeString &why) +{ + out.mapData = nullptr; + out.lastFrame = 0; + if (TheRecorder == nullptr || !readReplayMapInfo(getSourceFileName(), out.header, out.game, out.mapData)) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"the resume replay could not be read"); + return FALSE; + } + if (out.header.versionNumber != TheVersion->getVersionNumber() + || out.header.exeCRC != TheGlobalData->m_exeCRC + || out.header.iniCRC != TheGlobalData->m_iniCRC) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeVersionMismatch", L"the resume replay was recorded with a different game version"); + return FALSE; + } + // The header's frame count is only patched in when a recording ends normally, so a recording + // cut short by a crash (the very file a resume is for) reads 0 there, and a torn tail may hold + // fewer complete records than the count says. Walk the records either way. + out.lastFrame = TheRecorder->scanReplayLastFrame(getSourceFileName()); + return TRUE; +} + +static Bool computeHandoffFrame(UnsignedInt lastFrame, UnsignedInt &handoffOut, UnicodeString &why) +{ + const UnsignedInt slackFrames = HANDOFF_SLACK_SECONDS * LOGICFRAMES_PER_SECOND; + if (lastFrame <= slackFrames) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeTooShort", L"the last replay is too short to resume"); + return FALSE; + } + handoffOut = lastFrame - slackFrames; + return TRUE; +} + +Bool prepareHostSource(SourceReplay &out, UnsignedInt &handoffFrame, UnicodeString &why) +{ + if (TheRecorder == nullptr) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHeaderUnreadable", L"the resume replay could not be read"); + return FALSE; + } + + AsciiString lastReplay = RecorderClass::getReplayDir(); + lastReplay.concat(RecorderClass::getLastReplayFileName()); + lastReplay.concat(RecorderClass::getReplayExtention()); + const AsciiString source = getSourceFilePath(); + if (!CopyFile(lastReplay.str(), source.str(), FALSE)) + { + DEBUG_LOG(("ResumeFromReplay::prepareHostSource - could not copy %s to %s", lastReplay.str(), source.str())); + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeCopyFailed", L"the last replay could not be copied to the resume replay"); + return FALSE; + } + + if (!readSource(out, why)) + return FALSE; + if (out.mapData == nullptr) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMapMissing", L"the replay's map is not installed"); + return FALSE; + } + return computeHandoffFrame(out.lastFrame, handoffFrame, why); +} + +// The lobby must line up with the recording slot for slot: every recorded human in the slot +// they held, under the same name, and nobody else in a recorded slot. Recorded commands are +// indexed by slot position, so this is what keeps the replayed commands attached to the +// right players. +Bool slotsMatch(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why) +{ + for (Int i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replay.getConstSlot(i); + const GameSlot *ls = lobby->getConstSlot(i); + const Bool replayHuman = rs && rs->isHuman(); + const Bool lobbyHuman = ls && ls->isHuman(); + if (replayHuman == lobbyHuman && (!replayHuman || rs->getName().compare(ls->getName()) == 0)) + continue; + if (replayHuman) + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", + L"slot %d must be %ls (it was theirs in the recording)", i + 1, rs->getName().str()); + else + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", + L"slot %d was not a player in the recording, close it or move %ls", i + 1, ls->getName().str()); + return FALSE; + } + return TRUE; +} + +Bool sourceMatchesGame(const SourceReplay &replay, const GameInfo *game, UnsignedInt handoffFrame, UnicodeString &why) +{ + if (game == nullptr) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeNoLobby", L"there is no lobby to compare the replay with"); + return FALSE; + } + const ReplayGameInfo &rg = replay.game; + if (replay.mapData == nullptr) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMapMissing", L"the replay's map is not installed"); + return FALSE; + } + if (game->getMap().compareNoCase(rg.getMap()) != 0) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMapMismatch", L"the lobby map is not the replay's map (%hs)", rg.getMap().str()); + return FALSE; + } + if (game->getMapCRC() != rg.getMapCRC()) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMapCRCMismatch", L"the map file differs from the one the replay was recorded on"); + return FALSE; + } + if (game->getSeed() != rg.getSeed()) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSeedMismatch", L"the lobby's random seed is not the replay's"); + return FALSE; + } + if (game->getStartingCash().countMoney() != rg.getStartingCash().countMoney()) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCashMismatch", L"the starting cash differs from the recording (%u)", rg.getStartingCash().countMoney()); + return FALSE; + } + if (game->getSuperweaponRestriction() != rg.getSuperweaponRestriction()) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSuperweaponMismatch", L"the superweapon limit differs from the recording"); + return FALSE; + } + if (!slotsMatch(rg, game, why)) + return FALSE; + if (handoffFrame != 0 && replay.lastFrame < handoffFrame) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSourceTooShort", + L"the replay ends at %ls, before the handoff at %ls", formatGameTime(replay.lastFrame).str(), formatGameTime(handoffFrame).str()); + return FALSE; + } + return TRUE; +} + +Bool validateRoster(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why) +{ + Int i; + Int replayCount = 0; + Int lobbyCount = 0; + for (i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replay.getConstSlot(i); + if (rs && rs->isHuman()) + ++replayCount; + const GameSlot *ls = lobby->getConstSlot(i); + if (ls && ls->isHuman()) + ++lobbyCount; + } + if (replayCount != lobbyCount) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCountMismatch", + L"the lobby has %d players but the replay has %d", lobbyCount, replayCount); + return FALSE; + } + + const GameSlot *replayHost = replay.getConstSlot(0); + const GameSlot *lobbyHost = lobby->getConstSlot(0); + if (!replayHost || !lobbyHost || !replayHost->isHuman() || replayHost->getName().compare(lobbyHost->getName()) != 0) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeHostMismatch", + L"only %ls, the host of the recorded game, can resume it", replayHost ? replayHost->getName().str() : L"?"); + return FALSE; + } + + for (i = 0; i < MAX_SLOTS; ++i) + { + const GameSlot *rs = replay.getConstSlot(i); + if (!rs || !rs->isHuman()) + continue; + Bool found = FALSE; + for (Int j = 0; j < MAX_SLOTS && !found; ++j) + { + const GameSlot *ls = lobby->getConstSlot(j); + found = ls && ls->isHuman() && ls->getName().compare(rs->getName()) == 0; + } + if (!found) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMissingPlayer", L"%ls is not in the lobby", rs->getName().str()); + return FALSE; + } + } + return TRUE; +} + +Bool guestSourceReport(const GameInfo *lobby, UnicodeString &report) +{ + SourceReplay replay; + UnicodeString why; + if (!readSource(replay, why)) + { + report = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeGuestUnreadable", L"Resume: my copy of the replay could not be used (%ls)", why.str()); + return FALSE; + } + if (!sourceMatchesGame(replay, lobby, lobby ? lobby->getResumeHandoffFrame() : 0, why)) + { + report = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeGuestMismatch", L"Resume: the replay does not match this lobby (%ls)", why.str()); + return FALSE; + } + report = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeGuestDownloaded", L"Resume: replay downloaded (ends at %ls)", formatGameTime(replay.lastFrame).str()); + return TRUE; +} + +Bool prepareGameStart(const GameInfo *game, UnicodeString &why) +{ + if (TheRecorder == nullptr) + return TRUE; + TheRecorder->disarmResume(); + if (game == nullptr || game->getResumeHandoffFrame() == 0) + return TRUE; + + SourceReplay replay; + UnicodeString reason; + if (!readSource(replay, reason) || !sourceMatchesGame(replay, game, game->getResumeHandoffFrame(), reason)) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeStartAborted", + L"Resume aborted: %ls (my replay ends at %ls)", reason.str(), formatGameTime(replay.lastFrame).str()); + return FALSE; + } + TheRecorder->armResumeForNextGame(game->getResumeHandoffFrame(), replay.lastFrame); + return TRUE; +} + +} // namespace ResumeFromReplay From ddbdda98ab8b785e705a9e38a53698bf726848b2 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Thu, 24 Sep 2026 10:43:36 -0700 Subject: [PATCH 10/15] fix(resume): Check every slot against the recording and fetch each new upload The slot check now covers every slot, not just the humans' names: occupant (human by name, AI by difficulty, or empty, with open and closed both counting as empty), faction, color, start position and team, since all of it seeds the simulation the recorded commands drive. Arming aligns the faction, color, start spot and team of every occupied slot whose kind already matches and then runs the full check, so a missing or wrong AI is reported for the host to fix instead of slipping through to the start. Online guests download the resume replay whenever the lobby is armed with an upload generation they have not fetched (the service bumps it on every arm), so a re-arm with the same handoff frame is fetched again; a chunk upload answered 409 resumes from the length the service reports, up to three times. The lead-in keeps the network's realtime gate so its last ten seconds run at the logic rate regardless of the render rate. Once the recorder holds the arm at game start the handoff frame is cleared on the game info, keeping RH= out of the new recording's options string. scanReplayLastFrame refusing to run while a file is open is now an explicit, logged error that readSource reports rather than a silent zero. --- .../GameEngine/Source/GameNetwork/Network.cpp | 6 +- .../OnlineServices_LobbyInterface.h | 6 +- .../Include/GameNetwork/ResumeFromReplay.h | 9 ++- .../GameEngine/Source/Common/Recorder.cpp | 6 ++ .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 24 ++++-- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 54 +++++++++---- .../GameNetwork/GeneralsOnline/NGMPGame.cpp | 2 +- .../OnlineServices_LobbyInterface.cpp | 40 ++++++++-- .../Source/GameNetwork/ResumeFromReplay.cpp | 78 +++++++++++++++---- 9 files changed, 172 insertions(+), 53 deletions(-) diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index 5aecf9d719d..7888d9a8c55 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -798,9 +798,11 @@ void Network::update() // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: the freeze after the handoff holds // the simulation on this frame for a wall-clock countdown while the network keeps // pumping, and catchup before it skips the realtime timing gate (timeForNewFrame) so - // frames advance as fast as lockstep allows. AllCommandsReady stays enforced either way. + // frames advance as fast as lockstep allows; the lead-in (last seconds before the + // handoff) keeps the gate so it runs at the logic rate whatever the render rate does. + // AllCommandsReady stays enforced either way. const Bool resumeFrozen = TheRecorder && TheRecorder->updateResumeFreeze(); - const Bool inCatchup = TheRecorder && TheRecorder->isResumeCatchupMode(); + const Bool inCatchup = TheRecorder && TheRecorder->isResumeCatchupMode() && !TheRecorder->isResumeCatchupLeadIn(); if (!resumeFrozen && AllCommandsReady(TheGameLogic->getFrame())) { // If all the commands are ready for the next frame... m_conMgr->handleAllCommandsReady(); diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index 39d2afb1f5e..711b83de532 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -75,8 +75,10 @@ struct LobbyEntry int rng_seed = -1; - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (0 when not armed); see ResumeFromReplay + // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (0 when not armed); see ResumeFromReplay. + // The generation counts the service's arms, so a guest can tell a fresh upload from the one it already holds. uint32_t resume_handoff_frame = 0; + uint32_t resume_replay_generation = 0; bool passworded = false; std::string password; @@ -547,7 +549,7 @@ class NGMP_OnlineServices_LobbyInterface } private: - void SendResumeReplayChunk(int64_t lobbyID, std::shared_ptr> data, size_t offset, std::function onComplete); + void SendResumeReplayChunk(int64_t lobbyID, std::shared_ptr> data, size_t offset, int conflictRetries, std::function onComplete); void FetchResumeReplayChunk(int64_t lobbyID, AsciiString path, std::shared_ptr> data, std::function onComplete); std::function m_cb_CreateLobbyPendingCallback = nullptr; diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h index 7dd8cdd2efb..5fe4f456227 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h @@ -71,7 +71,7 @@ namespace ResumeFromReplay /// the recording's slot-0 player and nobody extra is present (slot order is checked separately). Bool validateRoster(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why); - /// Every recorded human in the slot they held, under the same name, and nobody else in a recorded slot. + /// Every slot as recorded: occupant (human by name, AI by difficulty, or empty), faction, color, start position and team. Bool slotsMatch(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why); /// Guest: after its copy of Resume.rep arrived, whether it matches the lobby, with one chat line @@ -79,7 +79,8 @@ namespace ResumeFromReplay Bool guestSourceReport(const GameInfo *lobby, UnicodeString &report); /// Game start (LAN OnGameStart / NGMPGame::startGame), before MSG_NEW_GAME: when the lobby is armed, - /// validates this client's Resume.rep against it and arms the recorder. Returns FALSE with the - /// reason when the start must be abandoned; the recorder is never left armed in that case. - Bool prepareGameStart(const GameInfo *game, UnicodeString &why); + /// validates this client's Resume.rep against it, arms the recorder and clears the arm on the game + /// info (the recorder owns it from here). Returns FALSE with the reason when the start must be + /// abandoned; the recorder is never left armed in that case. + Bool prepareGameStart(GameInfo *game, UnicodeString &why); } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index 6410636ff55..cf8c0614094 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -1966,7 +1966,13 @@ Bool RecorderClass::startResumeCatchup() UnsignedInt RecorderClass::scanReplayLastFrame(AsciiString filename) { if (m_file != nullptr || isPlaybackMode() || isResumeCatchupMode()) + { + // Lobby-only helper; the read helpers it borrows (readReplayHeader, appendNextCommand) work on + // m_file, so it cannot run while a recording or playback holds that. 0 is "no usable frames". + DEBUG_CRASH(("RecorderClass::scanReplayLastFrame(%s) called while the recorder has a file open (mode %d)", filename.str(), m_mode)); + RESUME_LOG("Resume: cannot scan %s while the recorder has a file open (mode %d)", filename.str(), m_mode); return 0; + } ReplayHeader header; header.forPlayback = TRUE; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index bf8054553c2..48693915ae7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -725,11 +725,13 @@ static Bool lanArmedResumeStillMatches(LANGameInfo *game) } // Put every human back into the slot they held in the replay and restore the -// recorded faction, color, start position and team. Recorded commands are indexed -// by slot position, so the lobby must line up with the recording exactly. Slot 0 is -// never swapped: the LAN protocol treats it as the host's slot and validation has -// already checked the host matches. Non-human slots are left alone: setState() has -// destructive side effects on LAN slot identity. +// recorded faction, color, start position and team on every occupied slot whose kind +// (human, or AI at the recorded difficulty) already matches. Recorded commands are +// indexed by slot position, so the lobby must line up with the recording exactly. +// Slot 0 is never swapped: the LAN protocol treats it as the host's slot and validation +// has already checked the host matches. Slot kinds are never changed here: setState() +// has destructive side effects on LAN slot identity, so a missing or wrong AI is +// reported by the full check afterwards for the host to fix. static void reorderLobbyForResume(const ReplayGameInfo &replayInfo, LANGameInfo *lobby) { Int i; @@ -758,7 +760,7 @@ static void reorderLobbyForResume(const ReplayGameInfo &replayInfo, LANGameInfo { const GameSlot *rs = replayInfo.getConstSlot(i); LANGameSlot *ls = lobby->getLANSlot(i); - if (!rs || !rs->isHuman() || !ls || !ls->isHuman()) + if (!rs || !rs->isOccupied() || !ls || !ls->isOccupied() || rs->getState() != ls->getState()) continue; ls->setColor(rs->getColor()); ls->setPlayerTemplate(rs->getPlayerTemplate()); @@ -843,6 +845,16 @@ static void tryArmResumeFromReplay() game->setSuperweaponRestriction(replay.game.getSuperweaponRestriction()); game->setResumeHandoffFrame(handoff); + // The alignment above cannot add or change AI slots; the full check reports what is left for the host to fix. + if (!ResumeFromReplay::sourceMatchesGame(replay, game, handoff, why)) + { + lanClearResumeArm(); + TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); + lanUpdateSlotList(); + lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); + return; + } + // The options travel in one LAN packet; refuse to arm rather than let the field be cut off. AsciiString options = GenerateGameOptionsString(); if (options.getLength() >= m_lanMaxOptionsLength) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index 16c0f9f06d5..81cac0ef1a1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -1620,8 +1620,10 @@ void WOLDisplaySlotList(void) // being reordered. // ----------------------------------------------------------------------------- -static UnsignedInt s_wolLastSeenResumeHandoff = 0; ///< the arm the last lobby update carried, to notice changes -static Bool s_wolResumeArmInProgress = FALSE; ///< an upload plus arm is under way +static UnsignedInt s_wolLastSeenResumeHandoff = 0; ///< the arm the last lobby update carried, to notice changes +static Bool s_wolResumeArmInProgress = FALSE; ///< an upload plus arm is under way (host) +static uint32_t s_wolResumeDownloadedGeneration = 0; ///< the service's upload generation this client last downloaded (guest) +static Bool s_wolResumeDownloadInProgress = FALSE; ///< a download is under way (guest) static void wolLocalSystemChat(const UnicodeString &text) { @@ -1732,26 +1734,35 @@ static void wolTryArmResumeFromReplay(Bool disarm) return; } - // Every human must sit in the slot they held in the replay; slot order is the - // service's, so tell the lobby the first difference instead of reordering. - if (!ResumeFromReplay::validateRoster(rg, game, why) || !ResumeFromReplay::slotsMatch(rg, game, why)) + // Every human must be present under the recorded name; slot order is the service's, so + // the lobby is told the first difference instead of being reordered. + if (!ResumeFromReplay::validateRoster(rg, game, why)) { wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); return; } - // Restore the recorded faction, color, start position and team on every human slot. + // Restore the recorded faction, color, start position and team on every occupied slot whose + // kind (human, or AI at the recorded difficulty) already matches, then check every slot in + // full; whatever is left (a player in the wrong slot, a missing or wrong AI) is for the host + // to fix. The local slots are re-synced from the service on the next lobby update either way. for (Int i = 0; i < MAX_SLOTS; ++i) { const GameSlot *rs = rg.getConstSlot(i); GameSlot *ls = game->getSlot(i); - if (!rs || !rs->isHuman() || !ls || !ls->isHuman()) + if (!rs || !rs->isOccupied() || !ls || !ls->isOccupied() || rs->getState() != ls->getState()) continue; ls->setColor(rs->getColor()); ls->setPlayerTemplate(rs->getPlayerTemplate()); ls->setStartPos(rs->getStartPos()); ls->setTeamNumber(rs->getTeamNumber()); } + if (!ResumeFromReplay::slotsMatch(rg, game, why)) + { + WOLDisplaySlotList(); + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); + return; + } pLobbyInterface->UpdateCurrentLobby_BulkSlotUpdate(game); WOLDisplaySlotList(); @@ -1786,8 +1797,10 @@ static void wolTryArmResumeFromReplay(Bool disarm) }); } -// Every lobby update: a guest that sees the arm appear downloads the source, tells the -// lobby whether its copy matches and flags itself; everyone notes a disarm. +// Every lobby update: a guest downloads the source whenever the lobby is armed with an upload +// it has not fetched yet (the service bumps ResumeReplayGeneration on every arm, so a re-arm +// with the same handoff frame is fetched again), tells the lobby whether its copy matches and +// flags itself; everyone notes an arm or a disarm. static void wolCheckResumeArmChange() { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); @@ -1795,20 +1808,25 @@ static void wolCheckResumeArmChange() if (game == nullptr) return; const UnsignedInt handoff = game->getResumeHandoffFrame(); - if (handoff == s_wolLastSeenResumeHandoff) - return; - s_wolLastSeenResumeHandoff = handoff; - if (handoff == 0) + if (handoff != s_wolLastSeenResumeHandoff) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); - return; + s_wolLastSeenResumeHandoff = handoff; + if (handoff == 0) + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); } - if (pLobbyInterface->IsHost()) - return; // the host announced it and holds the source + if (handoff == 0 || pLobbyInterface->IsHost()) + return; // nothing armed, or the host: it announced the arm and holds the source + + const uint32_t generation = pLobbyInterface->GetCurrentLobby().resume_replay_generation; + if (generation == s_wolResumeDownloadedGeneration || s_wolResumeDownloadInProgress) + return; + s_wolResumeDownloadedGeneration = generation; + s_wolResumeDownloadInProgress = TRUE; wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDownloading", L"Resume: downloading the replay from the service...")); pLobbyInterface->DownloadResumeReplay(ResumeFromReplay::getSourceFilePath(), [](bool bDownloaded) { + s_wolResumeDownloadInProgress = FALSE; NGMP_OnlineServices_LobbyInterface* pLobby = NGMP_OnlineServicesManager::GetInterface(); NGMPGame *lobbyGame = pLobby == nullptr ? nullptr : pLobby->GetCurrentGame(); if (pLobby == nullptr || lobbyGame == nullptr) @@ -1829,6 +1847,8 @@ void InitWOLGameGadgets() ClearGSMessageBoxes(); s_wolLastSeenResumeHandoff = 0; s_wolResumeArmInProgress = FALSE; + s_wolResumeDownloadedGeneration = 0; + s_wolResumeDownloadInProgress = FALSE; NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); NGMPGame* theGameInfo = pLobbyInterface == nullptr ? nullptr : pLobbyInterface->GetCurrentGame(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index da8f8b3f4a9..697910b7888 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -520,7 +520,7 @@ void NGMPGame::launchGame(void) UnicodeString resumeWhy; if (!ResumeFromReplay::prepareGameStart(this, resumeWhy)) { - DEBUG_LOG(("Resume-from-replay validation failed. Bailing...\n")); + DEBUG_LOG(("Resume-from-replay validation failed. Bailing...")); if (TheNetwork != NULL) { delete TheNetwork; TheNetwork = NULL; diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index e3f424ec5d7..322493af86e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -88,6 +88,7 @@ namespace // Resume-from-replay source transfer: replays are command logs, a long match is a few MB. const size_t RESUME_REPLAY_CHUNK_BYTES = 256 * 1024; const size_t RESUME_REPLAY_MAX_BYTES = 16 * 1024 * 1024; + const int RESUME_REPLAY_MAX_CONFLICT_RETRIES = 3; // 409s in a row before an upload gives up std::vector ReadWholeFile(const char* path) { @@ -662,10 +663,10 @@ void NGMP_OnlineServices_LobbyInterface::UploadResumeReplay(const AsciiString& p return; } NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: uploading %s (%u bytes)", path.str(), (unsigned)bytes.size()); - SendResumeReplayChunk(m_CurrentLobby.lobbyID, std::make_shared>(std::move(bytes)), 0, onComplete); + SendResumeReplayChunk(m_CurrentLobby.lobbyID, std::make_shared>(std::move(bytes)), 0, 0, onComplete); } -void NGMP_OnlineServices_LobbyInterface::SendResumeReplayChunk(int64_t lobbyID, std::shared_ptr> data, size_t offset, std::function onComplete) +void NGMP_OnlineServices_LobbyInterface::SendResumeReplayChunk(int64_t lobbyID, std::shared_ptr> data, size_t offset, int conflictRetries, std::function onComplete) { if (offset >= data->size()) { @@ -686,16 +687,37 @@ void NGMP_OnlineServices_LobbyInterface::SendResumeReplayChunk(int64_t lobbyID, j["data"] = Base64Encode(chunk); std::string strPostData = j.dump(); - NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [this, lobbyID, data, offset, len, onComplete](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [this, lobbyID, data, offset, len, conflictRetries, onComplete](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) { - if (!bSuccess || statusCode != 200 || m_CurrentLobby.lobbyID != lobbyID) + if (bSuccess && statusCode == 200 && m_CurrentLobby.lobbyID == lobbyID) { - NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: chunk at %u failed (success=%d, status=%d)", (unsigned)offset, bSuccess, statusCode); - if (onComplete != nullptr) - onComplete(false); + SendResumeReplayChunk(lobbyID, data, offset + len, 0, onComplete); return; } - SendResumeReplayChunk(lobbyID, data, offset + len, onComplete); + + // 409 carries the service's real length (a lost reply, a duplicate send, or the service + // dropped the file): resume from there, or from 0 when it does not fit our file. + if (statusCode == 409 && m_CurrentLobby.lobbyID == lobbyID && conflictRetries < RESUME_REPLAY_MAX_CONFLICT_RETRIES) + { + size_t resumeAt = 0; + try + { + nlohmann::json jResp = nlohmann::json::parse(strBody); + const int64_t total = jResp.value("total", (int64_t)0); + if (total > 0 && (uint64_t)total < (uint64_t)data->size()) + resumeAt = (size_t)total; + } + catch (...) + { + } + NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: chunk at %u conflicted, resuming from %u (retry %d)", (unsigned)offset, (unsigned)resumeAt, conflictRetries + 1); + SendResumeReplayChunk(lobbyID, data, resumeAt, conflictRetries + 1, onComplete); + return; + } + + NetworkLog(ELogVerbosity::LOG_RELEASE, "UploadResumeReplay: chunk at %u failed (success=%d, status=%d)", (unsigned)offset, bSuccess, statusCode); + if (onComplete != nullptr) + onComplete(false); }); } @@ -1188,6 +1210,8 @@ void NGMP_OnlineServices_LobbyInterface::UpdateRoomDataCache(std::functionscanReplayLastFrame(getSourceFileName()); + if (out.lastFrame == 0) + { + why = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeNoFrames", L"the resume replay holds no complete frames (or the recorder is busy)"); + return FALSE; + } return TRUE; } @@ -117,27 +122,70 @@ Bool prepareHostSource(SourceReplay &out, UnsignedInt &handoffFrame, UnicodeStri return computeHandoffFrame(out.lastFrame, handoffFrame, why); } -// The lobby must line up with the recording slot for slot: every recorded human in the slot -// they held, under the same name, and nobody else in a recorded slot. Recorded commands are -// indexed by slot position, so this is what keeps the replayed commands attached to the -// right players. +static UnicodeString slotOccupantName(const GameSlot *slot) +{ + if (slot != nullptr && slot->isHuman()) + return slot->getName(); + return TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeAIPlayer", L"the AI player"); +} + +static UnicodeString slotStateName(const GameSlot *slot) +{ + if (slot == nullptr) + return UnicodeString::TheEmptyString; + switch (slot->getState()) + { + case SLOT_EASY_AI: return TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeEasyAI", L"an easy AI"); + case SLOT_MED_AI: return TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMediumAI", L"a medium AI"); + case SLOT_BRUTAL_AI: return TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHardAI", L"a hard AI"); + default: return slot->getName(); + } +} + +// The lobby must line up with the recording slot for slot. Recorded commands are indexed by +// slot position and the simulation is seeded by every slot's occupant, faction, start spot +// and team, so all of it has to match: every recorded human in the slot they held under the +// same name, every recorded AI in its slot at its difficulty, nobody in a slot that was empty, +// and the same faction, color, start position and team everywhere. Open and closed slots +// are both empty. Bool slotsMatch(const ReplayGameInfo &replay, const GameInfo *lobby, UnicodeString &why) { for (Int i = 0; i < MAX_SLOTS; ++i) { const GameSlot *rs = replay.getConstSlot(i); const GameSlot *ls = lobby->getConstSlot(i); - const Bool replayHuman = rs && rs->isHuman(); - const Bool lobbyHuman = ls && ls->isHuman(); - if (replayHuman == lobbyHuman && (!replayHuman || rs->getName().compare(ls->getName()) == 0)) + const Bool replayOccupied = rs && rs->isOccupied(); + const Bool lobbyOccupied = ls && ls->isOccupied(); + if (!replayOccupied && !lobbyOccupied) continue; - if (replayHuman) + if (replayOccupied && !lobbyOccupied) + { why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", - L"slot %d must be %ls (it was theirs in the recording)", i + 1, rs->getName().str()); - else + L"slot %d must be %ls (it was theirs in the recording)", i + 1, slotStateName(rs).str()); + return FALSE; + } + if (!replayOccupied && lobbyOccupied) + { why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotExtra", - L"slot %d was not a player in the recording, close it or move %ls", i + 1, ls->getName().str()); - return FALSE; + L"slot %d was not a player in the recording, close it or move %ls", i + 1, slotOccupantName(ls).str()); + return FALSE; + } + // human vs AI, AI difficulty + if (rs->getState() != ls->getState() || (rs->isHuman() && rs->getName().compare(ls->getName()) != 0)) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotMismatch", + L"slot %d must be %ls (it was theirs in the recording)", i + 1, slotStateName(rs).str()); + return FALSE; + } + if (rs->getPlayerTemplate() != ls->getPlayerTemplate() + || rs->getColor() != ls->getColor() + || rs->getStartPos() != ls->getStartPos() + || rs->getTeamNumber() != ls->getTeamNumber()) + { + why = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSlotSettingsMismatch", + L"slot %d (%ls) has a different faction, color, start position or team than in the recording", i + 1, slotOccupantName(ls).str()); + return FALSE; + } } return TRUE; } @@ -259,7 +307,7 @@ Bool guestSourceReport(const GameInfo *lobby, UnicodeString &report) return TRUE; } -Bool prepareGameStart(const GameInfo *game, UnicodeString &why) +Bool prepareGameStart(GameInfo *game, UnicodeString &why) { if (TheRecorder == nullptr) return TRUE; @@ -276,6 +324,10 @@ Bool prepareGameStart(const GameInfo *game, UnicodeString &why) return FALSE; } TheRecorder->armResumeForNextGame(game->getResumeHandoffFrame(), replay.lastFrame); + // The recorder owns the arm from here. Clearing it on the game info keeps RH= out of the + // new recording's options string (external replay parsers do not know the token) and + // leaves the lobby disarmed when the players come back after the match. + game->setResumeHandoffFrame(0); return TRUE; } From c3c35b18898e64e8bb360e1f7b1cc019e8410e8a Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Sun, 11 Oct 2026 15:30:50 -0700 Subject: [PATCH 11/15] feat(resume): Realign the online lobby from the recording and wire the Resume button Online resume used to refuse whenever the lobby's slot order differed from the recording, because the service owns slot order. The host now sends the whole recorded arrangement in one HOST_ACTION_ALIGN_SLOTS (22) request and the service rebuilds the lobby to match or refuses it with a reason. The arm is a chain, each step from the previous completion: map, starting cash and superweapon limit (only what differs), the slot table, the replay upload, then the arm itself, which must come last because the service disarms on every one of those changes. Every refusal is posted to the whole lobby as what went wrong and who fixes it. Guests print the armed notice from the lobby state itself rather than relying on the host's chat line, and failed or mismatched downloads say what to do. Start on a drifted lobby points at Resume or Cancel Resume. The Resume button is the same action as /resume and /resume off: the host arms with it and, while armed, it reads CANCEL RESUME and disarms; guests see RESUME ARMED, disabled. Both lobbies look the button up by name and work without it, so the layouts can ship separately (LanGameOptionsMenu.wnd:ButtonResumeFromReplay and GameSpyGameOptionsMenu.wnd:ButtonResume). All texts use FETCH_OR_SUBSTITUTE, so no csf change is needed. --- .../OnlineServices_LobbyInterface.h | 26 +- .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 42 ++ .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 372 ++++++++++++++---- .../GUICallbacks/Menus/WOLMapSelectMenu.cpp | 1 + .../OnlineServices_LobbyInterface.cpp | 93 ++++- 5 files changed, 447 insertions(+), 87 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index 711b83de532..eb4d9df85fe 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -89,6 +89,20 @@ struct LobbyEntry int latency = 0; }; +// TheSuperHackers @feature bill-rich 11/10/2026 One slot of a HOST_ACTION_ALIGN_SLOTS request: what the +// slot must hold once the service has applied the whole arrangement. A human is named by user id, an +// AI by its difficulty state; open and closed slots carry nothing else. +struct LobbySlotSpec +{ + int slotIndex = -1; + int slotState = SlotState::SLOT_OPEN; + int64_t userID = -1; + int side = -1; + int color = -1; + int startPos = -1; + int team = -1; +}; + enum class EJoinLobbyResult { JoinLobbyResult_Success, // The room was joined. @@ -217,9 +231,11 @@ class NGMP_OnlineServices_LobbyInterface // updates - void UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers); - void UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons); - void UpdateCurrentLobby_StartingCash(UnsignedInt startingCashValue); + // TheSuperHackers @feature bill-rich 11/10/2026 The three settings a resume has to align carry an optional + // completion callback, so the arm can run them one after another and only then send the arm. + void UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers, std::function onDone = nullptr); + void UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons, std::function onDone = nullptr); + void UpdateCurrentLobby_StartingCash(UnsignedInt startingCashValue, std::function onDone = nullptr); void UpdateCurrentLobby_HasMap(); @@ -236,6 +252,10 @@ class NGMP_OnlineServices_LobbyInterface void UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game); + // TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay: place every slot the way the recording + // had it, in one host action the service applies whole or not at all. On refusal `error` says why. + void UpdateCurrentLobby_AlignSlots(const std::vector& slots, std::function onDone); + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay (see ResumeFromReplay). The host uploads // the resume source, then arms with the handoff frame and the replay's seed (handoff 0 disarms); // guests download the source when the arm reaches them and flag themselves as holding it. diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index 48693915ae7..ece63214f05 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -114,6 +114,8 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID; static NameKeyType buttonStartID = NAMEKEY_INVALID; static NameKeyType buttonEmoteID = NAMEKEY_INVALID; static NameKeyType buttonSelectMapID = NAMEKEY_INVALID; +// TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay button, back on the layout: the host arms or cancels, guests see the state. +static NameKeyType buttonResumeFromReplayID = NAMEKEY_INVALID; static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID; static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID; static NameKeyType windowMapID = NAMEKEY_INVALID; @@ -122,6 +124,26 @@ static GameWindow *parentLanGameOptions = nullptr; static GameWindow *buttonBack = nullptr; static GameWindow *buttonStart = nullptr; static GameWindow *buttonSelectMap = nullptr; +static GameWindow *buttonResumeFromReplay = nullptr; + +// What the Resume button says: RESUME or CANCEL RESUME for the host, RESUME ARMED +// (disabled) for a guest while one is pending, so the state is visible without the chat. +static void lanUpdateResumeButton() +{ + if (buttonResumeFromReplay == nullptr || TheLAN == nullptr) + return; + const Bool host = TheLAN->AmIHost(); + const Bool armed = TheLAN->GetMyGame() != nullptr && TheLAN->GetMyGame()->isResumeArmed(); + buttonResumeFromReplay->winEnable(host); + if (host) + buttonResumeFromReplay->winSetText(armed + ? TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeCancel", L"CANCEL RESUME") + : TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFromReplay", L"RESUME")); + else + buttonResumeFromReplay->winSetText(armed + ? TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmedButton", L"RESUME ARMED") + : TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFromReplay", L"RESUME")); +} static GameWindow *buttonEmote = nullptr; static GameWindow *textEntryChat = nullptr; static GameWindow *textEntryMapDisplay = nullptr; @@ -788,6 +810,7 @@ static void disarmResumeFromReplay() TheLAN->RequestGameOptions(GenerateGameOptionsString(), true); lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); } + lanUpdateResumeButton(); } // A host change to a setting the recording fixes (map, starting cash, superweapon limit) @@ -798,6 +821,7 @@ static void lanDisarmResumeForSettingsChange() return; lanClearResumeArm(); lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmedSettings", L"Resume disarmed: the game settings changed")); + lanUpdateResumeButton(); } // Guests: the arm arrives in the host's game options (RH=). The file itself is sent when the @@ -810,6 +834,7 @@ static void lanCheckResumeArmChange(LANGameInfo *game) if (handoff == s_lanLastSeenResumeHandoff) return; s_lanLastSeenResumeHandoff = handoff; + lanUpdateResumeButton(); if (handoff != 0) lanLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmedGuest", L"Resume armed by the host: the replay is sent when the game starts and replays to %ls", ResumeFromReplay::formatGameTime(handoff).str())); @@ -870,6 +895,7 @@ static void tryArmResumeFromReplay() lanSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", L"Resume armed: the next start replays the last match to %ls, then hands control back", ResumeFromReplay::formatGameTime(handoff).str())); + lanUpdateResumeButton(); } void InitLanGameGadgets() @@ -883,6 +909,7 @@ void InitLanGameGadgets() listboxChatWindowLanGameID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ListboxChatWindowLanGame" ); buttonEmoteID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonEmote" ); buttonSelectMapID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonSelectMap" ); + buttonResumeFromReplayID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonResumeFromReplay" ); checkboxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:CheckboxLimitSuperweapons" ); comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ComboBoxStartingCash" ); windowMapID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:MapWindow" ); @@ -896,6 +923,8 @@ void InitLanGameGadgets() DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap")); buttonStart = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonStartID ); DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart")); + buttonResumeFromReplay = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonResumeFromReplayID ); // absent from older .wnd layouts + lanUpdateResumeButton(); buttonBack = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonBackID); DEBUG_ASSERTCRASH(buttonBack, ("Could not find the buttonBack")); listboxChatWindowLanGame = TheWindowManager->winGetWindowFromId( parentLanGameOptions, listboxChatWindowLanGameID ); @@ -1001,6 +1030,7 @@ void DeinitLanGameGadgets() buttonSelectMap = nullptr; buttonStart = nullptr; buttonBack = nullptr; + buttonResumeFromReplay = nullptr; listboxChatWindowLanGame = nullptr; textEntryChat = nullptr; textEntryMapDisplay = nullptr; @@ -1091,6 +1121,7 @@ void LanGameOptionsMenuInit( WindowLayout *layout, void *userData ) //DEBUG_LOG(("LanGameOptionsMenuInit(): map is %s", TheLAN->GetMyGame()->getMap().str())); buttonStart->winSetText(TheGameText->fetch("GUI:Accept")); buttonSelectMap->winEnable( FALSE ); + lanUpdateResumeButton(); checkboxLimitSuperweapons->winEnable( FALSE ); // Can look but only host can touch comboBoxStartingCash->winEnable( FALSE ); // Ditto TheLAN->GetMyGame()->setMapCRC( TheLAN->GetMyGame()->getMapCRC() ); // force a recheck @@ -1454,6 +1485,17 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m if (!txtInput.isEmpty()) TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_EMOTE); } + else if ( controlID == buttonResumeFromReplayID ) + { + // TheSuperHackers @feature bill-rich 11/10/2026 Same as /resume and /resume off. + if (TheLAN->AmIHost()) + { + if (TheLAN->GetMyGame() && TheLAN->GetMyGame()->isResumeArmed()) + disarmResumeFromReplay(); + else + tryArmResumeFromReplay(); + } + } else if ( controlID == buttonSelectMapID ) { //buttonBack->winEnable( false ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index 81cac0ef1a1..2daa3dfd512 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -204,6 +204,8 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID; static NameKeyType buttonStartID = NAMEKEY_INVALID; static NameKeyType buttonEmoteID = NAMEKEY_INVALID; static NameKeyType buttonSelectMapID = NAMEKEY_INVALID; +// TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay button (host arms or cancels; guests see the state). +static NameKeyType buttonResumeID = NAMEKEY_INVALID; static NameKeyType windowMapID = NAMEKEY_INVALID; #if defined(GENERALS_ONLINE_ENABLE_MATCH_START_COUNTDOWN) @@ -221,6 +223,7 @@ static GameWindow *parentWOLGameSetup = NULL; static GameWindow *buttonBack = NULL; static GameWindow *buttonStart = NULL; static GameWindow *buttonSelectMap = NULL; +static GameWindow *buttonResume = NULL; static GameWindow *buttonEmote = NULL; static GameWindow *textEntryChat = NULL; static GameWindow *textEntryMapDisplay = NULL; @@ -1653,7 +1656,7 @@ static Bool wolArmedResumeStillMatches(NGMPGame *game) || !ResumeFromReplay::sourceMatchesGame(replay, game, game->getResumeHandoffFrame(), why)) { wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeStartRefused", - L"Resume is armed and the lobby no longer matches the recording (%ls). Fix it, or type /resume off to start a fresh game.", why.str())); + L"Resume is armed but the lobby no longer matches the recording (%ls). Host: press Resume again to realign it, or Cancel Resume for a fresh game.", why.str())); return FALSE; } @@ -1674,6 +1677,177 @@ static Bool wolArmedResumeStillMatches(NGMPGame *game) return TRUE; } +// ----------------------------------------------------------------------------- +// TheSuperHackers @feature bill-rich 11/10/2026 The arm is a chain of service +// requests, each started from the previous one's completion: the map, the +// starting cash and the superweapon limit (only those that differ from the +// recording), then the whole slot table in one piece, then the upload and the +// arm itself. The service disarms on every one of those changes, which is why +// the arm comes last and nothing is sent in parallel. The local lobby is not +// touched here: every step shows up through the lobby push, exactly as it does +// when the host changes a setting by hand. +// ----------------------------------------------------------------------------- +struct WolResumeArmJob +{ + UnsignedInt handoff = 0; + Int seed = 0; + AsciiString mapKey; + UnicodeString mapDisplayU; + Bool mapOfficial = FALSE; + Int mapNumPlayers = 0; + UnsignedInt startingCash = 0; + Bool limitSuperweapons = FALSE; + std::vector slots; +}; +static WolResumeArmJob s_wolResumeJob; + +// Everyone sees why it stopped and what to do about it; the host is usually not +// the one who has to act. +static void wolResumeArmFailed(const UnicodeString &what, const UnicodeString &fix) +{ + s_wolResumeArmInProgress = FALSE; + UnicodeString msg; + msg.format(L"Resume: %ls. %ls", what.str(), fix.str()); + wolLobbySystemChat(msg); +} + +static Bool wolResumeSlotsAlreadyAligned(NGMP_OnlineServices_LobbyInterface *pLobbyInterface) +{ + const LobbyEntry &lobby = pLobbyInterface->GetCurrentLobby(); + for (const LobbySlotSpec &spec : s_wolResumeJob.slots) + { + const LobbyMemberEntry *m = nullptr; + for (const LobbyMemberEntry &member : lobby.members) + { + if (member.m_SlotIndex == spec.slotIndex) + { + m = &member; + break; + } + } + if (m == nullptr || m->m_SlotState != spec.slotState) + return FALSE; + if (spec.slotState == SLOT_PLAYER && m->user_id != spec.userID) + return FALSE; + if (spec.slotState == SLOT_OPEN || spec.slotState == SLOT_CLOSED) + continue; + if (m->side != spec.side || m->color != spec.color || m->startpos != spec.startPos || m->team != spec.team) + return FALSE; + } + return TRUE; +} + +static void wolUpdateResumeButton(); + +static void wolResumeArmStep(Int step) +{ + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + NGMPGame *game = pLobbyInterface == nullptr ? nullptr : pLobbyInterface->GetCurrentGame(); + if (pLobbyInterface == nullptr || game == nullptr || !pLobbyInterface->IsHost()) + { + s_wolResumeArmInProgress = FALSE; + return; + } + const WolResumeArmJob &job = s_wolResumeJob; + const LobbyEntry &lobby = pLobbyInterface->GetCurrentLobby(); + NetworkLog(ELogVerbosity::LOG_RELEASE, "Resume: arm step %d", step); + + if (step <= 0 && game->getMap().compareNoCase(job.mapKey) != 0) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSettingMap", + L"Resume: switching the lobby to the recording's map, %ls", job.mapDisplayU.str())); + pLobbyInterface->UpdateCurrentLobby_Map(job.mapDisplayU, job.mapKey, job.mapOfficial, job.mapNumPlayers, [](bool bOK) + { + if (bOK) + wolResumeArmStep(1); + else + wolResumeArmFailed(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMapRefused", L"the service refused the map change"), + TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFixMap", L"Host: select the recording's map with Select Map, then press Resume again.")); + }); + return; + } + if (step <= 1 && lobby.starting_cash != job.startingCash) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeSettingCash", + L"Resume: setting the starting cash to %u, as recorded", job.startingCash)); + pLobbyInterface->UpdateCurrentLobby_StartingCash(job.startingCash, [](bool bOK) + { + if (bOK) + wolResumeArmStep(2); + else + wolResumeArmFailed(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeCashRefused", L"the service refused the starting cash change"), + TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFixCash", L"Host: set the starting cash the recording used, then press Resume again.")); + }); + return; + } + if (step <= 2 && lobby.limit_superweapons != (job.limitSuperweapons != FALSE)) + { + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSettingSuperweapons", + L"Resume: setting the superweapon limit as recorded")); + pLobbyInterface->UpdateCurrentLobby_LimitSuperweapons(job.limitSuperweapons != FALSE, [](bool bOK) + { + if (bOK) + wolResumeArmStep(3); + else + wolResumeArmFailed(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSuperweaponsRefused", L"the service refused the superweapon limit change"), + TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFixSuperweapons", L"Host: set the superweapon limit the recording used, then press Resume again.")); + }); + return; + } + if (step <= 3 && !wolResumeSlotsAlreadyAligned(pLobbyInterface)) + { + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeAligning", + L"Resume: moving everyone to the slot, faction, color and start position they had in the recording")); + pLobbyInterface->UpdateCurrentLobby_AlignSlots(job.slots, [](bool bOK, const std::string &error) + { + if (bOK) + { + wolResumeArmStep(4); + return; + } + UnicodeString what; + what.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeAlignRefused", L"the lobby could not be arranged like the recording (%hs)"), error.c_str()); + wolResumeArmFailed(what, TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFixAlign", + L"Everyone: take the slot you had in that match, then the host presses Resume again.")); + }); + return; + } + + // Upload the source, then arm; the arm is announced only once the service accepted it. + const UnsignedInt handoffFrame = job.handoff; + const Int seed = job.seed; + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploading", L"Resume: uploading the replay to the service...")); + pLobbyInterface->UploadResumeReplay(ResumeFromReplay::getSourceFilePath(), [handoffFrame, seed](bool bUploaded) + { + NGMP_OnlineServices_LobbyInterface* pLobby = NGMP_OnlineServicesManager::GetInterface(); + if (!bUploaded || pLobby == nullptr) + { + wolResumeArmFailed(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploadFailed", L"the replay upload failed, nothing is armed"), + TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFixUpload", L"Host: press Resume again; if it keeps failing the replay may be too large for the service.")); + return; + } + pLobby->UpdateCurrentLobby_ArmResume(handoffFrame, seed, [handoffFrame](bool bArmed) + { + s_wolResumeArmInProgress = FALSE; + NGMP_OnlineServices_LobbyInterface* pLobby2 = NGMP_OnlineServicesManager::GetInterface(); + if (!bArmed || pLobby2 == nullptr) + { + wolResumeArmFailed(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmRefused", L"the service refused to arm"), + TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFixArm", L"Host: press Resume again. A setting changed while it was arming, or the upload was not accepted.")); + return; + } + s_wolLastSeenResumeHandoff = handoffFrame; + pLobby2->UpdateCurrentLobby_HasResumeReplay(true); // the host holds the source by definition + wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", + L"Resume armed: the next start replays the last match to %ls, then hands control back", ResumeFromReplay::formatGameTime(handoffFrame).str())); + wolUpdateResumeButton(); + }); + }); +} + +// Press Resume (or type /resume): checks the recording against the lobby, then +// drives the service through whatever has to change (see wolResumeArmStep). +// /resume off, or the button while armed, disarms. static void wolTryArmResumeFromReplay(Bool disarm) { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); @@ -1693,13 +1867,14 @@ static void wolTryArmResumeFromReplay(Bool disarm) if (bSuccess) wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); else - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmRefused", L"Resume: the service refused the request")); + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmRefused", L"Resume: the service refused to disarm; try again")); + wolUpdateResumeButton(); }); return; } if (s_wolResumeArmInProgress) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploadInProgress", L"Resume: the replay is still being uploaded")); + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploadInProgress", L"Resume: still arming, wait for it to finish")); return; } @@ -1708,95 +1883,123 @@ static void wolTryArmResumeFromReplay(Bool disarm) UnicodeString why; if (!ResumeFromReplay::prepareHostSource(replay, handoff, why)) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); + // The recording itself is unusable (or there is none): nothing in the lobby can fix that. + UnicodeString msg; + msg.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSourceRefused", L"Resume: %ls. The host's last recording is what gets resumed, and it must come from this build."), why.str()); + wolLobbySystemChat(msg); return; } const ReplayGameInfo &rg = replay.game; - // The service owns the map, cash and superweapon settings (and clears an arm when they - // change), so they must already match the recording rather than be set here. - if (game->getMap().compareNoCase(rg.getMap()) != 0) - { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeMapMismatchOnline", - L"Resume: select the replay's map first (%hs)", rg.getMap().str())); - return; - } - if (game->getStartingCash().countMoney() != rg.getStartingCash().countMoney()) + if (replay.mapData->m_CRC != rg.getMapCRC()) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeCashMismatchOnline", - L"Resume: set the starting cash to %u first", rg.getStartingCash().countMoney())); - return; - } - if (game->getSuperweaponRestriction() != rg.getSuperweaponRestriction()) - { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSuperweaponMismatchOnline", - L"Resume: set the superweapon limit to match the recording first")); + UnicodeString msg; + msg.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeHostMapDiffers", + L"Resume: the host's copy of %ls is not the file that match was played on. Host: reinstall that map, then press Resume again."), replay.mapData->m_displayName.str()); + wolLobbySystemChat(msg); return; } - // Every human must be present under the recorded name; slot order is the service's, so - // the lobby is told the first difference instead of being reordered. + // Every human must be present under the recorded name, and only the recorded host can do this. if (!ResumeFromReplay::validateRoster(rg, game, why)) { - wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); + UnicodeString msg; + msg.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeRosterRefused", L"Resume: %ls. Get exactly the players of that match into this lobby, then press Resume again."), why.str()); + wolLobbySystemChat(msg); return; } - // Restore the recorded faction, color, start position and team on every occupied slot whose - // kind (human, or AI at the recorded difficulty) already matches, then check every slot in - // full; whatever is left (a player in the wrong slot, a missing or wrong AI) is for the host - // to fix. The local slots are re-synced from the service on the next lobby update either way. + // Everything the service has to be told, taken from the recording up front: the job + // outlives this call, and the ReplayGameInfo does not. + WolResumeArmJob &job = s_wolResumeJob; + job = WolResumeArmJob(); + job.handoff = handoff; + job.seed = rg.getSeed(); + job.mapKey = rg.getMap(); + job.mapDisplayU = replay.mapData->m_displayName; + job.mapOfficial = replay.mapData->m_isOfficial; + job.mapNumPlayers = replay.mapData->m_numPlayers; + job.startingCash = rg.getStartingCash().countMoney(); + job.limitSuperweapons = rg.getSuperweaponRestriction() != 0; + const LobbyEntry &lobby = pLobbyInterface->GetCurrentLobby(); for (Int i = 0; i < MAX_SLOTS; ++i) { + LobbySlotSpec spec; + spec.slotIndex = i; const GameSlot *rs = rg.getConstSlot(i); - GameSlot *ls = game->getSlot(i); - if (!rs || !rs->isOccupied() || !ls || !ls->isOccupied() || rs->getState() != ls->getState()) - continue; - ls->setColor(rs->getColor()); - ls->setPlayerTemplate(rs->getPlayerTemplate()); - ls->setStartPos(rs->getStartPos()); - ls->setTeamNumber(rs->getTeamNumber()); - } - if (!ResumeFromReplay::slotsMatch(rg, game, why)) - { - WOLDisplaySlotList(); - wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeRefused", L"Resume: %ls", why.str())); - return; - } - pLobbyInterface->UpdateCurrentLobby_BulkSlotUpdate(game); - WOLDisplaySlotList(); - - // Upload the source, then arm; the arm is announced only once the service accepted it. - const UnsignedInt handoffFrame = handoff; - const Int seed = rg.getSeed(); - s_wolResumeArmInProgress = TRUE; - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploading", L"Resume: uploading the replay to the service...")); - pLobbyInterface->UploadResumeReplay(ResumeFromReplay::getSourceFilePath(), [handoffFrame, seed](bool bUploaded) - { - NGMP_OnlineServices_LobbyInterface* pLobby = NGMP_OnlineServicesManager::GetInterface(); - if (!bUploaded || pLobby == nullptr) + if (rs != nullptr && rs->isHuman()) { - s_wolResumeArmInProgress = FALSE; - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeUploadFailed", L"Resume: the replay upload failed, not armed")); - return; - } - pLobby->UpdateCurrentLobby_ArmResume(handoffFrame, seed, [handoffFrame](bool bArmed) - { - s_wolResumeArmInProgress = FALSE; - NGMP_OnlineServices_LobbyInterface* pLobby2 = NGMP_OnlineServicesManager::GetInterface(); - if (!bArmed || pLobby2 == nullptr) + spec.slotState = SLOT_PLAYER; + for (const LobbyMemberEntry &member : lobby.members) { - wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmRefused", L"Resume: the service refused the request")); + if (member.IsHuman() && rs->getName().compare(UnicodeString(from_utf8(member.display_name).c_str())) == 0) + { + spec.userID = member.user_id; + break; + } + } + if (spec.userID == -1) + { + // validateRoster matched the names against the local slots, which mirror the members list; + // a miss here means the two disagree, which a lobby push will cure. + UnicodeString msg; + msg.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeMemberUnknown", + L"Resume: %ls is not in the lobby yet. Wait a moment, then press Resume again."), rs->getName().str()); + wolLobbySystemChat(msg); return; } - s_wolLastSeenResumeHandoff = handoffFrame; - pLobby2->UpdateCurrentLobby_HasResumeReplay(true); // the host holds the source by definition - wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmed", - L"Resume armed: the next start replays the last match to %ls, then hands control back", ResumeFromReplay::formatGameTime(handoffFrame).str())); - }); - }); + } + else if (rs != nullptr && rs->isOccupied()) + { + spec.slotState = rs->getState(); + } + else + { + spec.slotState = (i < job.mapNumPlayers) ? SLOT_OPEN : SLOT_CLOSED; + } + if (rs != nullptr && rs->isOccupied()) + { + spec.side = rs->getPlayerTemplate(); + spec.color = rs->getColor(); + spec.startPos = rs->getStartPos(); + spec.team = rs->getTeamNumber(); + } + job.slots.push_back(spec); + } + + NetworkLog(ELogVerbosity::LOG_RELEASE, "Resume: arming, handoff=%u seed=%d map=%s cash=%u sw=%d", handoff, job.seed, job.mapKey.str(), job.startingCash, (int)job.limitSuperweapons); + s_wolResumeArmInProgress = TRUE; + wolResumeArmStep(0); +} + +// The Resume button says what the arm is doing: for the host it arms or cancels; +// for everyone else it is read-only and shows RESUME ARMED while one is pending, +// so a guest who missed the chat line still knows the next start is a resume. +static void wolUpdateResumeButton() +{ + if (buttonResume == NULL) + return; + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + NGMPGame *game = pLobbyInterface == nullptr ? nullptr : pLobbyInterface->GetCurrentGame(); + const Bool armed = game != nullptr && game->isResumeArmed(); + const Bool host = pLobbyInterface != nullptr && pLobbyInterface->IsHost(); + if (host) + { + buttonResume->winEnable(TRUE); + buttonResume->winSetText(armed + ? TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeCancel", L"CANCEL RESUME") + : TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFromReplay", L"RESUME")); + } + else + { + buttonResume->winEnable(FALSE); + buttonResume->winSetText(armed + ? TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeArmedButton", L"RESUME ARMED") + : TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeFromReplay", L"RESUME")); + } } + // Every lobby update: a guest downloads the source whenever the lobby is armed with an upload // it has not fetched yet (the service bumps ResumeReplayGeneration on every arm, so a re-arm // with the same handoff frame is fetched again), tells the lobby whether its copy matches and @@ -1813,7 +2016,13 @@ static void wolCheckResumeArmChange() s_wolLastSeenResumeHandoff = handoff; if (handoff == 0) wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDisarmed", L"Resume disarmed: the next start is a fresh game")); + else if (!pLobbyInterface->IsHost()) + // Said locally, from the lobby state itself, so it does not depend on the host's + // chat line getting through. + wolLocalSystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeArmedGuest", + L"Resume armed by the host: the next start replays the last match to %ls, then hands control back", ResumeFromReplay::formatGameTime(handoff).str())); } + wolUpdateResumeButton(); if (handoff == 0 || pLobbyInterface->IsHost()) return; // nothing armed, or the host: it announced the arm and holds the source @@ -1834,9 +2043,9 @@ static void wolCheckResumeArmChange() UnicodeString report; Bool usable = FALSE; if (!bDownloaded) - report = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDownloadFailed", L"Resume: the replay download failed"); - else - usable = ResumeFromReplay::guestSourceReport(lobbyGame, report); + report = TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeDownloadFailed", L"Resume: my download of the replay failed. Host: press Cancel Resume, then Resume again"); + else if (!(usable = ResumeFromReplay::guestSourceReport(lobbyGame, report))) + report.concat(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeGuestMismatchFix", L". Host: press Resume again to realign the lobby")); pLobby->SendChatMessageToCurrentLobby(report, false); pLobby->UpdateCurrentLobby_HasResumeReplay(usable); }); @@ -1870,6 +2079,7 @@ void InitWOLGameGadgets() listboxGameSetupChatID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ListboxChatWindowGameSpyGameSetup" ); buttonEmoteID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ButtonEmote" ); buttonSelectMapID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ButtonSelectMap" ); + buttonResumeID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ButtonResume" ); checkBoxUseStatsID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:CheckBoxUseStats" ); windowMapID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:MapWindow" ); checkBoxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey("GameSpyGameOptionsMenu.wnd:CheckboxLimitSuperweapons"); @@ -1883,6 +2093,8 @@ void InitWOLGameGadgets() parentWOLGameSetup = TheWindowManager->winGetWindowFromId( NULL, parentWOLGameSetupID ); buttonEmote = TheWindowManager->winGetWindowFromId( parentWOLGameSetup,buttonEmoteID ); buttonSelectMap = TheWindowManager->winGetWindowFromId( parentWOLGameSetup,buttonSelectMapID ); + buttonResume = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, buttonResumeID ); // absent from older .wnd layouts + wolUpdateResumeButton(); checkBoxUseStats = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, checkBoxUseStatsID ); buttonStart = TheWindowManager->winGetWindowFromId( parentWOLGameSetup,buttonStartID ); buttonBack = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, buttonBackID); @@ -1929,6 +2141,7 @@ void InitWOLGameGadgets() { checkBoxLimitSuperweapons->winEnable( false ); comboBoxStartingCash->winEnable( false ); + wolUpdateResumeButton(); NameKeyType labelID = TheNameKeyGenerator->nameToKey("GameSpyGameOptionsMenu.wnd:StartingCashLabel"); TheWindowManager->winGetWindowFromId(parentWOLGameSetup, labelID)->winEnable( FALSE ); } @@ -1937,6 +2150,7 @@ void InitWOLGameGadgets() { checkBoxLimitSuperweapons->winEnable(true); comboBoxStartingCash->winEnable(true); + wolUpdateResumeButton(); } #endif @@ -2090,6 +2304,7 @@ void DeinitWOLGameGadgets() parentWOLGameSetup = NULL; buttonEmote = NULL; buttonSelectMap = NULL; + buttonResume = NULL; buttonStart = NULL; buttonBack = NULL; listboxGameSetupChat = NULL; @@ -2491,6 +2706,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) buttonStart->winSetText(TheGameText->fetch("GUI:Accept")); buttonStart->winEnable( FALSE ); buttonSelectMap->winEnable( FALSE ); + wolUpdateResumeButton(); initialAcceptEnable = FALSE; WOLDisplaySlotList(); @@ -2782,6 +2998,7 @@ void WOLGameSetupMenuUpdate( WindowLayout * layout, void *userData) buttonStart->winSetText(TheGameText->fetch("GUI:Start")); buttonStart->winEnable(TRUE); buttonSelectMap->winEnable(TRUE); + wolUpdateResumeButton(); initialAcceptEnable = TRUE; comboBoxStartingCash->winEnable(TRUE); @@ -3899,7 +4116,7 @@ Bool handleGameSetupSlashCommands(UnicodeString uText) { const Color helpColor = GameMakeColor(127, 127, 127, 255); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/me - Send an emote."), helpColor, -1, -1); - GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/resume - Resume the last recorded match from its replay; /resume off disarms (host only)."), helpColor, -1, -1); + GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/resume - Same as the Resume button: continue the host's last recorded match; /resume off cancels (host only)."), helpColor, -1, -1); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/friendsonly - Let only friends join (host only)."), helpColor, -1, -1); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/public - Let anyone join (host only)."), helpColor, -1, -1); GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"/setpassword - Set a lobby password (host only)."), helpColor, -1, -1); @@ -4398,6 +4615,13 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg WOLMapSelectLayout->hide( FALSE ); WOLMapSelectLayout->bringForward(); } + else if ( controlID == buttonResumeID ) + { + // TheSuperHackers @feature bill-rich 11/10/2026 Same as /resume and /resume off. + NGMP_OnlineServices_LobbyInterface* pResumeLobby = NGMP_OnlineServicesManager::GetInterface(); + NGMPGame *resumeGame = pResumeLobby ? pResumeLobby->GetCurrentGame() : nullptr; + wolTryArmResumeFromReplay(resumeGame != nullptr && resumeGame->isResumeArmed()); + } else if ( controlID == buttonStartID ) { savePlayerInfo(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp index d898c52b9ff..f055b319a1f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp @@ -101,6 +101,7 @@ static const char *gadgetsToHide[] = "ButtonStart", "StaticTextMapPreview", + "ButtonResume", nullptr }; static const char *perPlayerGadgetsToHide[] = diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index 322493af86e..126c605b5c4 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -77,7 +77,8 @@ enum class ELobbyUpdateField JOINABILITY = 18, HOST_ACTION_BULK_SLOT_UPDATE = 19, HOST_ACTION_ARM_RESUME = 20, // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (see ResumeFromReplay) - LOCAL_PLAYER_HAS_RESUME_REPLAY = 21 // TheSuperHackers @feature bill-rich 24/09/2026 this member holds a usable copy of the resume source + LOCAL_PLAYER_HAS_RESUME_REPLAY = 21, // TheSuperHackers @feature bill-rich 24/09/2026 this member holds a usable copy of the resume source + HOST_ACTION_ALIGN_SLOTS = 22 // TheSuperHackers @feature bill-rich 11/10/2026 resume-from-replay: the whole slot table at once }; std::string Base64Encode(const std::vector& data); @@ -121,7 +122,7 @@ namespace } } -void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers) +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers, std::function onDone) { // reset autostart if host changes anything (because ready flag will reset too) #if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) @@ -152,13 +153,17 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(UnicodeString st std::string strPostData = j.dump(); // convert - NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [onDone](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) { - + const bool bOK = bSuccess && statusCode >= 200 && statusCode < 300; + if (!bOK) + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_Map failed: success=%d, status=%d", bSuccess, statusCode); + if (onDone) + onDone(bOK); }); } -void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons) +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons, std::function onDone) { // reset autostart if host changes anything (because ready flag will reset too) #if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) @@ -176,13 +181,17 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_LimitSuperweapons(bo std::string strPostData = j.dump(); // convert - NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [onDone](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) { - + const bool bOK = bSuccess && statusCode >= 200 && statusCode < 300; + if (!bOK) + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_LimitSuperweapons failed: success=%d, status=%d", bSuccess, statusCode); + if (onDone) + onDone(bOK); }); } -void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_StartingCash(UnsignedInt startingCashValue) +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_StartingCash(UnsignedInt startingCashValue, std::function onDone) { // reset autostart if host changes anything (because ready flag will reset too) #if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) @@ -200,9 +209,13 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_StartingCash(Unsigne std::string strPostData = j.dump(); // convert - NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [onDone](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) { - + const bool bOK = bSuccess && statusCode >= 200 && statusCode < 300; + if (!bOK) + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_StartingCash failed: success=%d, status=%d", bSuccess, statusCode); + if (onDone) + onDone(bOK); }); } @@ -579,6 +592,66 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_BulkSlotUpdate(NGMPG }); } +// TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay: the whole slot table in one host action. +// The service rebuilds its member table from this (humans moved, AI and empty slots re-created) or refuses +// the lot with a reason; nothing is half-applied. The next lobby push shows the result everywhere. +void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_AlignSlots(const std::vector& slots, std::function onDone) +{ +#if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) + ClearAutoReadyCountdown(); +#endif + if (TheNGMPGame && TheNGMPGame->IsCountdownStarted()) + TheNGMPGame->StopCountdown(); + + std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), m_CurrentLobby.lobbyID); + std::map mapHeaders; + + nlohmann::json j; + j["field"] = ELobbyUpdateField::HOST_ACTION_ALIGN_SLOTS; + nlohmann::json slotsArray = nlohmann::json::array(); + for (const LobbySlotSpec& spec : slots) + { + nlohmann::json e; + e["slot_index"] = spec.slotIndex; + e["slot_state"] = spec.slotState; + if (spec.slotState == SlotState::SLOT_PLAYER) + e["user_id"] = spec.userID; + e["side"] = spec.side; + e["color"] = spec.color; + e["start_pos"] = spec.startPos; + e["team"] = spec.team; + slotsArray.push_back(e); + } + j["slots"] = slotsArray; + std::string strPostData = j.dump(); + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_AlignSlots: %s", strPostData.c_str()); + + NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [onDone](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) + { + bool bOK = bSuccess && statusCode >= 200 && statusCode < 300; + std::string error; + try + { + nlohmann::json jResp = nlohmann::json::parse(strBody); + if (bOK) + bOK = jResp.value("success", false); + error = jResp.value("error", std::string()); + } + catch (...) + { + bOK = false; + } + if (!bOK) + { + if (error.empty()) + error = std::format("service error {}", statusCode); + NetworkLog(ELogVerbosity::LOG_RELEASE, "UpdateCurrentLobby_AlignSlots failed: success=%d, status=%d, error=%s", bSuccess, statusCode, error.c_str()); + } + if (onDone) + onDone(bOK, error); + }); +} + // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: arm (handoff 0 disarms) the resume source // the host uploaded. The service stores the handoff frame on the lobby and takes the replay's seed // as the lobby seed, so the next start replays that file in lockstep before live control resumes. From 51a4da3422bc5f9edb326c326b2d12e9b356d5b4 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Sun, 11 Oct 2026 18:46:09 -0700 Subject: [PATCH 12/15] fix(resume): Tidy two refusal messages Reasons that already end in a period were getting a second one, and the wait for a guest's download now says what to do if it never comes. --- .../GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index 2daa3dfd512..cc364164344 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -1669,7 +1669,7 @@ static Bool wolArmedResumeStillMatches(NGMPGame *game) { UnicodeString name(from_utf8(member.display_name).c_str()); wolLobbySystemChat(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ResumeWaitingForDownload", - L"Resume: waiting for %ls to download the replay", name.str())); + L"Resume: waiting for %ls to download the replay. If it never arrives, they should leave and rejoin, then the host presses Resume again", name.str())); return FALSE; } } @@ -1706,8 +1706,14 @@ static WolResumeArmJob s_wolResumeJob; static void wolResumeArmFailed(const UnicodeString &what, const UnicodeString &fix) { s_wolResumeArmInProgress = FALSE; + // Some reasons already end in a period; do not double it. + UnicodeString reason = what; + if (!reason.isEmpty() && reason.getCharAt(reason.getLength() - 1) == L'.') + { + reason.removeLastChar(); + } UnicodeString msg; - msg.format(L"Resume: %ls. %ls", what.str(), fix.str()); + msg.format(L"Resume: %ls. %ls", reason.str(), fix.str()); wolLobbySystemChat(msg); } @@ -1884,8 +1890,13 @@ static void wolTryArmResumeFromReplay(Bool disarm) if (!ResumeFromReplay::prepareHostSource(replay, handoff, why)) { // The recording itself is unusable (or there is none): nothing in the lobby can fix that. + UnicodeString reason = why; + if (!reason.isEmpty() && reason.getCharAt(reason.getLength() - 1) == L'.') + { + reason.removeLastChar(); // the sentence continues + } UnicodeString msg; - msg.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSourceRefused", L"Resume: %ls. The host's last recording is what gets resumed, and it must come from this build."), why.str()); + msg.format(TheGameText->FETCH_OR_SUBSTITUTE("GUI:ResumeSourceRefused", L"Resume: %ls. The host's last recording is what gets resumed, and it must come from this build."), reason.str()); wolLobbySystemChat(msg); return; } From 7fd17d2d64b67fb7af19f071f8b8113b7b9b28f7 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Fri, 6 Nov 2026 08:14:22 -0800 Subject: [PATCH 13/15] refactor(lobby): Drop the unused host bulk slot update --- .../OnlineServices_LobbyInterface.h | 2 - .../OnlineServices_LobbyInterface.cpp | 42 ------------------- 2 files changed, 44 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index eb4d9df85fe..4ac0c16a881 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -250,8 +250,6 @@ class NGMP_OnlineServices_LobbyInterface void UpdateCurrentLobby_AITeam(int slot, int team); void UpdateCurrentLobby_AIStartPos(int slot, int startpos); - void UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game); - // TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay: place every slot the way the recording // had it, in one host action the service applies whole or not at all. On refusal `error` says why. void UpdateCurrentLobby_AlignSlots(const std::vector& slots, std::function onDone); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index 126c605b5c4..67d1a637188 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -550,48 +550,6 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ForceReady() }); } -void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game) -{ - // reset autostart if host changes anything (because ready flag will reset too) -#if !defined(GENERALS_ONLINE_DISABLE_AUTO_ACCEPT) - ClearAutoReadyCountdown(); -#endif - if (TheNGMPGame && TheNGMPGame->IsCountdownStarted()) - TheNGMPGame->StopCountdown(); - - std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), m_CurrentLobby.lobbyID); - std::map mapHeaders; - - nlohmann::json j; - j["field"] = ELobbyUpdateField::HOST_ACTION_BULK_SLOT_UPDATE; - - nlohmann::json slotsArray = nlohmann::json::array(); - for (int i = 0; i < MAX_SLOTS; ++i) - { - const GameSlot *slot = game->getConstSlot(i); - if (slot && slot->isOccupied()) - { - nlohmann::json slotEntry; - slotEntry["slot_index"] = i; - slotEntry["side"] = slot->getPlayerTemplate(); - slotEntry["color"] = slot->getColor(); - slotEntry["start_pos"] = slot->getStartPos(); - slotEntry["team"] = slot->getTeamNumber(); - slotsArray.push_back(slotEntry); - } - } - j["slots"] = slotsArray; - std::string strPostData = j.dump(); - - NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq) - { - if (!bSuccess || statusCode < 200 || statusCode >= 300) - { - DEBUG_LOG(("UpdateCurrentLobby_BulkSlotUpdate failed: success=%d, status=%d", bSuccess, statusCode)); - } - }); -} - // TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay: the whole slot table in one host action. // The service rebuilds its member table from this (humans moved, AI and empty slots re-created) or refuses // the lot with a reason; nothing is half-applied. The next lobby push shows the result everywhere. From a43eda22d575dd6d38ab0d7632e630dc690cfd70 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Fri, 6 Nov 2026 08:14:22 -0800 Subject: [PATCH 14/15] fix(resume): Only accept the resume source over the replay transfer path A transferred .rep could land under any name in the guest's replay folder. The only legitimate file is Resume.rep, so refuse every other leaf. --- .../Source/Common/System/SaveGame/GameState.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp index 224b5aa037c..f43fe1169c7 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp @@ -933,10 +933,18 @@ AsciiString GameState::portableMapPathToRealMapPath(const AsciiString& in) const } else if (in.startsWithNoCase(PORTABLE_REPLAYS)) { - // the replay dir ends with "\\"; only the leaf name travels, so nothing can escape it + // the replay dir ends with "\\". Only the resume source may land here, so a peer + // cannot name another replay on this machine. + AsciiString resumeLeaf = RecorderClass::getResumeReplayFileName(); + resumeLeaf.concat(RecorderClass::getReplayExtention()); + if (getMapLeafName(in).compareNoCase(resumeLeaf) != 0) + { + DEBUG_LOG(("Transferred replay '%s' is not the resume source.", in.str())); + return AsciiString::TheEmptyString; + } prefix = RecorderClass::getReplayDir(); containingBasePath = prefix; - prefix.concat(getMapLeafName(in)); + prefix.concat(resumeLeaf); } else { From ef749f44804843cfa82d99b58ec47b9074aeb245 Mon Sep 17 00:00:00 2001 From: Bill Rich Date: Wed, 11 Nov 2026 10:59:27 -0800 Subject: [PATCH 15/15] chore(resume): Drop the TheSuperHackers comment tags from the resume change --- .../Include/GameNetwork/FileTransfer.h | 2 +- .../GameEngine/Include/GameNetwork/GameInfo.h | 2 +- .../Include/GameNetwork/NetworkDefs.h | 2 +- Core/GameEngine/Source/Common/FramePacer.cpp | 2 +- .../ControlBarCommandProcessing.cpp | 2 +- .../GameClient/MessageStream/CommandXlat.cpp | 2 +- .../MessageStream/SelectionXlat.cpp | 2 +- .../Source/GameNetwork/ConnectionManager.cpp | 4 ++-- .../Source/GameNetwork/DisconnectManager.cpp | 2 +- .../Source/GameNetwork/FileTransfer.cpp | 4 ++-- .../Source/GameNetwork/FrameMetrics.cpp | 2 +- .../Source/GameNetwork/GameInfo.cpp | 2 +- .../Source/GameNetwork/LANAPICallbacks.cpp | 2 +- .../GameEngine/Source/GameNetwork/Network.cpp | 6 +++--- .../Code/GameEngine/Include/Common/Recorder.h | 2 +- .../OnlineServices_LobbyInterface.h | 12 +++++------ .../Include/GameNetwork/ResumeFromReplay.h | 2 +- .../GameEngine/Source/Common/GameEngine.cpp | 6 +++--- .../GameEngine/Source/Common/Recorder.cpp | 12 +++++------ .../Common/System/SaveGame/GameState.cpp | 2 +- .../GUICallbacks/Menus/LanGameOptionsMenu.cpp | 10 +++++----- .../GUI/GUICallbacks/Menus/ReplayMenu.cpp | 2 +- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 14 ++++++------- .../GameEngine/Source/GameClient/InGameUI.cpp | 2 +- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../GeneralsOnline/HTTP/HTTPRequest.cpp | 2 +- .../GameNetwork/GeneralsOnline/NGMPGame.cpp | 4 ++-- .../GeneralsOnline/NGMP_Helpers.cpp | 2 +- .../OnlineServices_LobbyInterface.cpp | 20 +++++++++---------- .../Source/GameNetwork/ResumeFromReplay.cpp | 2 +- 30 files changed, 66 insertions(+), 66 deletions(-) diff --git a/Core/GameEngine/Include/GameNetwork/FileTransfer.h b/Core/GameEngine/Include/GameNetwork/FileTransfer.h index bf68e331154..ea9285bf168 100644 --- a/Core/GameEngine/Include/GameNetwork/FileTransfer.h +++ b/Core/GameEngine/Include/GameNetwork/FileTransfer.h @@ -47,6 +47,6 @@ AsciiString GetReadmeFromMap( AsciiString path ); // The meat of file (map) transfers Bool DoAnyMapTransfers(GameInfo *game); -// TheSuperHackers @feature bill-rich 24/09/2026 Resume-from-replay: the host pushes the resume source +// Resume-from-replay: the host pushes the resume source // (a replay file) to every human guest over the same transfer path at game start. Bool DoResumeReplayTransfer(GameInfo *game, AsciiString path); diff --git a/Core/GameEngine/Include/GameNetwork/GameInfo.h b/Core/GameEngine/Include/GameNetwork/GameInfo.h index 645f8524d91..e2b10e24053 100644 --- a/Core/GameEngine/Include/GameNetwork/GameInfo.h +++ b/Core/GameEngine/Include/GameNetwork/GameInfo.h @@ -220,7 +220,7 @@ class GameInfo void setCRCInterval( Int val ) { m_crcInterval = (val > 0 && val < 100) ? val : 100; } Int getCRCInterval() const { return m_crcInterval; } - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming. When non-zero, every client + // Resume-from-replay arming. When non-zero, every client // replays its copy of the resume source (Resume.rep, pushed from the host) in lockstep // up to this frame on game start before live control resumes (see ResumeFromReplay). void setResumeHandoffFrame( UnsignedInt f ) { m_resumeHandoffFrame = f; } diff --git a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h index 314e566218d..eba656831bb 100644 --- a/Core/GameEngine/Include/GameNetwork/NetworkDefs.h +++ b/Core/GameEngine/Include/GameNetwork/NetworkDefs.h @@ -43,7 +43,7 @@ static Int MIN_RUNAHEAD = 6; static constexpr const Int MIN_RUNAHEAD = 4; #endif -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup pins the run-ahead and the +// Resume-from-replay catchup pins the run-ahead and the // logic frame rate that ConnectionManager::updateRunAhead negotiates, so every // peer derives the same short packet send interval while fast-forwarding. static constexpr const Int CATCHUP_RUNAHEAD = 32; diff --git a/Core/GameEngine/Source/Common/FramePacer.cpp b/Core/GameEngine/Source/Common/FramePacer.cpp index c23067ddb63..809d6458826 100644 --- a/Core/GameEngine/Source/Common/FramePacer.cpp +++ b/Core/GameEngine/Source/Common/FramePacer.cpp @@ -110,7 +110,7 @@ Bool FramePacer::isActualFramesPerSecondLimitEnabled() const #endif } - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup runs one logic frame per + // Resume-from-replay catchup runs one logic frame per // render frame and fast-forwards many times faster than realtime, so the render // cap has to get out of the way until the lead-in. if (TheRecorder != nullptr && TheRecorder->isResumeCatchupMode() && !TheRecorder->isResumeCatchupLeadIn()) diff --git a/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp index 7cb97c7f0bd..142296b3f08 100644 --- a/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp +++ b/Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp @@ -121,7 +121,7 @@ CBCommandStatus ControlBar::processCommandTransitionUI( GameWindow *control, Gad CBCommandStatus ControlBar::processCommandUI( GameWindow *control, GadgetGameMessage gadgetMessage ) { - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup: control bar buttons and + // Resume-from-replay catchup: control bar buttons and // their hotkeys (which re-dispatch into this path) are inert until control is handed back if( TheRecorder && TheRecorder->isResumeInputBlocked() ) return CBC_COMMAND_NOT_USED; diff --git a/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp index 3418f9e7f18..54a3b5803a9 100644 --- a/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp +++ b/Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp @@ -2550,7 +2550,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage GameMessage::Type t = msg->getType(); GameMessageDisposition disp = KEEP_MESSAGE; // We want to always be able to get to the options menu even during no input times and a clear game data message should always go through - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup blocks every command the + // Resume-from-replay catchup blocks every command the // same way disabled input does (camera scrolling lives in LookAtTranslator and // stays available); the options menu stays reachable so a stuck catchup can be left. const Bool resumeBlocked = TheRecorder && TheRecorder->isResumeInputBlocked(); diff --git a/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp index a7df9caa4c0..41230d952bf 100644 --- a/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp +++ b/Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp @@ -351,7 +351,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa { GameMessageDisposition disp = KEEP_MESSAGE; - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup: no selecting until control is handed back + // Resume-from-replay catchup: no selecting until control is handed back if( !TheInGameUI->getInputEnabled() || (TheRecorder && TheRecorder->isResumeInputBlocked()) ) { //Keep the message so the other translators (WindowXlat) can handle. diff --git a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp index eed3640f324..0485393ba23 100644 --- a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp @@ -68,7 +68,7 @@ static Bool hasValidTransferFileExtension(const AsciiString& filePath) "wak", "tga", "txt", - "rep" // TheSuperHackers @feature bill-rich 24/09/2026 the resume-from-replay source (see ResumeFromReplay) + "rep" // The resume-from-replay source (see ResumeFromReplay) }; const char* fileExt = strrchr(filePath.str(), '.'); @@ -1525,7 +1525,7 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS newRunAhead = clamp(minRunAheadForClamp, newRunAhead, MAX_FRAMES_AHEAD / 2); - // TheSuperHackers @feature bill-rich 15/09/2026 During resume-from-replay catchup Network::update() + // During resume-from-replay catchup Network::update() // drops the realtime frame gate, so the only thing bounding how fast we // replay is lockstep: a frame advances once every peer's commands for it have // arrived. Throughput is (frames in flight) / (packet send interval), and diff --git a/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp b/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp index 1a1543e5767..526084d3467 100644 --- a/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp @@ -98,7 +98,7 @@ void DisconnectManager::update(ConnectionManager *conMgr) { m_lastFrameTime = timeGetTime(); } - // TheSuperHackers @feature bill-rich 15/09/2026 The resume-from-replay freeze deliberately holds the + // The resume-from-replay freeze deliberately holds the // logic frame for a countdown; that is not a stalled peer. if (TheRecorder && TheRecorder->isResumeFreezeActive()) { m_lastFrameTime = timeGetTime(); diff --git a/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp b/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp index 0cae0a576e4..46b381a20d8 100644 --- a/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp +++ b/Core/GameEngine/Source/GameNetwork/FileTransfer.cpp @@ -82,7 +82,7 @@ static Bool doFileTransfer( AsciiString filename, MapTransferLoadScreen *ls, Int fileTransferPercent = 100; for (i=1; igetConstSlot(i)->isHuman() && (mask & (1<= 1000) { - // TheSuperHackers @feature bill-rich 15/09/2026 This history is the input to + // This history is the input to // ConnectionManager::updateRunAhead, i.e. how this machine tells the rest of // the game how fast it can run. During resume-from-replay catchup the renderer // is deliberately throttled while logic fast-forwards, so display FPS measures diff --git a/Core/GameEngine/Source/GameNetwork/GameInfo.cpp b/Core/GameEngine/Source/GameNetwork/GameInfo.cpp index c5fef7b1285..0f78a017c91 100644 --- a/Core/GameEngine/Source/GameNetwork/GameInfo.cpp +++ b/Core/GameEngine/Source/GameNetwork/GameInfo.cpp @@ -938,7 +938,7 @@ AsciiString GameInfoToAsciiString( const GameInfo *game ) game->getStartingCash().countMoney(), game->oldFactionsOnly() ? 'Y' : 'N' ); #endif - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay handoff frame. Only emitted when + // Resume-from-replay handoff frame. Only emitted when // armed so unarmed games still round-trip bit-identically through the serializer, and // emitted before the slot list so the slot-name truncation below accounts for it. if (game->isResumeArmed()) diff --git a/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp index fd243546b2d..a775529a9c8 100644 --- a/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp +++ b/Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp @@ -244,7 +244,7 @@ void LANAPI::OnGameStart() return; } - // TheSuperHackers @feature bill-rich 24/09/2026 An armed resume-from-replay first pushes the host's + // An armed resume-from-replay first pushes the host's // resume source to every guest over the map transfer path, then every client checks its // copy against the lobby and arms the recorder. Either failing backs out the same way as // a missing map rather than start a fresh match that would desync everyone. diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index 7888d9a8c55..3836f4b0609 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -485,7 +485,7 @@ void Network::attachTransport(Transport* transport) { } Bool Network::isMessageTypeWithinNetworkRange(GameMessage::Type type) { - // TheSuperHackers @feature bill-rich 15/09/2026 During resume-from-replay catchup every peer injects + // During resume-from-replay catchup every peer injects // the same commands from its own copy of the replay, so re-broadcasting them // would double them on the receiver. Treat everything as non-transfer so it flows // through processCommand instead, which also drives the per-frame tick forward. @@ -499,7 +499,7 @@ Bool Network::isMessageTypeWithinNetworkRange(GameMessage::Type type) { * Take commands from TheCommandList and give them to the connection manager for transport. */ void Network::GetCommandsFromCommandList() { - // TheSuperHackers @feature bill-rich 24/09/2026 During resume-from-replay catchup the local CRCs + // During resume-from-replay catchup the local CRCs // are not exchanged (every peer is replaying the source's recorded CRC messages instead), // and leaving one in TheCommandList would have it execute a frame later on its own: on // the handoff frame that is a lone CRC with validation back on, a false "Not enough CRCs". @@ -795,7 +795,7 @@ void Network::update() endOfGameCheck(); } - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: the freeze after the handoff holds + // Resume-from-replay: the freeze after the handoff holds // the simulation on this frame for a wall-clock countdown while the network keeps // pumping, and catchup before it skips the realtime timing gate (timeForNewFrame) so // frames advance as fast as lockstep allows; the lead-in (last seconds before the diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h index 7b0b18f6c32..54ecb30f1cf 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h @@ -140,7 +140,7 @@ class RecorderClass : public SubsystemInterface RecorderModeType getMode(); ///< Returns the current operating mode. Bool isPlaybackMode() const { return m_mode == RECORDERMODETYPE_PLAYBACK || m_mode == RECORDERMODETYPE_SIMULATION_PLAYBACK; } - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay. + // Resume-from-replay. // // The lobby's start path validates this client's copy of the resume source (Resume.rep, // see ResumeFromReplay) and arms the recorder. On the next MSG_NEW_GAME a brand new diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h index 4ac0c16a881..8ce5bb92bfd 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h @@ -26,7 +26,7 @@ struct LobbyMemberEntry : public NetworkMemberBase int team = -1; int startpos = -1; bool has_map = false; - bool has_resume_replay = false; // TheSuperHackers @feature bill-rich 24/09/2026 holds a usable copy of the resume-from-replay source + bool has_resume_replay = false; // Holds a usable copy of the resume-from-replay source uint16_t m_SlotIndex = 999999; uint16_t m_SlotState = SlotState::SLOT_OPEN; @@ -75,7 +75,7 @@ struct LobbyEntry int rng_seed = -1; - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (0 when not armed); see ResumeFromReplay. + // Resume-from-replay arming (0 when not armed); see ResumeFromReplay. // The generation counts the service's arms, so a guest can tell a fresh upload from the one it already holds. uint32_t resume_handoff_frame = 0; uint32_t resume_replay_generation = 0; @@ -89,7 +89,7 @@ struct LobbyEntry int latency = 0; }; -// TheSuperHackers @feature bill-rich 11/10/2026 One slot of a HOST_ACTION_ALIGN_SLOTS request: what the +// One slot of a HOST_ACTION_ALIGN_SLOTS request: what the // slot must hold once the service has applied the whole arrangement. A human is named by user id, an // AI by its difficulty state; open and closed slots carry nothing else. struct LobbySlotSpec @@ -231,7 +231,7 @@ class NGMP_OnlineServices_LobbyInterface // updates - // TheSuperHackers @feature bill-rich 11/10/2026 The three settings a resume has to align carry an optional + // The three settings a resume has to align carry an optional // completion callback, so the arm can run them one after another and only then send the arm. void UpdateCurrentLobby_Map(UnicodeString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers, std::function onDone = nullptr); void UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons, std::function onDone = nullptr); @@ -250,11 +250,11 @@ class NGMP_OnlineServices_LobbyInterface void UpdateCurrentLobby_AITeam(int slot, int team); void UpdateCurrentLobby_AIStartPos(int slot, int startpos); - // TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay: place every slot the way the recording + // Resume-from-replay: place every slot the way the recording // had it, in one host action the service applies whole or not at all. On refusal `error` says why. void UpdateCurrentLobby_AlignSlots(const std::vector& slots, std::function onDone); - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay (see ResumeFromReplay). The host uploads + // Resume-from-replay (see ResumeFromReplay). The host uploads // the resume source, then arms with the handoff frame and the replay's seed (handoff 0 disarms); // guests download the source when the arm reaches them and flag themselves as holding it. void UpdateCurrentLobby_ArmResume(uint32_t handoffFrame, int rngSeed, std::function onComplete); diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h index 5fe4f456227..46aa269a590 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ResumeFromReplay.h @@ -16,7 +16,7 @@ ** along with this program. If not, see . */ -// TheSuperHackers @feature bill-rich 24/09/2026 Resume-from-replay: the arming and validation +// Resume-from-replay: the arming and validation // shared by the LAN lobby, the online lobby and the game start path. // // After a match dies, the same players resume it from the host's recording. The host arms it diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp index 7436dfc2bcf..a6376dc6db6 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp @@ -937,7 +937,7 @@ Bool GameEngine::canUpdateRegularGameLogic(UnsignedInt logicTimeQueryFlags) const Bool useFastMode = TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame(); #endif - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup fast-forwards by running + // Resume-from-replay catchup fast-forwards by running // one logic frame per render frame; the logic time scale must not throttle it. const Bool inCatchup = TheRecorder && TheRecorder->isResumeCatchupMode() && !TheRecorder->isResumeCatchupLeadIn(); @@ -968,7 +968,7 @@ Bool GameEngine::canUpdateRegularGameLogic(UnsignedInt logicTimeQueryFlags) extern NGMPGame* TheNGMPGame; #endif -// TheSuperHackers @feature bill-rich 15/09/2026 Wall-clock cadence of the render passes during +// Wall-clock cadence of the render passes during // resume-from-replay catchup (about 30 fps), see GameEngine::update. static constexpr const UnsignedInt CATCHUP_RENDER_INTERVAL_MS = 33; @@ -982,7 +982,7 @@ void GameEngine::update() { USE_PERF_TIMER(GameEngine_update) { - // TheSuperHackers @feature bill-rich 15/09/2026 During resume-from-replay catchup, render on a + // During resume-from-replay catchup, render on a // wall-clock cadence rather than once per logic frame: logic is fast-forwarding // at many times realtime, so drawing every logic frame would burn the CPU on // frames no one can perceive, while drawing at ~30 fps keeps the catchup diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index cf8c0614094..79b3eed68ac 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -55,7 +55,7 @@ extern NGMPGame* TheNGMPGame; -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay milestones go to the release log online. +// Resume-from-replay milestones go to the release log online. #if defined(GENERALS_ONLINE) #define RESUME_LOG(...) NetworkLog(ELogVerbosity::LOG_RELEASE, __VA_ARGS__) #else @@ -420,7 +420,7 @@ void RecorderClass::reset() { */ void RecorderClass::update() { if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) { - // TheSuperHackers @feature bill-rich 15/09/2026 Inject the resume source's commands for this + // Inject the resume source's commands for this // frame, then record them like any other frame: the new recording is a normal replay of // the resumed match from frame 0. The handoff (or an abort) switches the mode inside. updateResumeCatchup(); @@ -511,7 +511,7 @@ void RecorderClass::updateRecord() if (msg->getArgumentCount() >= 4) maxFPS = msg->getArgument(3)->integer; - // TheSuperHackers @feature bill-rich 15/09/2026 The new recording starts as for any game. + // The new recording starts as for any game. // When the lobby's start path armed a resume-from-replay (ResumeFromReplay::prepareGameStart // validated this client's copy of the source), the source is then replayed into it. // startRecording resets the recorder, so the arming is carried across by hand. A source @@ -1346,7 +1346,7 @@ void RecorderClass::readNextFrame() { if (bytesRead != sizeof(m_nextFrame)) { DEBUG_LOG(("RecorderClass::readNextFrame - read failed on frame %d", TheGameLogic->getFrame())); m_nextFrame = -1; - // TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay catchup: running out of + // Resume-from-replay catchup: running out of // records is handled by updateResumeCatchup (which never ends the live game here). if (m_mode == RECORDERMODETYPE_RESUME_CATCHUP) return; @@ -1356,7 +1356,7 @@ void RecorderClass::readNextFrame() { /** * This reads the next command from the replay file and appends it to TheCommandList. - * TheSuperHackers @feature bill-rich 24/09/2026 Returns FALSE when the record is incomplete (a + * Returns FALSE when the record is incomplete (a * recording cut short by a crash ends in a torn record); the torn record is discarded and * m_nextFrame is set to -1 so the callers treat it as the end of the usable data. */ @@ -1818,7 +1818,7 @@ Bool RecorderClass::isMultiplayer() } //------------------------------------------------------------------------------------------------- -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay. See Recorder.h for the phase overview. +// Resume-from-replay. See Recorder.h for the phase overview. //------------------------------------------------------------------------------------------------- AsciiString RecorderClass::getResumeReplayFileName() diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp index f43fe1169c7..32201d87a16 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp @@ -864,7 +864,7 @@ static AsciiString getMapLeafAndDirName(const AsciiString& in) const char* PORTABLE_SAVE = "Save\\"; const char* PORTABLE_MAPS = "Maps\\"; const char* PORTABLE_USER_MAPS = "UserData\\Maps\\"; -const char* PORTABLE_REPLAYS = "Replays\\"; // TheSuperHackers @feature bill-rich 24/09/2026 the resume-from-replay source travels the map transfer path +const char* PORTABLE_REPLAYS = "Replays\\"; // The resume-from-replay source travels the map transfer path // ------------------------------------------------------------------------------------------------ AsciiString GameState::realMapPathToPortableMapPath(const AsciiString& in) const diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp index ece63214f05..f4e2b2b5c00 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp @@ -114,7 +114,7 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID; static NameKeyType buttonStartID = NAMEKEY_INVALID; static NameKeyType buttonEmoteID = NAMEKEY_INVALID; static NameKeyType buttonSelectMapID = NAMEKEY_INVALID; -// TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay button, back on the layout: the host arms or cancels, guests see the state. +// Resume-from-replay button, back on the layout: the host arms or cancels, guests see the state. static NameKeyType buttonResumeFromReplayID = NAMEKEY_INVALID; static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID; static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID; @@ -286,7 +286,7 @@ void StartPressed() return; } - // TheSuperHackers @feature bill-rich 15/09/2026 An armed resume-from-replay only works if the lobby still matches the recording. + // An armed resume-from-replay only works if the lobby still matches the recording. if (TheLAN->AmIHost() && myGame->isResumeArmed() && !lanArmedResumeStillMatches(myGame)) { return; @@ -705,7 +705,7 @@ void lanUpdateSlotList() //------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------- -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming (host only). +// Resume-from-replay arming (host only). // // /resume copies the host's last recording to Resume.rep (ResumeFromReplay::prepareHostSource), // aligns the lobby with it (slot order, factions, colors, start spots, teams, map, seed, @@ -1487,7 +1487,7 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m } else if ( controlID == buttonResumeFromReplayID ) { - // TheSuperHackers @feature bill-rich 11/10/2026 Same as /resume and /resume off. + // Same as /resume and /resume off. if (TheLAN->AmIHost()) { if (TheLAN->GetMyGame() && TheLAN->GetMyGame()->isResumeArmed()) @@ -1630,7 +1630,7 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m txtInput.trim(); // Echo the user's input to the chat window if (!txtInput.isEmpty()) - // TheSuperHackers @feature bill-rich 15/09/2026 "/resume" arms resume-from-replay, "/resume off" disarms + // "/resume" arms resume-from-replay, "/resume off" disarms if (txtInput.compareNoCase(L"/resume") == 0 || txtInput.compareNoCase(L"/resume off") == 0) { if (!TheLAN->AmIHost()) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp index ce6d0a767e9..ce171bbfcb1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp @@ -106,7 +106,7 @@ UnicodeString GetReplayFilenameFromListbox(GameWindow *listbox, Int index) //------------------------------------------------------------------------------------------------- -// TheSuperHackers @refactor bill-rich 15/09/2026 No longer static: resume-from-replay reads replay headers too (declared in ResumeFromReplay.h). +// No longer static: resume-from-replay reads replay headers too (declared in ResumeFromReplay.h). Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData) { header.forPlayback = FALSE; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index cc364164344..705ef032159 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -204,7 +204,7 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID; static NameKeyType buttonStartID = NAMEKEY_INVALID; static NameKeyType buttonEmoteID = NAMEKEY_INVALID; static NameKeyType buttonSelectMapID = NAMEKEY_INVALID; -// TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay button (host arms or cancels; guests see the state). +// Resume-from-replay button (host arms or cancels; guests see the state). static NameKeyType buttonResumeID = NAMEKEY_INVALID; static NameKeyType windowMapID = NAMEKEY_INVALID; @@ -985,7 +985,7 @@ static Bool wolArmedResumeStillMatches(NGMPGame *game); static void wolCheckResumeArmChange(); static void StartPressed() { - // TheSuperHackers @feature bill-rich 15/09/2026 An armed resume-from-replay only works if the lobby still + // An armed resume-from-replay only works if the lobby still // matches the recording and every human holds the resume source. { NGMP_OnlineServices_LobbyInterface* pResumeLobby = NGMP_OnlineServicesManager::GetInterface(); @@ -1611,7 +1611,7 @@ void WOLDisplaySlotList(void) /** Initialize the Gadgets Options Menu */ //------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------- -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay arming for online lobbies (host only). +// Resume-from-replay arming for online lobbies (host only). // // Same contract as the LAN lobby (LanGameOptionsMenu.cpp): /resume copies the host's last // recording to Resume.rep and aligns the lobby with it. Online the file is uploaded to the @@ -1678,7 +1678,7 @@ static Bool wolArmedResumeStillMatches(NGMPGame *game) } // ----------------------------------------------------------------------------- -// TheSuperHackers @feature bill-rich 11/10/2026 The arm is a chain of service +// The arm is a chain of service // requests, each started from the previous one's completion: the map, the // starting cash and the superweapon limit (only those that differ from the // recording), then the whole slot table in one piece, then the upload and the @@ -2481,7 +2481,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) { WOLDisplaySlotList(); WOLDisplayGameOptions(); - wolCheckResumeArmChange(); // TheSuperHackers @feature bill-rich 24/09/2026 resume-from-replay arm arrived or left + wolCheckResumeArmChange(); // Resume-from-replay arm arrived or left }); pLobbyInterface->RegisterForGameStartPacket([]() @@ -4116,7 +4116,7 @@ Bool handleGameSetupSlashCommands(UnicodeString uText) #if defined(GENERALS_ONLINE) else if (token == "resume") { - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming lives behind a chat command so no layout change is needed + // Resume-from-replay arming lives behind a chat command so no layout change is needed AsciiString arg; remainder.nextToken(&arg); arg.toLower(); @@ -4628,7 +4628,7 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg } else if ( controlID == buttonResumeID ) { - // TheSuperHackers @feature bill-rich 11/10/2026 Same as /resume and /resume off. + // Same as /resume and /resume off. NGMP_OnlineServices_LobbyInterface* pResumeLobby = NGMP_OnlineServicesManager::GetInterface(); NGMPGame *resumeGame = pResumeLobby ? pResumeLobby->GetCurrentGame() : nullptr; wolTryArmResumeFromReplay(resumeGame != nullptr && resumeGame->isResumeArmed()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp index 01205acccc0..cc61879077e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp @@ -3292,7 +3292,7 @@ Coord2D InGameUI::getScrollAmount() //------------------------------------------------------------------------------------------------- void InGameUI::setGUICommand(const CommandButton* command) { - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay catchup: no GUI commands until control is handed back + // Resume-from-replay catchup: no GUI commands until control is handed back if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK || TheRecorder->isResumeInputBlocked()) return; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 4429ad5eeb1..02e7636ba58 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -2780,7 +2780,7 @@ void GameLogic::processCommandList(CommandList* list) logicMessageDispatcher(msg, NULL); } - // TheSuperHackers @feature bill-rich 15/09/2026 Skip CRC validation while in resume-from-replay + // Skip CRC validation while in resume-from-replay // catchup (the CRC messages of that window come out of the resume source, not from the // live peers) and for one run-ahead after the handoff, until the first set the peers // exchanged live can have arrived. diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp index 8c4981a7ccb..08d513ef342 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp @@ -273,7 +273,7 @@ void HTTPRequest::PlatformStartRequest() } } - // TheSuperHackers @bugfix bill-rich 24/09/2026 Say what the body is. Without a Content-Type + // Say what the body is. Without a Content-Type // libcurl sends application/x-www-form-urlencoded, and a service that form-parses on that // header rejects any body large enough to exceed its form key limit, because the whole // payload reads as one enormous key. Every request built here carries JSON unless the diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index 697910b7888..179a1b92618 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -116,7 +116,7 @@ void NGMPGame::SyncWithLobby(LobbyEntry& lobby) // rng seed setSeed(lobby.rng_seed); - // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (see ResumeFromReplay) + // Resume-from-replay arming (see ResumeFromReplay) setResumeHandoffFrame(lobby.resume_handoff_frame); // observers @@ -514,7 +514,7 @@ void NGMPGame::launchGame(void) return; } - // TheSuperHackers @feature bill-rich 24/09/2026 An armed resume-from-replay needs this client's copy + // An armed resume-from-replay needs this client's copy // of the resume source to match the lobby; when it does not, back out the same way as for a // missing map rather than start a fresh match that would desync everyone. UnicodeString resumeWhy; diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp index 4c33f6377f7..e91bac3daa6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMP_Helpers.cpp @@ -206,7 +206,7 @@ std::string Base64Encode(const std::vector& data) std::string encoded; encoded.reserve((data.size() + 2) / 3 * 4); - // TheSuperHackers @bugfix bill-rich 24/09/2026 A one-byte tail was emitted as "XXX=" instead of "XX==": + // A one-byte tail was emitted as "XXX=" instead of "XX==": // the old padding test compared the consumed index against size + 1, which can never be // true, so every input whose length is 1 mod 3 decoded to one byte too many. for (size_t i = 0; i < data.size(); i += 3) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp index 67d1a637188..e2e5611e11b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.cpp @@ -76,9 +76,9 @@ enum class ELobbyUpdateField MAX_CAMERA_HEIGHT = 17, JOINABILITY = 18, HOST_ACTION_BULK_SLOT_UPDATE = 19, - HOST_ACTION_ARM_RESUME = 20, // TheSuperHackers @feature bill-rich 15/09/2026 resume-from-replay arming (see ResumeFromReplay) - LOCAL_PLAYER_HAS_RESUME_REPLAY = 21, // TheSuperHackers @feature bill-rich 24/09/2026 this member holds a usable copy of the resume source - HOST_ACTION_ALIGN_SLOTS = 22 // TheSuperHackers @feature bill-rich 11/10/2026 resume-from-replay: the whole slot table at once + HOST_ACTION_ARM_RESUME = 20, // Resume-from-replay arming (see ResumeFromReplay) + LOCAL_PLAYER_HAS_RESUME_REPLAY = 21, // This member holds a usable copy of the resume source + HOST_ACTION_ALIGN_SLOTS = 22 // Resume-from-replay: the whole slot table at once }; std::string Base64Encode(const std::vector& data); @@ -550,7 +550,7 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ForceReady() }); } -// TheSuperHackers @feature bill-rich 11/10/2026 Resume-from-replay: the whole slot table in one host action. +// Resume-from-replay: the whole slot table in one host action. // The service rebuilds its member table from this (humans moved, AI and empty slots re-created) or refuses // the lot with a reason; nothing is half-applied. The next lobby push shows the result everywhere. void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_AlignSlots(const std::vector& slots, std::function onDone) @@ -610,7 +610,7 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_AlignSlots(const std }); } -// TheSuperHackers @feature bill-rich 15/09/2026 Resume-from-replay: arm (handoff 0 disarms) the resume source +// Resume-from-replay: arm (handoff 0 disarms) the resume source // the host uploaded. The service stores the handoff frame on the lobby and takes the replay's seed // as the lobby seed, so the next start replays that file in lockstep before live control resumes. // The caller announces the arm only from the success callback: the service refuses an arm without @@ -660,7 +660,7 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ArmResume(uint32_t h }); } -// TheSuperHackers @feature bill-rich 24/09/2026 Whether this member holds a usable copy of the resume source; +// Whether this member holds a usable copy of the resume source; // the host's start is refused until every human does (the way has_map gates the map). void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_HasResumeReplay(bool bHasResumeReplay) { @@ -681,7 +681,7 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_HasResumeReplay(bool }); } -// TheSuperHackers @feature bill-rich 24/09/2026 Host: push the resume source to the service in chunks (the +// Host: push the resume source to the service in chunks (the // service keeps it in memory with the lobby). The first chunk (offset 0) replaces whatever the lobby held. void NGMP_OnlineServices_LobbyInterface::UploadResumeReplay(const AsciiString& path, std::function onComplete) { @@ -752,7 +752,7 @@ void NGMP_OnlineServices_LobbyInterface::SendResumeReplayChunk(int64_t lobbyID, }); } -// TheSuperHackers @feature bill-rich 24/09/2026 Guest: pull the resume source back from the service into the +// Guest: pull the resume source back from the service into the // replay directory, in the chunks the service serves. void NGMP_OnlineServices_LobbyInterface::DownloadResumeReplay(const AsciiString& path, std::function onComplete) { @@ -1238,7 +1238,7 @@ void NGMP_OnlineServices_LobbyInterface::UpdateRoomDataCache(std::function. */ -// TheSuperHackers @feature bill-rich 24/09/2026 Resume-from-replay arming and validation. See the header. +// Resume-from-replay arming and validation. See the header. #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine