fix(tutorial): /tutorial/update preserves max TutorialState

The endpoint used to write the client-supplied step verbatim, so a stale or
replayed request with tutorial_step=0 against any later-stage viewer would
regress the persisted state to 0. NextSceneSwitcher routes step==0 to
AreaSelect section 0, which has no chapter data — the client LINQ-Single()
crashes on next /load/index, bricking the viewer. Math.Max-preserve matches
the 31→41 pattern in GiftController.TutorialGiftReceive.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-28 20:22:59 -04:00
parent ac077dfc13
commit 6fd8705990
2 changed files with 30 additions and 1 deletions

View File

@@ -36,7 +36,14 @@ public class TutorialController : SVSimController
.Include(v => v.MissionData)
.FirstAsync(v => v.Id == viewerId);
viewer.MissionData.TutorialState = request.TutorialStep;
// Preserve max — never regress. Mirrors GiftController.TutorialGiftReceive's 31→41 guard.
// Without this, a stale or replayed request with tutorial_step=0 (or any value below the
// viewer's current state) crashes the client on next /load/index: NextSceneSwitcher routes
// step==0 to AreaSelect section 0, which has no chapter data → LINQ Single() failure.
// Response keeps echoing request.TutorialStep so the client's own transition confirmation
// still works; the client owns the step-it-thinks-it's-moving-to concept and we don't
// want to surface a divergent value mid-flow.
viewer.MissionData.TutorialState = Math.Max(viewer.MissionData.TutorialState, request.TutorialStep);
await _db.SaveChangesAsync();
return new TutorialUpdateResponse { TutorialStep = request.TutorialStep };