From 2949e83e01d0e3ad1c3b9a0a1e3850fa5aff17cf Mon Sep 17 00:00:00 2001 From: Slendy Date: Wed, 30 Aug 2023 17:48:07 -0500 Subject: [PATCH] Remove 7 player mode and show your playlists in LBP3 --- .../Controllers/ActivityController.cs | 2 +- .../Controllers/ActivityControllerTests.cs | 35 ++++++++++++++++++- .../Activity/ActivityEntityEventHandler.cs | 4 +-- .../Activity/Events/GameScoreEvent.cs | 6 ++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs index 03252a69..f023f443 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs @@ -102,7 +102,7 @@ public class ActivityController : ControllerBase predicate = predicate.Or(dto => includedUserIds.Contains(dto.Activity.UserId)); - if (!excludeMyPlaylists) + if (!excludeMyPlaylists && !excludeMyself && token.GameVersion == GameVersion.LittleBigPlanet3) { List creatorPlaylists = await this.database.Playlists.Where(p => p.CreatorId == token.UserId) .Select(p => p.PlaylistId) diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ActivityControllerTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ActivityControllerTests.cs index 1aa1d38d..b37ed595 100644 --- a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ActivityControllerTests.cs +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ActivityControllerTests.cs @@ -1,6 +1,39 @@ -namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Database; +using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers; +using LBPUnion.ProjectLighthouse.Tests.Helpers; +using LBPUnion.ProjectLighthouse.Types.Entities.Token; +using LBPUnion.ProjectLighthouse.Types.Serialization.Activity; +using LBPUnion.ProjectLighthouse.Types.Users; +using Microsoft.AspNetCore.Mvc; +using Xunit; +namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers; + +[Trait("Category", "Unit")] public class ActivityControllerTests { + private static void SetupToken(ControllerBase controller, GameVersion version) + { + GameTokenEntity token = MockHelper.GetUnitTestToken(); + token.GameVersion = version; + controller.SetupTestController(token); + } + + [Fact] + public async Task LBP2GlobalActivity_ShouldReturnNothing_WhenEmpty() + { + DatabaseContext database = await MockHelper.GetTestDatabase(); + ActivityController activityController = new(database); + SetupToken(activityController, GameVersion.LittleBigPlanet2); + + long timestamp = TimeHelper.TimestampMillis; + + IActionResult response = await activityController.GlobalActivity(timestamp, 0, false, false, false, false, false); + GameStream stream = response.CastTo(); + Assert.Null(stream.Groups); + Assert.Equal(timestamp, stream.StartTimestamp); + } //TODO write activity controller tests } \ No newline at end of file diff --git a/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs b/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs index dd8447f1..58b766fb 100644 --- a/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs +++ b/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs @@ -140,8 +140,6 @@ public class ActivityEntityEventHandler : IEntityEventHandler { if (origEntity is not VisitedLevelEntity oldVisitedLevel) break; - int Plays(VisitedLevelEntity entity) => entity.PlaysLBP1 + entity.PlaysLBP2 + entity.PlaysLBP3; - if (Plays(oldVisitedLevel) >= Plays(visitedLevel)) break; activity = new LevelActivityEntity @@ -151,6 +149,8 @@ public class ActivityEntityEventHandler : IEntityEventHandler UserId = visitedLevel.UserId, }; break; + + int Plays(VisitedLevelEntity entity) => entity.PlaysLBP1 + entity.PlaysLBP2 + entity.PlaysLBP3; } case SlotEntity slotEntity: { diff --git a/ProjectLighthouse/Types/Serialization/Activity/Events/GameScoreEvent.cs b/ProjectLighthouse/Types/Serialization/Activity/Events/GameScoreEvent.cs index bed5c1ac..a6fd19d6 100644 --- a/ProjectLighthouse/Types/Serialization/Activity/Events/GameScoreEvent.cs +++ b/ProjectLighthouse/Types/Serialization/Activity/Events/GameScoreEvent.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.ComponentModel; +using System.Threading.Tasks; using System.Xml.Serialization; using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Types.Entities.Level; @@ -17,6 +18,7 @@ public class GameScoreEvent : GameEvent [XmlElement("score")] public int Score { get; set; } + [DefaultValue(0)] [XmlElement("user_count")] public int UserCount { get; set; } @@ -32,7 +34,7 @@ public class GameScoreEvent : GameEvent this.Score = score.Points; //TODO is this correct? - this.UserCount = score.Type; + this.UserCount = score.Type == 7 ? 0 : score.Type; this.Slot = ReviewSlot.CreateFromEntity(slot); }