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

GameUser: Split Vita icon hash from PS3 icon hash #317

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 32 additions & 6 deletions Refresh.GameServer/Database/GameDatabaseContext.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,38 @@ public void UpdateUserData(GameUser user, SerializedUpdateData data, TokenGame g

// ReSharper disable once InvertIf
if (data.IconHash != null)
//PSP icons are special and use a GUID system separate from the mainline games,
//so we separate PSP icons to another field
if (game == TokenGame.LittleBigPlanetPSP)
user.PspIconHash = data.IconHash;
else
user.IconHash = data.IconHash;
switch (game)
{

case TokenGame.LittleBigPlanet1:
case TokenGame.LittleBigPlanet2:
case TokenGame.LittleBigPlanet3:
#if false // TODO: Enable this code once https://github.com/LittleBigRefresh/Refresh/issues/309 is resolved
//If the icon is a remote asset, then it will work on Vita as well, so set the Vita hash
if (!data.IconHash.StartsWith('g'))
{
user.VitaIconHash = data.IconHash;
}
#endif
user.IconHash = data.IconHash;
break;
case TokenGame.LittleBigPlanetVita:
#if false // TODO: Enable this code once https://github.com/LittleBigRefresh/Refresh/issues/309 is resolved
//If the icon is a remote asset, then it will work on PS3 as well, so set the PS3 hash to it as well
if (!data.IconHash.StartsWith('g'))
{
user.IconHash = data.IconHash;
}
#endif
user.VitaIconHash = data.IconHash;

break;
case TokenGame.LittleBigPlanetPSP:
//PSP icons are special and use a GUID system separate from the mainline games,
//so we separate PSP icons to another field
user.PspIconHash = data.IconHash;
break;
}
});
}

Expand Down
5 changes: 4 additions & 1 deletion Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected GameDatabaseProvider(IDateTimeProvider time)
this._time = time;
}

protected override ulong SchemaVersion => 101;
protected override ulong SchemaVersion => 102;

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

Expand Down Expand Up @@ -168,6 +168,9 @@ protected override void Migrate(Migration migration, ulong oldVersion)

// Version was bumped here to delete invalid favourite level relations
if (oldVersion < 101) migration.NewRealm.RemoveRange(newUser.FavouriteLevelRelations.Where(r => r.Level == null));

// In version 102 we split the Vita icon hash from the PS3 icon hash
if (oldVersion < 102) newUser.VitaIconHash = "0";
}

IQueryable<dynamic>? oldLevels = migration.OldRealm.DynamicApi.All("GameLevel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[XmlElement("location")] public required GameLocation Location { get; set; }
[XmlElement("planets")] public required string PlanetsHash { get; set; }

[XmlElement("npHandle")] public SerializedUserHandle Handle { get; set; }

Check warning on line 23 in Refresh.GameServer/Endpoints/Game/DataTypes/Response/GameUserResponse.cs

View workflow job for this annotation

GitHub Actions / Build, Test, and Upload Builds

Non-nullable property 'Handle' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[XmlElement("commentCount")] public int CommentCount { get; set; }
[XmlElement("commentsEnabled")] public bool CommentsEnabled { get; set; }
[XmlElement("favouriteSlotCount")] public int FavouriteLevelCount { get; set; }
Expand Down Expand Up @@ -142,6 +142,9 @@
//Match all LBP Vita levels
this.UsedSlotsLBP2 = old.PublishedLevels.Count(x => x._GameVersion == (int)TokenGame.LittleBigPlanetVita);
this.FreeSlotsLBP2 = MaximumLevels - this.UsedSlotsLBP2;

//Apply Vita-specific icon hash
this.IconHash = old.VitaIconHash;
break;
}
case TokenGame.LittleBigPlanet1: {
Expand All @@ -154,28 +157,25 @@
//Match all LBP PSP levels
this.UsedSlots = old.PublishedLevels.Count(x => x._GameVersion == (int)TokenGame.LittleBigPlanetPSP);
this.FreeSlots = MaximumLevels - this.UsedSlots;

// Apply PSP-specific icon hash
this.IconHash = old.PspIconHash;

//Fill out PSP favourite users
List<GameUser> users = database.GetUsersFavouritedByUser(old, 20, 0).ToList();
this.FavouriteUsers = new SerializedMinimalFavouriteUserList(users.Select(SerializedUserHandle.FromUser).ToList(), users.Count);

//Fill out PSP favourite levels
List<GameMinimalLevelResponse> favouriteLevels = old.FavouriteLevelRelations
.AsEnumerable()
.Where(l => l.Level._GameVersion == (int)TokenGame.LittleBigPlanetPSP)
.Select(f => GameMinimalLevelResponse.FromOld(f.Level)).ToList()!;
this.FavouriteLevels = new SerializedMinimalFavouriteLevelList(new SerializedMinimalLevelList(favouriteLevels, favouriteLevels.Count));
break;
}
case TokenGame.Website: break;
default:
throw new ArgumentOutOfRangeException(nameof(gameVersion), gameVersion, null);
}

if (gameVersion == TokenGame.LittleBigPlanetPSP)
{
// Apply PSP-specific icon hashes
this.IconHash = old.PspIconHash;

//Fill out PSP favourite users
List<GameUser> users = database.GetUsersFavouritedByUser(old, 20, 0).ToList();
this.FavouriteUsers = new SerializedMinimalFavouriteUserList(users.Select(SerializedUserHandle.FromUser).ToList(), users.Count);

//Fill out PSP favourite levels
List<GameMinimalLevelResponse> favouriteLevels = old.FavouriteLevelRelations
.AsEnumerable()
.Where(l => l.Level._GameVersion == (int)TokenGame.LittleBigPlanetPSP)
.Select(f => GameMinimalLevelResponse.FromOld(f.Level)).ToList()!;
this.FavouriteLevels = new SerializedMinimalFavouriteLevelList(new SerializedMinimalLevelList(favouriteLevels, favouriteLevels.Count));
}
}
}
7 changes: 7 additions & 0 deletions Refresh.GameServer/Types/UserData/GameUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public partial class GameUser : IRealmObject, IRateLimitUser
/// Hopefully this explains why this distinction is necessary.
/// </remarks>
public string PspIconHash { get; set; } = "0";
/// <summary>
/// The <see cref="IconHash"/>, except only for Vita clients.
/// </summary>
/// <remarks>
/// Vita GUIDs do not map to mainline GUIDs, so we dont want someone to set their Vita icon, and it map to an invalid GUID on PS3.
/// </remarks>
public string VitaIconHash { get; set; } = "0";

public string Description { get; set; } = "";
public GameLocation Location { get; set; } = GameLocation.Zero;
Expand Down
Loading