Skip to content

Commit da5e728

Browse files
authored
fix: handle :MISSION:SAVED: async callback from extension (#114)
* feat(extension): handle :MISSION:SAVED: async callback * fix(recorder): remove misleading sync save logging in fnc_exportData * review(addon): type-validate :MISSION:SAVED: payload and defer final diary
1 parent 502df91 commit da5e728

2 files changed

Lines changed: 85 additions & 7 deletions

File tree

addons/extension/fnc_initSession.sqf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,78 @@ addMissionEventHandler ["ExtensionCallback", {
154154
INFO("Mission registered. Starting data send.");
155155
GVAR(sessionReady) = true;
156156
};
157+
158+
if (_function isEqualTo ":MISSION:SAVED:") exitWith {
159+
// Payload shapes:
160+
// ["ok", path]
161+
// ["partial", path, error]
162+
// ["error", error]
163+
// Type-check each field: if the extension ever sends something
164+
// unexpected, fall back to an empty string rather than crashing
165+
// the callback handler with a type error in the switch below.
166+
private _status = _data param [0, "", [""]];
167+
private _detail = _data param [1, "", [""]];
168+
private _extra = _data param [2, "", [""]];
169+
170+
// finalDiary appends a final status entry to the OCAPInfo diary
171+
// subject so the interim "being saved" record from fnc_exportData.sqf
172+
// is followed by the authoritative outcome.
173+
private _finalDiary = {
174+
params ["_diaryHtml"];
175+
[[_diaryHtml], {
176+
params ["_html"];
177+
player createDiaryRecord [
178+
"OCAPInfo",
179+
["Status", _html]
180+
];
181+
}] remoteExec ["call", [0, -2] select isDedicated, true];
182+
};
183+
184+
switch (_status) do {
185+
case "ok": {
186+
INFO_1("Mission save complete — path: %1",_detail);
187+
GVAR(lastSaveResult) = ["ok", _detail];
188+
[
189+
format["OCAP saved %1 successfully", briefingName],
190+
2,
191+
[0, 0.8, 0, 1]
192+
] remoteExec ["CBA_fnc_notify", [0, -2] select isDedicated];
193+
[format[
194+
"<font color='#33FF33'>OCAP capture of %1 has been exported and uploaded successfully.</font>",
195+
briefingName
196+
]] call _finalDiary;
197+
};
198+
case "partial": {
199+
WARNING_2("Mission save complete but upload failed — path: %1 error: %2",_detail,_extra);
200+
GVAR(lastSaveResult) = ["partial", _detail, _extra];
201+
[
202+
format["OCAP saved locally (%1) but upload failed: %2", _detail, _extra],
203+
2,
204+
[1, 0.8, 0, 1]
205+
] remoteExec ["CBA_fnc_notify", [0, -2] select isDedicated];
206+
[format[
207+
"<font color='#FFCC00'>OCAP capture of %1 was saved locally to %2, but the upload to the web server failed:</font><br/>%3",
208+
briefingName, _detail, _extra
209+
]] call _finalDiary;
210+
};
211+
case "error": {
212+
ERROR_MSG_1("Mission save failed: %1",_detail);
213+
GVAR(lastSaveResult) = ["error", _detail];
214+
[
215+
format["OCAP save failed: %1", _detail],
216+
2,
217+
[1, 0, 0, 1]
218+
] remoteExec ["CBA_fnc_notify", [0, -2] select isDedicated];
219+
[format[
220+
"<font color='#FF3333'>OCAP save of %1 failed:</font><br/>%2",
221+
briefingName, _detail
222+
]] call _finalDiary;
223+
};
224+
default {
225+
WARNING_1("Unknown :MISSION:SAVED: status: %1",_status);
226+
};
227+
};
228+
};
157229
}];
158230

159231

addons/recorder/fnc_exportData.sqf

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,20 @@ private _endMessage = if (isNil "_message") then {if (_winSide == "") then {"Mis
123123

124124
private _saveTag = if (!isNil "_tag") then {_tag} else {EGVAR(settings,saveTag)};
125125
INFO_3("Saving recording — mission: %1 | frames: %2 | tag: %3",GVAR(missionName),_endFrameNumber,_saveTag);
126-
private _saveStart = diag_tickTime;
127-
[":MISSION:SAVE:", []] call EFUNC(extension,sendData);
128-
INFO_2("Recording saved — took %1 ms | mission: %2",round ((diag_tickTime - _saveStart) * 1000),GVAR(missionName));
129-
OCAPEXTLOG(ARR4("Saved recording of mission",GVAR(missionName),"with tag",_saveTag));
130126

127+
// Save is now asynchronous — the extension returns immediately and will fire
128+
// a :MISSION:SAVED: ExtensionCallback when the write + upload finishes.
129+
// The final success/failure notification is driven from that callback in
130+
// fnc_initSession.sqf.
131+
INFO_2("Mission save queued — mission: %1 | frames: %2",GVAR(missionName),_endFrameNumber);
132+
[":MISSION:SAVE:", []] call EFUNC(extension,sendData);
133+
OCAPEXTLOG(ARR4("Queued recording of mission",GVAR(missionName),"with tag",_saveTag));
131134

132-
// notify players that the recording was saved with a 2 second delay to ensure the "stopped recording" entries populate first
133-
[format["OCAP saved %1 frames successfully", _endFrameNumber], 1, [1, 1, 1, 1]] remoteExec ["CBA_fnc_notify", [0, -2] select isDedicated];
135+
// Interim "saving..." toast; the final result comes from :MISSION:SAVED:
136+
[format["OCAP saving %1 (%2 frames) — upload will follow", briefingName, _endFrameNumber], 1, [1, 1, 1, 1]] remoteExec ["CBA_fnc_notify", [0, -2] select isDedicated];
137+
// Interim diary record. The final "exported successfully" / "upload failed"
138+
// record is appended from the :MISSION:SAVED: ExtensionCallback handler in
139+
// fnc_initSession.sqf once the async save completes.
134140
[[GVAR(missionName), GVAR(captureFrameNo)], {
135141
params ["_missionName", "_endFrame"];
136142

@@ -143,7 +149,7 @@ OCAPEXTLOG(ARR4("Saved recording of mission",GVAR(missionName),"with tag",_saveT
143149
[
144150
"Status",
145151
format[
146-
"<font color='#33FF33'>OCAP capture of %1 has been exported with %2 frames saved.</font><br/><br/>Upload results have been logged.",
152+
"<font color='#FFFF33'>OCAP capture of %1 with %2 frames is being saved and uploaded.</font><br/><br/>Final status will be reported when the upload completes.",
147153
_missionName,
148154
_endFrame
149155
]

0 commit comments

Comments
 (0)