Skip to content

Commit

Permalink
Fix broken planet updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sudokoko committed Dec 28, 2023
1 parent 9dc7ce2 commit c9e5295
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System.Text.Json;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
Expand Down Expand Up @@ -82,7 +81,7 @@ public async Task<IActionResult> UpdateUser()
if (update.Location != null) user.Location = update.Location;

// ReSharper disable once LoopCanBeConvertedToQuery
foreach (string? resource in new[]{update.IconHash, update.YayHash, update.MehHash, update.BooHash, update.PlanetHash,})
foreach (string? resource in new[]{update.IconHash, update.YayHash, update.MehHash, update.BooHash,})
{
if (string.IsNullOrWhiteSpace(resource)) continue;

Expand All @@ -91,6 +90,9 @@ public async Task<IActionResult> UpdateUser()
if (!GameResourceHelper.IsValidTexture(resource)) return this.BadRequest();
}

if (!string.IsNullOrWhiteSpace(update.PlanetHash) && !GameResourceHelper.IsValidLevel(update.PlanetHash))
return this.BadRequest();

if (update.IconHash != null) user.IconHash = update.IconHash;

if (update.YayHash != null) user.YayHash = update.YayHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ public static bool IsValidTexture(string resource)
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Painting
or LbpFileType.Texture;
}

public static bool IsValidLevel(string resource)
{
if (!FileHelper.IsResourceValid(resource)) return false;

// Technically this method could be used (and is used) to check if a planet is valid,
// but I'm keeping the method name as is for semantic reasons.
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Level;
}
}

0 comments on commit c9e5295

Please sign in to comment.