From 1820425038717a5216fb5fad5a1dd0e5583bda64 Mon Sep 17 00:00:00 2001 From: Slendy Date: Mon, 13 May 2024 21:21:38 -0500 Subject: [PATCH] Fix LBP3 playlist recent activity --- .../Controllers/ActivityController.cs | 9 ++--- .../Controllers/Slots/ScoreController.cs | 4 ++- .../Extensions/ActivityQueryExtensions.cs | 12 +++---- .../Types/Activity/ActivityDto.cs | 14 ++++---- .../Activity/ActivityEntityEventHandler.cs | 35 +++++++++++++------ .../Types/Activity/ActivityGroup.cs | 22 ++++++------ .../Activity/Events/GameEvent.cs | 8 ++--- 7 files changed, 59 insertions(+), 45 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs index 7fc867e2..f84e25ae 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs @@ -306,6 +306,9 @@ public class ActivityController : ControllerBase if ((SlotHelper.IsTypeInvalid(slotType) || slotId == 0) == (username == null)) return this.BadRequest(); + bool isLevelActivity = username == null; + bool groupByActor = !isLevelActivity && token.GameVersion == GameVersion.LittleBigPlanet3; + // User and Level activity will never contain news posts or MM pick events. IQueryable activityQuery = this.database.Activities.ToActivityDto() .Where(a => a.Activity.Type != EventType.NewsPost && a.Activity.Type != EventType.MMPickLevel); @@ -318,8 +321,6 @@ public class ActivityController : ControllerBase a.Activity.Type != EventType.AddLevelToPlaylist); } - bool isLevelActivity = username == null; - // Slot activity if (isLevelActivity) { @@ -345,9 +346,9 @@ public class ActivityController : ControllerBase activityQuery = activityQuery.Where(dto => dto.Activity.Timestamp < times.Start && dto.Activity.Timestamp > times.End); - List> groups = await activityQuery.ToActivityGroups().ToListAsync(); + List> groups = await activityQuery.ToActivityGroups(groupByActor).ToListAsync(); - List outerGroups = groups.ToOuterActivityGroups(); + List outerGroups = groups.ToOuterActivityGroups(groupByActor); long oldestTimestamp = GetOldestTime(groups, times.Start).ToUnixTimeMilliseconds(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs index 841cef38..56c5bc84 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs @@ -131,7 +131,9 @@ public class ScoreController : ControllerBase await this.database.SaveChangesAsync(); - ScoreEntity? existingScore = await this.database.Scores.Where(s => s.SlotId == slot.SlotId) + ScoreEntity? existingScore = await this.database.Scores + .Include(s => s.Slot) + .Where(s => s.SlotId == slot.SlotId) .Where(s => s.ChildSlotId == 0 || s.ChildSlotId == childId) .Where(s => s.UserId == token.UserId) .Where(s => s.Type == score.Type) diff --git a/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs b/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs index 0697ec5e..cbe70db8 100644 --- a/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs +++ b/ProjectLighthouse/Extensions/ActivityQueryExtensions.cs @@ -66,15 +66,15 @@ public static class ActivityQueryExtensions { Type = groupByActor ? gr.GroupType - : gr.GroupType != ActivityGroupType.News - ? ActivityGroupType.User - : ActivityGroupType.News, + : gr.GroupType == ActivityGroupType.News + ? ActivityGroupType.News + : ActivityGroupType.User, UserId = gr.Activity.UserId, TargetId = groupByActor ? gr.TargetId - : gr.GroupType != ActivityGroupType.News - ? gr.Activity.UserId - : gr.TargetNewsId ?? 0, + : gr.GroupType == ActivityGroupType.News + ? gr.TargetNewsId ?? 0 + : gr.Activity.UserId, }) .ToList(), }) diff --git a/ProjectLighthouse/Types/Activity/ActivityDto.cs b/ProjectLighthouse/Types/Activity/ActivityDto.cs index 87759369..6e696d8f 100644 --- a/ProjectLighthouse/Types/Activity/ActivityDto.cs +++ b/ProjectLighthouse/Types/Activity/ActivityDto.cs @@ -25,11 +25,11 @@ public class ActivityDto }; public ActivityGroupType GroupType => - this.TargetSlotId != null - ? ActivityGroupType.Level - : this.TargetUserId != null - ? ActivityGroupType.User - : this.TargetPlaylistId != null - ? ActivityGroupType.Playlist - : ActivityGroupType.News; + this.TargetPlaylistId != null + ? ActivityGroupType.Playlist + : this.TargetNewsId != null + ? ActivityGroupType.News + : this.TargetSlotId != null + ? ActivityGroupType.Level + : ActivityGroupType.User; } \ No newline at end of file diff --git a/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs b/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs index 91e3e605..29810f8c 100644 --- a/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs +++ b/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs @@ -57,25 +57,17 @@ public class ActivityEntityEventHandler : IEntityEventHandler }, PhotoEntity photo => photo.SlotId switch { - // Photos without levels - null => new UserPhotoActivity - { - Type = EventType.UploadPhoto, - PhotoId = photo.PhotoId, - UserId = photo.CreatorId, - TargetUserId = photo.CreatorId, - }, _ => photo.Slot?.Type switch { - SlotType.Developer => null, - // Non-story levels (moon, pod, etc) - _ => new LevelPhotoActivity + SlotType.User => new LevelPhotoActivity { Type = EventType.UploadPhoto, PhotoId = photo.PhotoId, UserId = photo.CreatorId, SlotId = photo.SlotId ?? throw new NullReferenceException("SlotId in Photo is null"), }, + // All other photos (story, moon, pod, etc.) + _ => null, }, }, ScoreEntity score => score.Slot.Type switch @@ -227,6 +219,27 @@ public class ActivityEntityEventHandler : IEntityEventHandler int Plays(VisitedLevelEntity entity) => entity.PlaysLBP1 + entity.PlaysLBP2 + entity.PlaysLBP3; } + case ScoreEntity score: + { + if (origEntity is not ScoreEntity oldScore) break; + + // don't track versus levels + if (oldScore.Type == 7) break; + + if (score.Slot.Type != SlotType.User) break; + + if (oldScore.Points > score.Points) break; + + activity = new ScoreActivityEntity + { + Type = EventType.Score, + ScoreId = score.ScoreId, + SlotId = score.SlotId, + UserId = score.UserId, + }; + + break; + } case SlotEntity slotEntity: { if (origEntity is not SlotEntity oldSlotEntity) break; diff --git a/ProjectLighthouse/Types/Activity/ActivityGroup.cs b/ProjectLighthouse/Types/Activity/ActivityGroup.cs index 51f981b0..8cd189ae 100644 --- a/ProjectLighthouse/Types/Activity/ActivityGroup.cs +++ b/ProjectLighthouse/Types/Activity/ActivityGroup.cs @@ -19,7 +19,7 @@ public struct ActivityGroup this.GroupType switch { ActivityGroupType.User => this.TargetUserId ?? this.UserId, - ActivityGroupType.Level => this.TargetSlotId?? 0, + ActivityGroupType.Level => this.TargetSlotId ?? 0, ActivityGroupType.TeamPick => this.TargetTeamPickSlotId ?? 0, ActivityGroupType.Playlist => this.TargetPlaylistId ?? 0, ActivityGroupType.News => this.TargetNewsId ?? 0, @@ -27,17 +27,15 @@ public struct ActivityGroup }; public ActivityGroupType GroupType => - (this.TargetSlotId ?? 0) != 0 - ? ActivityGroupType.Level - : (this.TargetUserId ?? 0) != 0 - ? ActivityGroupType.User - : (this.TargetPlaylistId ?? 0) != 0 - ? ActivityGroupType.Playlist - : (this.TargetNewsId ?? 0) != 0 - ? ActivityGroupType.News - : (this.TargetTeamPickSlotId ?? 0) != 0 - ? ActivityGroupType.TeamPick - : ActivityGroupType.User; + (this.TargetPlaylistId ?? 0) != 0 + ? ActivityGroupType.User + : (this.TargetNewsId ?? 0) != 0 + ? ActivityGroupType.News + : (this.TargetTeamPickSlotId ?? 0) != 0 + ? ActivityGroupType.TeamPick + : (this.TargetSlotId ?? 0) != 0 + ? ActivityGroupType.Level + : ActivityGroupType.User; public override string ToString() => $@"{this.GroupType} Group: Timestamp: {this.Timestamp}, UserId: {this.UserId}, TargetId: {this.TargetId}"; diff --git a/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs b/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs index 21d28314..f9f48a0f 100644 --- a/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs +++ b/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs @@ -187,7 +187,7 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization PhotoId = ((PhotoActivityEntity)activity.Activity).PhotoId, Slot = new ReviewSlot { - SlotId = targetId, + SlotId = activity.TargetSlotId ?? -1, }, }, EventType.MMPickLevel => new GameTeamPickLevelEvent @@ -211,15 +211,15 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization }, EventType.CreatePlaylist => new GameCreatePlaylistEvent { - TargetPlaylistId = targetId, + TargetPlaylistId = activity.TargetPlaylistId ?? -1, }, EventType.HeartPlaylist => new GameHeartPlaylistEvent { - TargetPlaylistId = targetId, + TargetPlaylistId = activity.TargetPlaylistId ?? -1, }, EventType.AddLevelToPlaylist => new GameAddLevelToPlaylistEvent { - TargetPlaylistId = targetId, + TargetPlaylistId = activity.TargetPlaylistId ?? -1, Slot = new ReviewSlot { SlotId = ((PlaylistWithSlotActivityEntity)activity.Activity).SlotId,