diff --git a/SVSim.EmulatedEntrypoint/Controllers/AccountController.cs b/SVSim.EmulatedEntrypoint/Controllers/AccountController.cs index bc9be0cd..91a41b12 100644 --- a/SVSim.EmulatedEntrypoint/Controllers/AccountController.cs +++ b/SVSim.EmulatedEntrypoint/Controllers/AccountController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using SVSim.Database; +using SVSim.EmulatedEntrypoint.Models.Dtos.Common; using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Account; namespace SVSim.EmulatedEntrypoint.Controllers; @@ -46,4 +47,14 @@ public class AccountController : SVSimController // so the translation middleware emits the right msgpack shape. return Ok(Array.Empty()); } + + [HttpPost("update_region_code")] + public ActionResult UpdateRegionCode([FromBody] AccountUpdateRegionCodeRequest _) + { + if (!TryGetViewerId(out long __)) return Unauthorized(); + // No-op: actual region value is sent in the REGION_CODE HTTP header, which we + // don't currently consume server-side. The body carries only initialize_flag, + // which is a first-set-vs-update signal we have no use for yet. + return new EmptyResponse(); + } } diff --git a/SVSim.EmulatedEntrypoint/Models/Dtos/Requests/Account/AccountUpdateRegionCodeRequest.cs b/SVSim.EmulatedEntrypoint/Models/Dtos/Requests/Account/AccountUpdateRegionCodeRequest.cs new file mode 100644 index 00000000..ed640c0f --- /dev/null +++ b/SVSim.EmulatedEntrypoint/Models/Dtos/Requests/Account/AccountUpdateRegionCodeRequest.cs @@ -0,0 +1,12 @@ +using MessagePack; +using System.Text.Json.Serialization; + +namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Account; + +[MessagePackObject] +public class AccountUpdateRegionCodeRequest : BaseRequest +{ + [JsonPropertyName("initialize_flag")] + [Key("initialize_flag")] + public int InitializeFlag { get; set; } +} diff --git a/SVSim.UnitTests/Controllers/AccountControllerUpdateRegionCodeTests.cs b/SVSim.UnitTests/Controllers/AccountControllerUpdateRegionCodeTests.cs new file mode 100644 index 00000000..dc184717 --- /dev/null +++ b/SVSim.UnitTests/Controllers/AccountControllerUpdateRegionCodeTests.cs @@ -0,0 +1,24 @@ +using System.Net; +using System.Text; +using NUnit.Framework; +using SVSim.UnitTests.Infrastructure; + +namespace SVSim.UnitTests.Controllers; + +public class AccountControllerUpdateRegionCodeTests +{ + [TestCase(0)] + [TestCase(1)] + public async Task UpdateRegionCode_accepts(int initializeFlag) + { + using var factory = new SVSimTestFactory(); + long viewerId = await factory.SeedViewerAsync(tutorialState: 0); + using var client = factory.CreateAuthenticatedClient(viewerId); + + var requestJson = $$"""{"initialize_flag":{{initializeFlag}},"viewer_id":"0","steam_id":0,"steam_session_ticket":""}"""; + var response = await client.PostAsync("/account/update_region_code", + new StringContent(requestJson, Encoding.UTF8, "application/json")); + + Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); + } +}