From 807d5d275d48b97faf99b6b19dd1a9761b8ed9ff Mon Sep 17 00:00:00 2001 From: Metra Date: Tue, 27 Aug 2024 15:13:33 -0700 Subject: [PATCH 1/3] filter locked levels from lucky dip --- .../Extensions/ControllerExtensions.cs | 3 +++ ProjectLighthouse/Filter/Filters/LockedSlotFilter.cs | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 ProjectLighthouse/Filter/Filters/LockedSlotFilter.cs diff --git a/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs b/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs index 7c654a6f2..5cd52ff58 100644 --- a/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs +++ b/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs @@ -175,6 +175,9 @@ void ParseLbp3Query(string key, Action allMust, Action noneCan, Action dontCare) if (!queryBuilder.GetFilters(typeof(CrossControlFilter)).Any()) queryBuilder.AddFilter(new ExcludeCrossControlFilter()); + + if (controller.Request.Path.Value.EndsWith("lbp2luckydip")) + queryBuilder.AddFilter(new LockedSlotFilter()); queryBuilder.AddFilter(new SubLevelFilter(token.UserId)); queryBuilder.AddFilter(new HiddenSlotFilter()); diff --git a/ProjectLighthouse/Filter/Filters/LockedSlotFilter.cs b/ProjectLighthouse/Filter/Filters/LockedSlotFilter.cs new file mode 100644 index 000000000..185b45658 --- /dev/null +++ b/ProjectLighthouse/Filter/Filters/LockedSlotFilter.cs @@ -0,0 +1,11 @@ +using System; +using System.Linq.Expressions; +using LBPUnion.ProjectLighthouse.Types.Entities.Level; +using LBPUnion.ProjectLighthouse.Types.Filter; + +namespace LBPUnion.ProjectLighthouse.Filter.Filters; + +public class LockedSlotFilter : ISlotFilter +{ + public Expression> GetPredicate() => s => !s.InitiallyLocked; +} \ No newline at end of file From 9ac74312ce44f2bc47eb447d81c305fc83d17e94 Mon Sep 17 00:00:00 2001 From: Metra Date: Tue, 27 Aug 2024 19:53:48 -0700 Subject: [PATCH 2/3] yeah sure --- .../Extensions/ControllerExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs b/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs index 5cd52ff58..103a92b4d 100644 --- a/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs +++ b/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs @@ -176,7 +176,7 @@ void ParseLbp3Query(string key, Action allMust, Action noneCan, Action dontCare) if (!queryBuilder.GetFilters(typeof(CrossControlFilter)).Any()) queryBuilder.AddFilter(new ExcludeCrossControlFilter()); - if (controller.Request.Path.Value.EndsWith("lbp2luckydip")) + if (controller.Request.Path.Value != null && controller.Request.Path.Value.EndsWith("lbp2luckydip")) queryBuilder.AddFilter(new LockedSlotFilter()); queryBuilder.AddFilter(new SubLevelFilter(token.UserId)); From cdddfcaf0cdfc69e12ed58a0b5979ec7484fa4be Mon Sep 17 00:00:00 2001 From: Metra Date: Tue, 27 Aug 2024 20:58:33 -0700 Subject: [PATCH 3/3] put the filter in a more reasonable place --- .../Controllers/Slots/SlotsController.cs | 1 + .../Extensions/ControllerExtensions.cs | 3 --- .../Types/Categories/LuckyDipCategory.cs | 8 ++++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs index 13f9afa8a..f71267bab 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs @@ -263,6 +263,7 @@ public async Task LuckyDipSlots([FromQuery] int seed) PaginationData pageData = this.Request.GetPaginationData(); SlotQueryBuilder queryBuilder = this.FilterFromRequest(token); + queryBuilder.AddFilter(new LockedSlotFilter()); pageData.TotalElements = await StatisticsHelper.SlotCount(this.database, queryBuilder); diff --git a/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs b/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs index 103a92b4d..7c654a6f2 100644 --- a/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs +++ b/ProjectLighthouse.Servers.GameServer/Extensions/ControllerExtensions.cs @@ -175,9 +175,6 @@ void ParseLbp3Query(string key, Action allMust, Action noneCan, Action dontCare) if (!queryBuilder.GetFilters(typeof(CrossControlFilter)).Any()) queryBuilder.AddFilter(new ExcludeCrossControlFilter()); - - if (controller.Request.Path.Value != null && controller.Request.Path.Value.EndsWith("lbp2luckydip")) - queryBuilder.AddFilter(new LockedSlotFilter()); queryBuilder.AddFilter(new SubLevelFilter(token.UserId)); queryBuilder.AddFilter(new HiddenSlotFilter()); diff --git a/ProjectLighthouse.Servers.GameServer/Types/Categories/LuckyDipCategory.cs b/ProjectLighthouse.Servers.GameServer/Types/Categories/LuckyDipCategory.cs index 93bea8805..6d8528b4d 100644 --- a/ProjectLighthouse.Servers.GameServer/Types/Categories/LuckyDipCategory.cs +++ b/ProjectLighthouse.Servers.GameServer/Types/Categories/LuckyDipCategory.cs @@ -2,6 +2,7 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Filter; +using LBPUnion.ProjectLighthouse.Filter.Filters; using LBPUnion.ProjectLighthouse.Filter.Sorts; using LBPUnion.ProjectLighthouse.Types.Entities.Level; using LBPUnion.ProjectLighthouse.Types.Entities.Token; @@ -16,7 +17,10 @@ public class LuckyDipCategory : SlotCategory public override string Endpoint { get; set; } = "lucky_dip"; public override string Tag => "lucky_dip"; - public override IQueryable GetItems(DatabaseContext database, GameTokenEntity token, SlotQueryBuilder queryBuilder) => - database.Slots.Where(queryBuilder.Build()) + public override IQueryable GetItems(DatabaseContext database, GameTokenEntity token, SlotQueryBuilder queryBuilder) + { + queryBuilder.AddFilter(new LockedSlotFilter()); + return database.Slots.Where(queryBuilder.Build()) .ApplyOrdering(new SlotSortBuilder().AddSort(new RandomFirstUploadedSort())); + } } \ No newline at end of file