Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LBP3 Playlists #702

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
79b4ef0
WIP LBP3 Playlist support
Toastbrot236 Nov 27, 2024
e3c8ef4
Rename lbp1 playlist related things to be explicitly lbp1 related to …
Toastbrot236 Nov 29, 2024
c2494d8
bug fixes, 1 more endpoint, some more experiments, some other things
Toastbrot236 Nov 29, 2024
8f7c0a9
bug fixes, a refactor, some other improvements
Toastbrot236 Dec 13, 2024
eae06e0
Refactor some code for more reusability and to replace a hack for lbp…
Toastbrot236 Dec 14, 2024
5a0d739
dont fail to send multiple levels to game completely if atleast one l…
Toastbrot236 Dec 14, 2024
2a2e1f9
Let lbp3 playlists immediately update ingame, remove some no longer n…
Toastbrot236 Dec 14, 2024
36e05d0
nvm, let people reset their playlist name and description in lbp3
Toastbrot236 Dec 14, 2024
d50ce49
Remove some debugging, fixup my code style, slightly easier differenc…
Toastbrot236 Dec 14, 2024
bd67093
Differentiate further between lbp1 and lbp3 specific playlist classes…
Toastbrot236 Dec 14, 2024
b3adc15
Implement custom order for levels in playlists, add some comments
Toastbrot236 Dec 15, 2024
8c85c91
Reword a comment
Toastbrot236 Dec 15, 2024
061a058
Correct another one of my comments, use dedicated method for getting …
Toastbrot236 Dec 15, 2024
966641d
More accurate playlist timestamps (set before write), move foreach in…
Toastbrot236 Dec 16, 2024
6c0c4ab
fore matting, add some comments
Toastbrot236 Dec 16, 2024
ef6f5f9
Reword more comments, always sort levels in playlists, more fore matting
Toastbrot236 Jan 10, 2025
a1328af
Fix some ways of creating recursive playlists not being caught, fix o…
Toastbrot236 Jan 11, 2025
dbdc2a9
Fix that test, sort playlists and playlist levels
Toastbrot236 Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bug fixes, a refactor, some other improvements
  • Loading branch information
Toastbrot236 committed Dec 13, 2024
commit 8f7c0a9709f23dd6ba6888089de642fe5febc1a0
7 changes: 4 additions & 3 deletions Refresh.GameServer/Database/GameDatabaseContext.Playlists.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Refresh.GameServer.Authentication;
using Refresh.GameServer.Extensions;
using Refresh.GameServer.Types;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.Playlists;
using Refresh.GameServer.Types.Relations;
@@ -29,16 +30,16 @@ public GamePlaylist CreatePlaylist(GameUser user, SerializedPlaylist createInfo,

public GamePlaylist CreatePlaylist(GameUser user, SerializedLbp3Playlist createInfo, bool rootPlaylist)
{
Random random = new();
GameLocation randomLocation = GameLocation.GetRandomLocation();

GamePlaylist playlist = new()
{
Publisher = user,
Name = createInfo.Name ?? "",
Description = createInfo.Description ?? "",
IconHash = "g30477", // Mr Molecule sticker
LocationX = random.Next(25000),
LocationY = random.Next(25000),
LocationX = randomLocation.X,
LocationY = randomLocation.Y,
IsRoot = rootPlaylist,
};

2 changes: 1 addition & 1 deletion Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ protected GameDatabaseProvider(IDateTimeProvider time)
this._time = time;
}

protected override ulong SchemaVersion => 161;
protected override ulong SchemaVersion => 162;

protected override string Filename => "refreshGameServer.realm";

2 changes: 1 addition & 1 deletion Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ public class LevelEndpoints : EndpointGroup

foreach (string levelIdStr in levelIds)
{
if (!int.TryParse(levelIdStr, out int levelId)) return null;
if (!int.TryParse(levelIdStr.StartsWith('d') ? levelIdStr[1..] : levelIdStr, out int levelId)) return null;
GameLevel? level = database.GetLevelById(levelId);

if (level == null) continue;
Original file line number Diff line number Diff line change
@@ -29,12 +29,12 @@ public Response CreatePlaylist(RequestContext context, DataContext dataContext,
if (user.RootPlaylist == null)
{
// create a SerializedLbp3Playlist to reuse random location assignment from CreatePlaylist()
SerializedLbp3Playlist RootPlaylistOld = new()
SerializedLbp3Playlist rootPlaylist = new()
{
Name = "My Playlists"
};

GamePlaylist RootPlaylist = dataContext.Database.CreatePlaylist(user, RootPlaylistOld, true);
GamePlaylist RootPlaylist = dataContext.Database.CreatePlaylist(user, rootPlaylist, true);
dataContext.Database.SetUserRootPlaylist(user, RootPlaylist);
}

@@ -155,9 +155,9 @@ public Response RemoveLevelFromPlaylist(RequestContext context, DataContext data

return new SerializedLbp3PlaylistList
(
SerializedLbp3Playlist.FromOldList(playlists.Skip(skip).Take(count), dataContext).ToList(),
SerializedLbp3Playlist.FromOldList(playlists.Skip(skip).Take(count), dataContext),
playlists.Count(),
skip + 1
skip
);
}

@@ -172,11 +172,16 @@ public Response RemoveLevelFromPlaylist(RequestContext context, DataContext data
(int skip, int count) = context.GetPageData();
IEnumerable<GamePlaylist> playlists = dataContext.Database.GetPlaylistsFavouritedByUser(user);

return new SerializedLbp3PlaylistList
foreach(GamePlaylist playlist in playlists)
{
dataContext.Logger.LogInfo(BunkumCategory.UserContent, $"Playlist {playlist.Name} is in the hearted playlists list");
}

return new SerializedLbp3FavouritePlaylistList
(
SerializedLbp3Playlist.FromOldList(playlists.Skip(skip).Take(count), dataContext),
playlists.Count(),
skip + 1
skip
);
}

11 changes: 11 additions & 0 deletions Refresh.GameServer/Types/GameLocation.cs
Original file line number Diff line number Diff line change
@@ -22,4 +22,15 @@ public GameLocation(int x, int y)

[XmlElement("y")] public int X { get; set; }
[XmlElement("x")] public int Y { get; set; }

public static GameLocation GetRandomLocation()
{
Random random = new();

return new GameLocation
(
random.Next(30000),
random.Next(65000)
);
}
}
13 changes: 10 additions & 3 deletions Refresh.GameServer/Types/Lists/SerializedLbp3PlaylistList.cs
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@

namespace Refresh.GameServer.Types.Lists;

#nullable disable

[XmlRoot("playlists")]
[XmlType("playlists")]
public class SerializedLbp3PlaylistList : SerializedList<SerializedLbp3Playlist>
@@ -20,5 +18,14 @@ public SerializedLbp3PlaylistList(IEnumerable<SerializedLbp3Playlist> list, int
}

[XmlElement("playlist")]
public override List<SerializedLbp3Playlist> Items { get; set; }
public override List<SerializedLbp3Playlist> Items { get; set; } = [];
}


// elbeppe 3 moment
[XmlRoot("favouritePlaylists")]
public class SerializedLbp3FavouritePlaylistList : SerializedLbp3PlaylistList
{
internal SerializedLbp3FavouritePlaylistList() : base() {}
internal SerializedLbp3FavouritePlaylistList(IEnumerable<SerializedLbp3Playlist> list, int total, int skip) : base(list, total, skip) {}
}
2 changes: 1 addition & 1 deletion Refresh.GameServer/Types/Lists/SerializedLevelIdList.cs
Original file line number Diff line number Diff line change
@@ -10,5 +10,5 @@ public SerializedLevelIdList(List<int> levelIds)
this.LevelIds = levelIds;
}

