Files
SVSimServer/SVSim.EmulatedEntrypoint/Models/Dtos/GuildChat/GuildChatReplayDetailResponse.cs
gamer147 ff77d5e5b6 fix(guild): final-review remediation — replay_detail flat, FK on leader, transaction wraps, _db extraction
C1: replay_detail — flatten stored payload to data level. ChatReplayDetailTask.Parse() calls
new ReplayDetailInfo(data) which unguardedly accesses data[battleId], data[seed], data[vid1],
etc. Wrapping under replay_info key crashes the client. Controller now returns Ok(JsonElement)
directly so stored battle fields are at data root. Wire-shape test added.

C2: Guild.LeaderViewerId long to long?; add HasOne<Viewer> FK with OnDelete=SetNull; migration
AddGuildLeaderViewerIdFk; all consumers null-guarded with ?? 0L.

C3: BreakupAsync — wrap 6 destructive ops in IDbContextTransaction with InMemory fallback.

C4: CommitJoinAsync — wrap member-add + viewer-guildId-set + invite/request cleanup in
IDbContextTransaction with InMemory fallback. Chat event emitted after commit.

I1: GuildController — remove SVSimDbContext field; inject IViewerRepository + IGuildMemberRepository.
Add IGuildMemberRepository.GetViewerIdsInAGuildAsync (batch guild-membership check).
All _db.Viewers / _db.GuildMembers queries replaced with repo calls.

I2: GuildService — extract 3 _db.Viewers queries: GetEquippedEmblemIdAsync (CreateAsync),
LoadGuildProfileBatchAsync (ListOutgoingInvitesAsync + ListPendingJoinRequestsForMyGuildAsync).
Add GuildMemberProfile record with IsOfficialMarkDisplayed. GetEmblemListAsync for EmblemList.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-27 16:33:59 -04:00

33 lines
1.8 KiB
C#

using System.Text.Json.Serialization;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.GuildChat;
/// <summary>
/// Response for POST /guild_chat/replay_detail.
///
/// Wire shape: the stored ReplayPayload JSON is forwarded FLAT as the entire data payload.
/// ChatReplayDetailTask.Parse() calls new ReplayDetailInfo(base.ResponseData["data"]) which
/// then accesses data["battleId"], data["seed"], data["vid1"], etc. directly (no Keys.Contains
/// guards on required fields). Wrapping the payload under a "replay_info" key would crash the
/// client. The controller returns the raw JsonElement directly via Ok(element).
///
/// C1 decision: Option (b) is superseded — client CAN handle a full payload; the bug was the
/// wrapper key. The flat pass-through here is Option (a) variant: emit stored fields at data level.
/// If GetReplayDetailAsync returns null (no stored replay), the controller emits result_code=2
/// to gate the client off unguarded parsing.
/// </summary>
// NOTE: This DTO is unused at runtime — the controller returns ActionResult directly. It is kept
// as documentation of the wire contract and for future typed deserialization tests.
public class GuildChatReplayDetailResponse
{
// Fields are emitted flat at the data level, not under a wrapper key.
// See ReplayDetailInfo.cs in the decompiled client for the full field list.
// Key representative required fields (unguarded access in constructor):
// battleId, seed, fieldId, firstTurn, card_master_id,
// vid1/name1/charaId1/classId1/emblemId1/degreeId1/countryCode1/sleeveId1/battlePoint1/masterPoint1/rank1/isOfficial1/deck1
// vid2/name2/charaId2/classId2/emblemId2/degreeId2/countryCode2/sleeveId2/battlePoint2/masterPoint2/rank2/isOfficial2/deck2
[JsonPropertyName("result_code")]
public int ResultCode { get; set; } = 1;
}