diff --git a/addons/database/XEH_prep.sqf b/addons/database/XEH_prep.sqf index 9e70f9b..56e6867 100644 --- a/addons/database/XEH_prep.sqf +++ b/addons/database/XEH_prep.sqf @@ -4,6 +4,7 @@ PREP(addEventHandlers); PREP(getStaticObjects); PREP(handleChatMessage); PREP(initDB); +PREP(newMission); PREP(radioEvent); PREP(metricsLoop); PREP(eh_fired_server); diff --git a/addons/database/fnc_initDB.sqf b/addons/database/fnc_initDB.sqf index a516981..ca8f70c 100644 --- a/addons/database/fnc_initDB.sqf +++ b/addons/database/fnc_initDB.sqf @@ -158,11 +158,14 @@ addMissionEventHandler ["ExtensionCallback", { INFO("Mission saved to DB. Starting data send."); GVAR(dbValid) = true; - // set initial stuff unique to DB - [] spawn FUNC(getStaticObjects); - call FUNC(addEventHandlers); - call FUNC(eh_fired_server); - call FUNC(metricsLoop); + // Only run one-time setup on first init, not on re-registration after export + if (isNil QGVAR(initialSetupDone)) then { + GVAR(initialSetupDone) = true; + [] spawn FUNC(getStaticObjects); + call FUNC(addEventHandlers); + call FUNC(eh_fired_server); + call FUNC(metricsLoop); + }; }; }]; diff --git a/addons/database/fnc_newMission.sqf b/addons/database/fnc_newMission.sqf new file mode 100644 index 0000000..7847000 --- /dev/null +++ b/addons/database/fnc_newMission.sqf @@ -0,0 +1,37 @@ +/* ---------------------------------------------------------------------------- +FILE: fnc_newMission.sqf + +FUNCTION: OCAP_database_fnc_newMission + +Description: + Re-registers a new mission session with the extension after a previous + recording was exported via fnc_exportData. Reuses the cached world and + mission context from the initial initDB call (same mission is still running). + + The existing ExtensionCallback handler (added during initDB) will process + the :MISSION:OK: response and set dbValid = true. + + Called from fnc_startRecording when starting a fresh recording with + dbValid = false. + +Parameters: + None + +Returns: + Nothing + +Public: + No + +Author: + Fank +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +if (isNil QGVAR(worldContext) || isNil QGVAR(missionContext)) exitWith { + ERROR("Cannot re-register mission: cached world/mission context is nil. Full initDB required."); +}; + +INFO("Re-registering new mission with extension"); +GVAR(initTimer) = diag_tickTime; +[":NEW:MISSION:", [GVAR(worldContext), GVAR(missionContext)], 'ocap_recorder'] call EFUNC(extension,sendData); diff --git a/addons/extension/fnc_sendData.sqf b/addons/extension/fnc_sendData.sqf index fd30b6d..9c47c77 100644 --- a/addons/extension/fnc_sendData.sqf +++ b/addons/extension/fnc_sendData.sqf @@ -34,11 +34,15 @@ _res params ["_result","_returnCode","_errorCode"]; diag_log text format ["[OCAP] [EXT] << Response: result='%1', returnCode=%2, errorCode=%3", _result, _returnCode, _errorCode]; -if (_errorCode != 0 || _returnCode != 0) exitWith { - diag_log text format ["[OCAP] [EXT] ERROR when calling extension: %1", [_result, _returnCode, _errorCode, _command, _args]]; +if (_returnCode != 0) exitWith { + diag_log text format ["[OCAP] [EXT] ERROR from extension (returnCode=%1): %2", _returnCode, [_result, _returnCode, _errorCode, _command, _args]]; nil }; +if (_errorCode != 0) then { + diag_log text format ["[OCAP] [EXT] WARNING: Arma errorCode=%1 for command '%2' (result still valid)", _errorCode, _command]; +}; + // Parse the response - new format: ["ok", ] or ["error", ""] if (_result isEqualTo "") exitWith { diag_log text "[OCAP] [EXT] WARNING: Empty response from extension"; diff --git a/addons/recorder/fnc_exportData.sqf b/addons/recorder/fnc_exportData.sqf index f2f717e..9ac6701 100644 --- a/addons/recorder/fnc_exportData.sqf +++ b/addons/recorder/fnc_exportData.sqf @@ -163,3 +163,4 @@ GVAR(startTime) = nil; _x setVariable [QGVARMAIN(unitType), nil]; } count (allUnits + allDeadMen + vehicles); GVAR(nextId) = 0; +EGVAR(database,dbValid) = false; diff --git a/addons/recorder/fnc_startRecording.sqf b/addons/recorder/fnc_startRecording.sqf index 1dc3cbf..00bae67 100644 --- a/addons/recorder/fnc_startRecording.sqf +++ b/addons/recorder/fnc_startRecording.sqf @@ -64,7 +64,19 @@ _missionDateFormat append (date apply {if (_x < 10) then {"0" + str _x} else {st }] remoteExec ["call", [0, -2] select isDedicated, true]; if (GVAR(captureFrameNo) == 0) then { - call FUNC(captureLoop); + if (!EGVAR(database,dbValid)) then { + // Previous recording was exported — re-register new mission with extension + call EFUNC(database,newMission); + // Wait for extension to confirm new mission before starting capture + [{EGVAR(database,dbValid)}, { + call FUNC(captureLoop); + }, [], 30, { + ERROR("Timeout waiting for new mission confirmation from extension. Recording will not start."); + ["OCAP failed to start recording: extension did not respond", 1, [1, 0, 0, 1]] remoteExecCall ["CBA_fnc_notify", [0, -2] select isDedicated]; + }] call CBA_fnc_waitUntilAndExecute; + } else { + call FUNC(captureLoop); + }; }; [QGVARMAIN(customEvent), ["generalEvent", "Recording started."]] call CBA_fnc_serverEvent;