[XmlElement("level_id")] public List<int> LevelIds = [];
[XmlElement("level_id")] public List<int> LevelIds { get; set; } = [];
}
18 changes: 15 additions & 3 deletions Refresh.GameServer/Types/Playlists/SerializedLbp3Playlist.cs
Original file line number Diff line number Diff line change
@@ -17,23 +17,35 @@ public class SerializedLbp3Playlist : IDataConvertableFrom<SerializedLbp3Playlis
[XmlElement("author")] public SerializedAuthor? Author { get; set; }
[XmlElement("levels")] public int LevelCount { get; set; } // doesnt even seem to do anything
[XmlElement("hearts")] public int HeartCount { get; set; }
// [XmlElement("icons")] public SerializedIconList? LevelIcons { get; set; }
[XmlElement("levels_quota")] public int PlaylistQuota { get; set; }
[XmlElement("icons")] public SerializedIconList? LevelIcons { get; set; }
[XmlArray("level_id")] public List<int> LevelIds { get; set; } = [];

public static SerializedLbp3Playlist? FromOld(GamePlaylist? old, DataContext dataContext)
{
if (old == null)
return null;

IEnumerable<int> levelIds = [];
IEnumerable<string> levelIcons = [];
levelIcons = levelIcons.Append(old.IconHash);
foreach(GameLevel level in dataContext.Database.GetLevelsInPlaylist(old, dataContext.Game))
{
levelIds = levelIds.Append(level.LevelId);
levelIcons = levelIcons.Append(level.IconHash);
}

return new SerializedLbp3Playlist
{
Id = old.PlaylistId,
Name = old.Name,
Description = old.Description,
Author = null, //new SerializedAuthor(old.Publisher.Username),
LevelCount = 7, //dataContext.Database.GetTotalLevelsInPlaylistCount(old, dataContext.Game) * -1, // lol
Author = new SerializedAuthor(old.Publisher.Username),
LevelCount = dataContext.Database.GetTotalLevelsInPlaylistCount(old, dataContext.Game) * -1, // lol
HeartCount = dataContext.Database.GetFavouriteCountForPlaylist(old),
PlaylistQuota = UgcLimits.MaximumLevels,
LevelIds = levelIds.ToList(),
LevelIcons = new SerializedIconList(levelIcons),
};
}