diff --git a/TaikoLocalServer/Controllers/Game/AddTokenCountController.cs b/TaikoLocalServer/Controllers/Game/AddTokenCountController.cs index fcf0618..36c9fda 100644 --- a/TaikoLocalServer/Controllers/Game/AddTokenCountController.cs +++ b/TaikoLocalServer/Controllers/Game/AddTokenCountController.cs @@ -1,15 +1,56 @@ -namespace TaikoLocalServer.Controllers.Game; +using System.Text.Json; +using Throw; + +namespace TaikoLocalServer.Controllers.Game; [Route("/v12r00_cn/chassis/addtokencount.php")] [ApiController] public class AddTokenCountController : BaseController { + private readonly IUserDatumService userDatumService; + + public AddTokenCountController(IUserDatumService userDatumService) + { + this.userDatumService = userDatumService; + } + [HttpPost] [Produces("application/protobuf")] - public IActionResult AddTokenCount([FromBody] AddTokenCountRequest request) + public async Task AddTokenCount([FromBody] AddTokenCountRequest request) { Logger.LogInformation("AddTokenCount request : {Request}", request.Stringify()); + var user = await userDatumService.GetFirstUserDatumOrNull(request.Baid); + user.ThrowIfNull($"User with baid {request.Baid} does not exist!"); + + var tokenCountDict = new Dictionary(); + try + { + tokenCountDict = !string.IsNullOrEmpty(user.TokenCountDict) + ? JsonSerializer.Deserialize>(user.TokenCountDict) + : new Dictionary(); + } + catch (JsonException e) + { + Logger.LogError(e, "Parsing TokenCountDict data for user with baid {Request} failed!", request.Baid); + } + + tokenCountDict.ThrowIfNull("TokenCountDict should never be null"); + + foreach (var addTokenCountData in request.AryAddTokenCountDatas) + { + var tokenId = addTokenCountData.TokenId; + var addTokenCount = addTokenCountData.AddTokenCount; + + if (tokenCountDict.ContainsKey(tokenId)) + tokenCountDict[tokenId] += addTokenCount; + else + tokenCountDict.Add(tokenId, addTokenCount); + } + + user.TokenCountDict = JsonSerializer.Serialize(tokenCountDict); + await userDatumService.UpdateUserDatum(user); + var response = new AddTokenCountResponse { Result = 1 diff --git a/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs b/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs index a1072ca..8819e69 100644 --- a/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs +++ b/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs @@ -22,10 +22,10 @@ public class GetDanOdaiController : BaseController Result = 1 }; - if (request.Type == 2) - { - return Ok(response); - } + // if (request.Type == 2) + // { + // return Ok(response); + // } foreach (var danId in request.DanIds) { diff --git a/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs b/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs index d8dfc37..fc6db04 100644 --- a/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs +++ b/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs @@ -39,6 +39,9 @@ public class InitialDataCheckController : BaseController new InitialdatacheckResponse.VerupNoData1 @@ -65,6 +68,13 @@ public class InitialDataCheckController : BaseController(); foreach (var folderId in Constants.EVENT_FOLDER_IDS) { @@ -98,9 +108,6 @@ public class InitialDataCheckController : BaseController var response = new VerifyQrcodeResponse { Result = 1, - QrcodeId = 1 + QrcodeId = 999999001 }; return Ok(response);