From c9e529533853db2284288d87e04ec89f41175525 Mon Sep 17 00:00:00 2001 From: sudokoko Date: Thu, 28 Dec 2023 13:31:20 -0500 Subject: [PATCH] Fix broken planet updates --- .../Controllers/UserController.cs | 6 ++++-- .../Helpers/GameResourceHelper.cs | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs index ace3b9456..fb5b6128f 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Text.Json; using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; @@ -82,7 +81,7 @@ public async Task 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; @@ -91,6 +90,9 @@ public async Task 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; diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs index 3932724e8..597f38335 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs @@ -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; + } } \ No newline at end of file