feat(rank-battle): real DoMatching with PvP pair + AI fallback mapping

DoMatchingInternal calls IMatchingPairUpService.TryPairAsync, then maps:
- null result → 3002 RETRY (empty node_server_url, no battle_id)
- IsAiFallback → 3011 AI_BATTLE_MATCHING_SUCCEEDED
- IsOwner → 3007 SUCCEEDED_OWNER (cache pickup)
- joiner → 3004 SUCCEEDED

BuildForRankBattleAsync's InvalidOperationException (typically "no deck
for format") surfaces as 3001 ILLEGAL so the client shows the
matchmaking-error dialog rather than retrying.

card_master_id is a placeholder (0) per the per-battle card-master
split deferral. AI-fallback timing is covered by InProcessPairUp unit
tests; controller tests focus on the wire mapping (3002, 3004, 3007).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-02 01:21:38 -04:00
parent 7c4aa89d45
commit bb63b0df2f
2 changed files with 157 additions and 5 deletions

View File

@@ -107,12 +107,54 @@ public sealed class RankBattleController : ControllerBase
return Ok(new { });
}
// Filled in by Task 9.
private Task<IActionResult> DoMatchingInternal(string mode, Format format, DoMatchingRequestDto req, CancellationToken ct)
private async Task<IActionResult> DoMatchingInternal(string mode, Format format, DoMatchingRequestDto req, CancellationToken ct)
{
if (!TryGetViewerId(out var _)) return Task.FromResult<IActionResult>(Unauthorized());
// Placeholder; real impl arrives in Task 9.
return Task.FromResult<IActionResult>(Ok(new DoMatchingResponseDto { MatchingState = 3002 }));
if (!TryGetViewerId(out var vid)) return Unauthorized();
MatchContext ctx;
try
{
ctx = await _ctxBuilder.BuildForRankBattleAsync(vid, format);
}
catch (InvalidOperationException ex)
{
// Most likely cause: viewer has no deck for this format. Surface as 3001
// RC_BATTLE_MATCHING_ILLEGAL — the client shows the standard matchmaking-error
// dialog rather than retrying forever.
_log.LogWarning(ex, "BuildForRankBattleAsync failed for viewer {Vid} format {Fmt}; returning 3001.", vid, format);
return Ok(new DoMatchingResponseDto { MatchingState = 3001, NodeServerUrl = "" });
}
var paired = await _pairUp.TryPairAsync(mode, new BattlePlayer(vid, ctx), ct);
if (paired is null)
{
// Parked. 3002 RETRY. node_server_url must be present as empty string —
// client's DoMatchingBase parser calls .ToString() without a guard.
return Ok(new DoMatchingResponseDto
{
MatchingState = 3002,
NodeServerUrl = "",
});
}
// Owner cache-pickup → 3007 (PvP) or 3011 (AI fallback).
// Joiner (only PvP) → 3004.
var state = paired switch
{
{ IsAiFallback: true } => 3011,
{ IsOwner: true } => 3007,
_ => 3004,
};
return Ok(new DoMatchingResponseDto
{
MatchingState = state,
BattleId = paired.Match.BattleId,
NodeServerUrl = paired.Match.NodeServerUrl,
// Placeholder per spec § Out of scope — per-battle card-master split is deferred.
CardMasterId = 0,
});
}
// Filled in by Task 10.