From 46fe93d8066421afa3119de4fec67b52be9b9b80 Mon Sep 17 00:00:00 2001 From: S-Sebb?? Date: Mon, 18 Sep 2023 03:15:04 +0800 Subject: [PATCH] Implemented qrCodeData related functions --- SharedProject/Models/QRCodeData.cs | 10 ++++++++++ .../Controllers/Game/GetDanOdaiController.cs | 1 + .../Controllers/Game/VerifyQrCodeController.cs | 18 +++++++++++++++++- TaikoLocalServer/Services/GameDataService.cs | 18 ++++++++++++++++++ .../Services/Interfaces/IGameDataService.cs | 2 ++ TaikoLocalServer/Settings/DataSettings.cs | 2 ++ TaikoLocalServer/wwwroot/data/movie_data.json | 4 ++-- TaikoLocalServer/wwwroot/data/qrcode_data.json | 6 ++++++ 8 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 SharedProject/Models/QRCodeData.cs create mode 100644 TaikoLocalServer/wwwroot/data/qrcode_data.json diff --git a/SharedProject/Models/QRCodeData.cs b/SharedProject/Models/QRCodeData.cs new file mode 100644 index 0000000..8785b68 --- /dev/null +++ b/SharedProject/Models/QRCodeData.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace SharedProject.Models; + +public class QRCodeData +{ + [JsonPropertyName("serial")] public string Serial { get; set; } = null!; + + [JsonPropertyName("id")] public uint Id { get; set; } +} \ No newline at end of file diff --git a/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs b/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs index 3395fab..a7ec853 100644 --- a/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs +++ b/TaikoLocalServer/Controllers/Game/GetDanOdaiController.cs @@ -46,6 +46,7 @@ public class GetDanOdaiController : BaseController Logger.LogWarning("Requested dan id {Id} does not exist!", danId); continue; } + Logger.LogInformation(odaiData.Stringify()); response.AryOdaiDatas.Add(odaiData); } diff --git a/TaikoLocalServer/Controllers/Game/VerifyQrCodeController.cs b/TaikoLocalServer/Controllers/Game/VerifyQrCodeController.cs index 563fa83..9c8f896 100644 --- a/TaikoLocalServer/Controllers/Game/VerifyQrCodeController.cs +++ b/TaikoLocalServer/Controllers/Game/VerifyQrCodeController.cs @@ -4,16 +4,32 @@ [ApiController] public class VerifyQrCodeController : BaseController { + private readonly IGameDataService gameDataService; + + public VerifyQrCodeController(IGameDataService gameDataService) + { + this.gameDataService = gameDataService; + } + [HttpPost] [Produces("application/protobuf")] public IActionResult VerifyQrCode([FromBody] VerifyQrcodeRequest request) { Logger.LogInformation("VerifyQrCode request : {Request}", request.Stringify()); + var qrCodeDataDictionary = gameDataService.GetQRCodeDataDictionary(); + + qrCodeDataDictionary.TryGetValue(request.QrcodeSerial, out var qrCodeId); + + if (qrCodeId == 0) + { + Logger.LogWarning("Requested QR code serial {Serial} does not exist!", request.QrcodeSerial); + } + var response = new VerifyQrcodeResponse { Result = 1, - QrcodeId = 999999001 + QrcodeId = qrCodeId }; return Ok(response); diff --git a/TaikoLocalServer/Services/GameDataService.cs b/TaikoLocalServer/Services/GameDataService.cs index 4919602..a572cd5 100644 --- a/TaikoLocalServer/Services/GameDataService.cs +++ b/TaikoLocalServer/Services/GameDataService.cs @@ -36,6 +36,8 @@ public class GameDataService : IGameDataService private ImmutableDictionary shopFolderDictionary = ImmutableDictionary.Empty; + private ImmutableDictionary qrCodeDataDictionary = ImmutableDictionary.Empty; + private List musics = new(); private List musicsWithUra = new(); @@ -110,6 +112,11 @@ public class GameDataService : IGameDataService { return lockedSongsList; } + + public ImmutableDictionary GetQRCodeDataDictionary() + { + return qrCodeDataDictionary; + } public async Task InitializeAsync() { @@ -126,6 +133,7 @@ public class GameDataService : IGameDataService var shopFolderDataPath = Path.Combine(dataPath, settings.ShopFolderDataFileName); var tokenDataPath = Path.Combine(dataPath, settings.TokenDataFileName); var lockedSongsDataPath = Path.Combine(dataPath, settings.LockedSongsDataFileName); + var qrCodeDataPath = Path.Combine(dataPath, settings.QRCodeDataFileName); if (File.Exists(compressedMusicInfoPath)) { @@ -145,6 +153,7 @@ public class GameDataService : IGameDataService await using var shopFolderDataFile = File.OpenRead(shopFolderDataPath); await using var tokenDataFile = File.OpenRead(tokenDataPath); await using var lockedSongsDataFile = File.OpenRead(lockedSongsDataPath); + await using var qrCodeDataFile = File.OpenRead(qrCodeDataPath); var infoesData = await JsonSerializer.DeserializeAsync(musicInfoFile); var attributesData = await JsonSerializer.DeserializeAsync(musicAttributeFile); @@ -156,6 +165,7 @@ public class GameDataService : IGameDataService var shopFolderData = await JsonSerializer.DeserializeAsync>(shopFolderDataFile); var tokenData = await JsonSerializer.DeserializeAsync>(tokenDataFile); var lockedSongsData = await JsonSerializer.DeserializeAsync>(lockedSongsDataFile); + var qrCodeData = await JsonSerializer.DeserializeAsync>(qrCodeDataFile); InitializeMusicInfoes(infoesData); @@ -176,6 +186,8 @@ public class GameDataService : IGameDataService InitializeTokenData(tokenData); InitializeLockedSongsData(lockedSongsData); + + InitializeQRCodeData(qrCodeData); } private static void TryDecompressMusicInfo() @@ -272,6 +284,12 @@ public class GameDataService : IGameDataService lockedSongsData.ThrowIfNull("Shouldn't happen!"); lockedSongsList = lockedSongsData["songNo"].ToList(); } + + private void InitializeQRCodeData(List? qrCodeData) + { + qrCodeData.ThrowIfNull("Shouldn't happen!"); + qrCodeDataDictionary = qrCodeData.ToImmutableDictionary(data => data.Serial, data => data.Id); + } private static GetDanOdaiResponse.OdaiData ToResponseOdaiData(DanData data) { diff --git a/TaikoLocalServer/Services/Interfaces/IGameDataService.cs b/TaikoLocalServer/Services/Interfaces/IGameDataService.cs index 82f302d..40bce35 100644 --- a/TaikoLocalServer/Services/Interfaces/IGameDataService.cs +++ b/TaikoLocalServer/Services/Interfaces/IGameDataService.cs @@ -29,5 +29,7 @@ public interface IGameDataService public Dictionary GetTokenDataDictionary(); public List GetLockedSongsList(); + + public ImmutableDictionary GetQRCodeDataDictionary(); } diff --git a/TaikoLocalServer/Settings/DataSettings.cs b/TaikoLocalServer/Settings/DataSettings.cs index ddcdc65..a9a92f8 100644 --- a/TaikoLocalServer/Settings/DataSettings.cs +++ b/TaikoLocalServer/Settings/DataSettings.cs @@ -17,4 +17,6 @@ public class DataSettings public string TokenDataFileName { get; set; } = "token_data.json"; public string LockedSongsDataFileName { get; set; } = "locked_songs_data.json"; + + public string QRCodeDataFileName { get; set; } = "qrcode_data.json"; } \ No newline at end of file diff --git a/TaikoLocalServer/wwwroot/data/movie_data.json b/TaikoLocalServer/wwwroot/data/movie_data.json index f26aa0b..00e2ed7 100644 --- a/TaikoLocalServer/wwwroot/data/movie_data.json +++ b/TaikoLocalServer/wwwroot/data/movie_data.json @@ -1,6 +1,6 @@ [ { - "movie_id": 0, - "enable_days": 0 + "movie_id": 0, + "enable_days": 0 } ] \ No newline at end of file diff --git a/TaikoLocalServer/wwwroot/data/qrcode_data.json b/TaikoLocalServer/wwwroot/data/qrcode_data.json new file mode 100644 index 0000000..76fb6f5 --- /dev/null +++ b/TaikoLocalServer/wwwroot/data/qrcode_data.json @@ -0,0 +1,6 @@ +[ + { + "serial": "", + "id": -1 + } +] \ No newline at end of file