mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-04-19 11:04:51 +00:00
Merge pull request from GHSA-c8wx-65c7-q9r3
Co-authored-by: Slendy <josh@slendy.pw>
This commit is contained in:
parent
e593d5c957
commit
ef87606ba2
6 changed files with 41069 additions and 1 deletions
|
@ -20,6 +20,7 @@ website notifications to indicate what went wrong.
|
|||
- `LH-PUB-0008`: The level failed to publish because the root level is not an LBP3 Adventure level.
|
||||
- `LH-PUB-0009`: The level failed to publish because the the user has reached their level publishing limit.
|
||||
- **Fix:** Delete some of your previously published levels to make room for new ones.
|
||||
- `LH-PUB-0010`: THe level failed to publish because the icon of the level is not a valid texture or image.
|
||||
|
||||
## Level Republishing
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using LBPUnion.ProjectLighthouse.Extensions;
|
|||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -157,6 +158,14 @@ public class PublishController : ControllerBase
|
|||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (!GameResourceHelper.IsValidTexture(slot.IconHash))
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, invalid icon resource", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish because your level icon is invalid. (LH-PUB-0010)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (slot.Resources.Any(resource => !FileHelper.ResourceExists(resource)))
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, missing resource(s)", LogArea.Publish);
|
||||
|
|
|
@ -4,6 +4,7 @@ using LBPUnion.ProjectLighthouse.Database;
|
|||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
@ -85,7 +86,9 @@ public class UserController : ControllerBase
|
|||
{
|
||||
if (string.IsNullOrWhiteSpace(resource)) continue;
|
||||
|
||||
if (!FileHelper.ResourceExists(resource)) return this.BadRequest();
|
||||
if (!FileHelper.ResourceExists(resource) && !resource.StartsWith('g')) return this.BadRequest();
|
||||
|
||||
if (!GameResourceHelper.IsValidTexture(resource)) return this.BadRequest();
|
||||
}
|
||||
|
||||
if (update.IconHash != null) user.IconHash = update.IconHash;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
using System.Collections.Immutable;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Resources;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
|
||||
|
||||
public static class GameResourceHelper
|
||||
{
|
||||
private static readonly ImmutableList<string> textureGuids = ImmutableList<string>.Empty;
|
||||
|
||||
static GameResourceHelper()
|
||||
{
|
||||
List<string> guids = new();
|
||||
using Stream? guidStream = typeof(GameResourceHelper).Assembly.GetManifestResourceStream("LBPUnion.ProjectLighthouse.Servers.GameServer.textureGuids.txt");
|
||||
if (guidStream == null)
|
||||
{
|
||||
Logger.Warn("Failed to load texture guids, users may experience issues when setting level and profile icons", LogArea.Startup);
|
||||
return;
|
||||
}
|
||||
|
||||
using StreamReader reader = new(guidStream);
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
string? guid = reader.ReadLine();
|
||||
if (guid == null) continue;
|
||||
|
||||
guids.Add(guid);
|
||||
}
|
||||
textureGuids = ImmutableList.Create(guids.ToArray());
|
||||
}
|
||||
|
||||
public static bool IsValidTexture(string resource)
|
||||
{
|
||||
if (!FileHelper.IsResourceValid(resource)) return false;
|
||||
|
||||
if (resource.StartsWith("g"))
|
||||
{
|
||||
return textureGuids.Contains(resource[1..]);
|
||||
}
|
||||
|
||||
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Plan
|
||||
or LbpFileType.Painting or LbpFileType.Texture;
|
||||
}
|
||||
}
|
|
@ -13,4 +13,8 @@
|
|||
<ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="textureGuids.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
41005
ProjectLighthouse.Servers.GameServer/textureGuids.txt
Normal file
41005
ProjectLighthouse.Servers.GameServer/textureGuids.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue