Fix broken planet updates

This commit is contained in:
sudokoko 2023-12-28 13:31:20 -05:00
parent 9dc7ce27e1
commit c9e5295338
No known key found for this signature in database
GPG key ID: 48BB40C0F649D603
2 changed files with 13 additions and 2 deletions

View file

@ -1,4 +1,3 @@
#nullable enable
using System.Text.Json;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
@ -82,7 +81,7 @@ public class UserController : ControllerBase
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;
@ -91,6 +90,9 @@ public class UserController : ControllerBase
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;

View file

@ -37,4 +37,13 @@ public static class GameResourceHelper
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;
}
}