From 43e4c06a2cf877b6916c76126f2e54ba512cc3c9 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Fri, 12 Jun 2026 23:08:42 -0400 Subject: [PATCH] =?UTF-8?q?feat(mypage):=20/mypage/finish=5Fbattle=20(retu?= =?UTF-8?q?rns=20check=3D0=20=E2=80=94=20no=20in-flight=20state=20yet)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MyPageController.cs | 9 ++++++ .../MyPage/MyPageFinishBattleRequest.cs | 14 ++++++++++ .../MyPage/MyPageFinishBattleResponse.cs | 17 +++++++++++ .../MyPageControllerFinishBattleTests.cs | 28 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 SVSim.EmulatedEntrypoint/Models/Dtos/Requests/MyPage/MyPageFinishBattleRequest.cs create mode 100644 SVSim.EmulatedEntrypoint/Models/Dtos/Responses/MyPage/MyPageFinishBattleResponse.cs create mode 100644 SVSim.UnitTests/Controllers/MyPageControllerFinishBattleTests.cs diff --git a/SVSim.EmulatedEntrypoint/Controllers/MyPageController.cs b/SVSim.EmulatedEntrypoint/Controllers/MyPageController.cs index 7d7f9e3b..fbcdf8c0 100644 --- a/SVSim.EmulatedEntrypoint/Controllers/MyPageController.cs +++ b/SVSim.EmulatedEntrypoint/Controllers/MyPageController.cs @@ -10,7 +10,9 @@ using SVSim.EmulatedEntrypoint.Constants; using SVSim.EmulatedEntrypoint.Infrastructure; using SVSim.EmulatedEntrypoint.Models.Dtos; using SVSim.EmulatedEntrypoint.Models.Dtos.Requests; +using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.MyPage; using SVSim.EmulatedEntrypoint.Models.Dtos.Responses; +using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.MyPage; using SVSim.EmulatedEntrypoint.Services; namespace SVSim.EmulatedEntrypoint.Controllers; @@ -361,4 +363,11 @@ public class MyPageController : SVSimController EndTime = row.EndTime.ToString(WireDateFormat, CultureInfo.InvariantCulture), }; } + + [HttpPost("finish_battle")] + public ActionResult FinishBattle([FromBody] MyPageFinishBattleRequest _) + { + if (!TryGetViewerId(out long __)) return Unauthorized(); + return new MyPageFinishBattleResponse { CheckUnfinishedBattle = 0 }; + } } diff --git a/SVSim.EmulatedEntrypoint/Models/Dtos/Requests/MyPage/MyPageFinishBattleRequest.cs b/SVSim.EmulatedEntrypoint/Models/Dtos/Requests/MyPage/MyPageFinishBattleRequest.cs new file mode 100644 index 00000000..c009c749 --- /dev/null +++ b/SVSim.EmulatedEntrypoint/Models/Dtos/Requests/MyPage/MyPageFinishBattleRequest.cs @@ -0,0 +1,14 @@ +using MessagePack; +using System.Text.Json.Serialization; + +namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.MyPage; + +[MessagePackObject] +public class MyPageFinishBattleRequest : BaseRequest +{ + // Wire key is uppercase "SDTRB" — verbatim from + // PlayerPrefsWrapper.SELF_DISCONNECT_OPEN_STATUS_TO_REPLACE_LOG. + [JsonPropertyName("SDTRB")] + [Key("SDTRB")] + public int Sdtrb { get; set; } +} diff --git a/SVSim.EmulatedEntrypoint/Models/Dtos/Responses/MyPage/MyPageFinishBattleResponse.cs b/SVSim.EmulatedEntrypoint/Models/Dtos/Responses/MyPage/MyPageFinishBattleResponse.cs new file mode 100644 index 00000000..d00c75fb --- /dev/null +++ b/SVSim.EmulatedEntrypoint/Models/Dtos/Responses/MyPage/MyPageFinishBattleResponse.cs @@ -0,0 +1,17 @@ +using MessagePack; +using System.Text.Json.Serialization; + +namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.MyPage; + +/// +/// Spec source: docs/api-spec/endpoints/post-login/mypage-finish-battle.md. +/// We always emit check_unfinished_battle=0 because no in-flight battle state +/// is tracked server-side yet. When that lands, branch to is_win + class/rank refresh. +/// +[MessagePackObject] +public class MyPageFinishBattleResponse +{ + [JsonPropertyName("check_unfinished_battle")] + [Key("check_unfinished_battle")] + public int CheckUnfinishedBattle { get; set; } +} diff --git a/SVSim.UnitTests/Controllers/MyPageControllerFinishBattleTests.cs b/SVSim.UnitTests/Controllers/MyPageControllerFinishBattleTests.cs new file mode 100644 index 00000000..7dcb957a --- /dev/null +++ b/SVSim.UnitTests/Controllers/MyPageControllerFinishBattleTests.cs @@ -0,0 +1,28 @@ +using System.Net; +using System.Text; +using System.Text.Json; +using NUnit.Framework; +using SVSim.UnitTests.Infrastructure; + +namespace SVSim.UnitTests.Controllers; + +public class MyPageControllerFinishBattleTests +{ + [Test] + public async Task FinishBattle_returns_check_zero() + { + using var factory = new SVSimTestFactory(); + long viewerId = await factory.SeedViewerAsync(tutorialState: 0); + using var client = factory.CreateAuthenticatedClient(viewerId); + + var requestJson = """{"SDTRB":0,"viewer_id":"0","steam_id":0,"steam_session_ticket":""}"""; + var response = await client.PostAsync("/mypage/finish_battle", + new StringContent(requestJson, Encoding.UTF8, "application/json")); + + Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); + + var body = await response.Content.ReadAsStringAsync(); + using var doc = JsonDocument.Parse(body); + Assert.That(doc.RootElement.GetProperty("check_unfinished_battle").GetInt32(), Is.EqualTo(0)); + } +}