From 116b134b7057d10b4301523c54515abf9eb1fdc2 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Fri, 16 Sep 2022 23:45:08 +0800 Subject: [PATCH 1/2] Prevent exception from guest mode results --- TaikoLocalServer/Controllers/Game/PlayResultController.cs | 8 +++++++- TaikoLocalServer/Services/UserDatumService.cs | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/TaikoLocalServer/Controllers/Game/PlayResultController.cs b/TaikoLocalServer/Controllers/Game/PlayResultController.cs index 43e5ea2..a436bbf 100644 --- a/TaikoLocalServer/Controllers/Game/PlayResultController.cs +++ b/TaikoLocalServer/Controllers/Game/PlayResultController.cs @@ -45,6 +45,12 @@ public class PlayResultController : BaseController Result = 1 }; + // Fix issue caused by guest play, god knows why they send guest play data + if (request.BaidConf == 0 || await userDatumService.GetFirstUserDatumOrNull(request.BaidConf) is null) + { + return Ok(response); + } + var lastPlayDatetime = DateTime.ParseExact(playResultData.PlayDatetime, Constants.DATE_TIME_FORMAT, CultureInfo.InvariantCulture); @@ -168,7 +174,7 @@ public class PlayResultController : BaseController { var userdata = await userDatumService.GetFirstUserDatumOrNull(request.BaidConf); - userdata.ThrowIfNull(); + userdata.ThrowIfNull($"User data is null! Baid: {request.BaidConf}"); userdata.Title = playResultData.Title; userdata.TitlePlateId = playResultData.TitleplateId; diff --git a/TaikoLocalServer/Services/UserDatumService.cs b/TaikoLocalServer/Services/UserDatumService.cs index 8b3d5ca..f71b646 100644 --- a/TaikoLocalServer/Services/UserDatumService.cs +++ b/TaikoLocalServer/Services/UserDatumService.cs @@ -59,7 +59,7 @@ public class UserDatumService : IUserDatumService public async Task> GetFavoriteSongIds(uint baid) { var userDatum = await context.UserData.FindAsync(baid); - userDatum.ThrowIfNull(); + userDatum.ThrowIfNull($"User with baid: {baid} not found!"); using var stringStream = GZipBytesUtil.GenerateStreamFromString(userDatum.FavoriteSongsArray); List? result; @@ -79,7 +79,7 @@ public class UserDatumService : IUserDatumService public async Task UpdateFavoriteSong(uint baid, uint songId, bool isFavorite) { var userDatum = await context.UserData.FindAsync(baid); - userDatum.ThrowIfNull(); + userDatum.ThrowIfNull($"User with baid: {baid} not found!"); using var stringStream = GZipBytesUtil.GenerateStreamFromString(userDatum.FavoriteSongsArray); List? favoriteSongIds; From d1995cab852258dfc23cee4097138eedc2e94f5b Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Sat, 17 Sep 2022 21:36:31 +0800 Subject: [PATCH 2/2] Update guest fix --- TaikoLocalServer/Controllers/Game/PlayResultController.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TaikoLocalServer/Controllers/Game/PlayResultController.cs b/TaikoLocalServer/Controllers/Game/PlayResultController.cs index a436bbf..fc55045 100644 --- a/TaikoLocalServer/Controllers/Game/PlayResultController.cs +++ b/TaikoLocalServer/Controllers/Game/PlayResultController.cs @@ -46,11 +46,16 @@ public class PlayResultController : BaseController }; // Fix issue caused by guest play, god knows why they send guest play data - if (request.BaidConf == 0 || await userDatumService.GetFirstUserDatumOrNull(request.BaidConf) is null) + if (request.BaidConf == 0) { return Ok(response); } + if (await userDatumService.GetFirstUserDatumOrNull(request.BaidConf) is null) + { + Logger.LogWarning("Game uploading a non exisiting user with baid {Baid}", request.BaidConf); + } + var lastPlayDatetime = DateTime.ParseExact(playResultData.PlayDatetime, Constants.DATE_TIME_FORMAT, CultureInfo.InvariantCulture);