Implemented qrCodeData related functions
This commit is contained in:
parent
7dd43d2617
commit
46fe93d806
10
SharedProject/Models/QRCodeData.cs
Normal file
10
SharedProject/Models/QRCodeData.cs
Normal file
@ -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; }
|
||||||
|
}
|
@ -46,6 +46,7 @@ public class GetDanOdaiController : BaseController<GetDanOdaiController>
|
|||||||
Logger.LogWarning("Requested dan id {Id} does not exist!", danId);
|
Logger.LogWarning("Requested dan id {Id} does not exist!", danId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Logger.LogInformation(odaiData.Stringify());
|
||||||
|
|
||||||
response.AryOdaiDatas.Add(odaiData);
|
response.AryOdaiDatas.Add(odaiData);
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,32 @@
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class VerifyQrCodeController : BaseController<VerifyQrCodeController>
|
public class VerifyQrCodeController : BaseController<VerifyQrCodeController>
|
||||||
{
|
{
|
||||||
|
private readonly IGameDataService gameDataService;
|
||||||
|
|
||||||
|
public VerifyQrCodeController(IGameDataService gameDataService)
|
||||||
|
{
|
||||||
|
this.gameDataService = gameDataService;
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/protobuf")]
|
[Produces("application/protobuf")]
|
||||||
public IActionResult VerifyQrCode([FromBody] VerifyQrcodeRequest request)
|
public IActionResult VerifyQrCode([FromBody] VerifyQrcodeRequest request)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("VerifyQrCode request : {Request}", request.Stringify());
|
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
|
var response = new VerifyQrcodeResponse
|
||||||
{
|
{
|
||||||
Result = 1,
|
Result = 1,
|
||||||
QrcodeId = 999999001
|
QrcodeId = qrCodeId
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
|
@ -36,6 +36,8 @@ public class GameDataService : IGameDataService
|
|||||||
private ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData> shopFolderDictionary =
|
private ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData> shopFolderDictionary =
|
||||||
ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData>.Empty;
|
ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData>.Empty;
|
||||||
|
|
||||||
|
private ImmutableDictionary<string, uint> qrCodeDataDictionary = ImmutableDictionary<string, uint>.Empty;
|
||||||
|
|
||||||
private List<uint> musics = new();
|
private List<uint> musics = new();
|
||||||
|
|
||||||
private List<uint> musicsWithUra = new();
|
private List<uint> musicsWithUra = new();
|
||||||
@ -111,6 +113,11 @@ public class GameDataService : IGameDataService
|
|||||||
return lockedSongsList;
|
return lockedSongsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImmutableDictionary<string, uint> GetQRCodeDataDictionary()
|
||||||
|
{
|
||||||
|
return qrCodeDataDictionary;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task InitializeAsync()
|
public async Task InitializeAsync()
|
||||||
{
|
{
|
||||||
var dataPath = PathHelper.GetDataPath();
|
var dataPath = PathHelper.GetDataPath();
|
||||||
@ -126,6 +133,7 @@ public class GameDataService : IGameDataService
|
|||||||
var shopFolderDataPath = Path.Combine(dataPath, settings.ShopFolderDataFileName);
|
var shopFolderDataPath = Path.Combine(dataPath, settings.ShopFolderDataFileName);
|
||||||
var tokenDataPath = Path.Combine(dataPath, settings.TokenDataFileName);
|
var tokenDataPath = Path.Combine(dataPath, settings.TokenDataFileName);
|
||||||
var lockedSongsDataPath = Path.Combine(dataPath, settings.LockedSongsDataFileName);
|
var lockedSongsDataPath = Path.Combine(dataPath, settings.LockedSongsDataFileName);
|
||||||
|
var qrCodeDataPath = Path.Combine(dataPath, settings.QRCodeDataFileName);
|
||||||
|
|
||||||
if (File.Exists(compressedMusicInfoPath))
|
if (File.Exists(compressedMusicInfoPath))
|
||||||
{
|
{
|
||||||
@ -145,6 +153,7 @@ public class GameDataService : IGameDataService
|
|||||||
await using var shopFolderDataFile = File.OpenRead(shopFolderDataPath);
|
await using var shopFolderDataFile = File.OpenRead(shopFolderDataPath);
|
||||||
await using var tokenDataFile = File.OpenRead(tokenDataPath);
|
await using var tokenDataFile = File.OpenRead(tokenDataPath);
|
||||||
await using var lockedSongsDataFile = File.OpenRead(lockedSongsDataPath);
|
await using var lockedSongsDataFile = File.OpenRead(lockedSongsDataPath);
|
||||||
|
await using var qrCodeDataFile = File.OpenRead(qrCodeDataPath);
|
||||||
|
|
||||||
var infoesData = await JsonSerializer.DeserializeAsync<MusicInfoes>(musicInfoFile);
|
var infoesData = await JsonSerializer.DeserializeAsync<MusicInfoes>(musicInfoFile);
|
||||||
var attributesData = await JsonSerializer.DeserializeAsync<MusicAttributes>(musicAttributeFile);
|
var attributesData = await JsonSerializer.DeserializeAsync<MusicAttributes>(musicAttributeFile);
|
||||||
@ -156,6 +165,7 @@ public class GameDataService : IGameDataService
|
|||||||
var shopFolderData = await JsonSerializer.DeserializeAsync<List<ShopFolderData>>(shopFolderDataFile);
|
var shopFolderData = await JsonSerializer.DeserializeAsync<List<ShopFolderData>>(shopFolderDataFile);
|
||||||
var tokenData = await JsonSerializer.DeserializeAsync<Dictionary<string, int>>(tokenDataFile);
|
var tokenData = await JsonSerializer.DeserializeAsync<Dictionary<string, int>>(tokenDataFile);
|
||||||
var lockedSongsData = await JsonSerializer.DeserializeAsync<Dictionary<string, uint[]>>(lockedSongsDataFile);
|
var lockedSongsData = await JsonSerializer.DeserializeAsync<Dictionary<string, uint[]>>(lockedSongsDataFile);
|
||||||
|
var qrCodeData = await JsonSerializer.DeserializeAsync<List<QRCodeData>>(qrCodeDataFile);
|
||||||
|
|
||||||
InitializeMusicInfoes(infoesData);
|
InitializeMusicInfoes(infoesData);
|
||||||
|
|
||||||
@ -176,6 +186,8 @@ public class GameDataService : IGameDataService
|
|||||||
InitializeTokenData(tokenData);
|
InitializeTokenData(tokenData);
|
||||||
|
|
||||||
InitializeLockedSongsData(lockedSongsData);
|
InitializeLockedSongsData(lockedSongsData);
|
||||||
|
|
||||||
|
InitializeQRCodeData(qrCodeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TryDecompressMusicInfo()
|
private static void TryDecompressMusicInfo()
|
||||||
@ -273,6 +285,12 @@ public class GameDataService : IGameDataService
|
|||||||
lockedSongsList = lockedSongsData["songNo"].ToList();
|
lockedSongsList = lockedSongsData["songNo"].ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitializeQRCodeData(List<QRCodeData>? qrCodeData)
|
||||||
|
{
|
||||||
|
qrCodeData.ThrowIfNull("Shouldn't happen!");
|
||||||
|
qrCodeDataDictionary = qrCodeData.ToImmutableDictionary(data => data.Serial, data => data.Id);
|
||||||
|
}
|
||||||
|
|
||||||
private static GetDanOdaiResponse.OdaiData ToResponseOdaiData(DanData data)
|
private static GetDanOdaiResponse.OdaiData ToResponseOdaiData(DanData data)
|
||||||
{
|
{
|
||||||
var responseOdaiData = new GetDanOdaiResponse.OdaiData
|
var responseOdaiData = new GetDanOdaiResponse.OdaiData
|
||||||
|
@ -29,5 +29,7 @@ public interface IGameDataService
|
|||||||
public Dictionary<string, int> GetTokenDataDictionary();
|
public Dictionary<string, int> GetTokenDataDictionary();
|
||||||
|
|
||||||
public List<uint> GetLockedSongsList();
|
public List<uint> GetLockedSongsList();
|
||||||
|
|
||||||
|
public ImmutableDictionary<string, uint> GetQRCodeDataDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,4 +17,6 @@ public class DataSettings
|
|||||||
public string TokenDataFileName { get; set; } = "token_data.json";
|
public string TokenDataFileName { get; set; } = "token_data.json";
|
||||||
|
|
||||||
public string LockedSongsDataFileName { get; set; } = "locked_songs_data.json";
|
public string LockedSongsDataFileName { get; set; } = "locked_songs_data.json";
|
||||||
|
|
||||||
|
public string QRCodeDataFileName { get; set; } = "qrcode_data.json";
|
||||||
}
|
}
|
6
TaikoLocalServer/wwwroot/data/qrcode_data.json
Normal file
6
TaikoLocalServer/wwwroot/data/qrcode_data.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"serial": "",
|
||||||
|
"id": -1
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user