From ab346bc90687918fa55141ec4b68ed78a92c9720 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sat, 30 Jul 2022 18:17:28 -0400 Subject: [PATCH] Add logging to StartPublish, fix bug where levels do not publish if rootLevel does not exist --- .gitignore | 4 ++- .../Controllers/Slots/PublishController.cs | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index b766f916..3d04161d 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ gitUnpushed.txt gitRevCount.txt logs/* npTicket* +r.tar.gz +lighthouse.yml.configme # MSBuild stuff bin/ @@ -44,4 +46,4 @@ BACKUP* backup* *.tmp -*.bin +*.bin \ No newline at end of file diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs index 620753a3..a545230c 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs @@ -40,26 +40,35 @@ public class PublishController : ControllerBase GameToken gameToken = userAndToken.Value.Item2; Slot? slot = await this.getSlotFromBody(); - if (slot == null) return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded + if (slot == null) { + Logger.Warn("Rejecting level upload, slot is null", LogArea.Publish); + return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded + } - if (string.IsNullOrEmpty(slot.RootLevel)) return this.BadRequest(); + if (string.IsNullOrEmpty(slot.RootLevel)) + { + Logger.Warn("Rejecting level upload, slot does not include rootLevel", LogArea.Publish); + return this.BadRequest(); + } if (string.IsNullOrEmpty(slot.ResourceCollection)) slot.ResourceCollection = slot.RootLevel; - LbpFile? rootLevel = LbpFile.FromHash(slot.RootLevel); - if (rootLevel == null) return this.BadRequest(); - - GameVersion slotVersion = FileHelper.ParseLevelVersion(rootLevel); - if (slotVersion == GameVersion.Unknown) slotVersion = gameToken.GameVersion; - // Republish logic if (slot.SlotId != 0) { Slot? oldSlot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId); - if (oldSlot == null) return this.NotFound(); - if (oldSlot.CreatorId != user.UserId) return this.BadRequest(); + if (oldSlot == null) + { + Logger.Warn("Rejecting level reupload, could not find old slot", LogArea.Publish); + return this.NotFound(); + } + if (oldSlot.CreatorId != user.UserId) + { + Logger.Warn("Rejecting level reupload, old slot's creator is not publishing user", LogArea.Publish); + return this.BadRequest(); + } } - else if (user.GetUsedSlotsForGame(slotVersion) > ServerConfiguration.Instance.UserGeneratedContentLimits.EntitledSlots) + else if (user.GetUsedSlotsForGame(gameToken.GameVersion) > ServerConfiguration.Instance.UserGeneratedContentLimits.EntitledSlots) { return this.StatusCode(403, ""); }