diff --git a/ProjectLighthouse/Controllers/GameApi/Slots/PublishController.cs b/ProjectLighthouse/Controllers/GameApi/Slots/PublishController.cs index b7128d8d..564a0607 100644 --- a/ProjectLighthouse/Controllers/GameApi/Slots/PublishController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Slots/PublishController.cs @@ -33,10 +33,18 @@ public class PublishController : ControllerBase [HttpPost("startPublish")] public async Task StartPublish() { - User? user = await this.database.UserFromGameRequest(this.Request); - if (user == null) return this.StatusCode(403, ""); + (User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request); - if (user.UsedSlots >= ServerSettings.Instance.EntitledSlots) return this.BadRequest(); + if (userAndToken == null) return this.StatusCode(403, ""); + + // ReSharper disable once PossibleInvalidOperationException + User user = userAndToken.Value.Item1; + GameToken gameToken = userAndToken.Value.Item2; + + if (user.GetUsedSlotsForGame(gameToken.GameVersion, database) > 50) + { + return this.StatusCode(403, ""); + } Slot? slot = await this.getSlotFromBody(); if (slot == null) return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded diff --git a/ProjectLighthouse/Types/User.cs b/ProjectLighthouse/Types/User.cs index a370aaef..0678209d 100644 --- a/ProjectLighthouse/Types/User.cs +++ b/ProjectLighthouse/Types/User.cs @@ -223,11 +223,14 @@ public class User } } - public int GetUsedSlotsForGame(GameVersion version) + #nullable enable + public int GetUsedSlotsForGame(GameVersion version, Database? database = null) { - using Database database = new(); + database ??= new Database(); + return database.Slots.Count(s => s.CreatorId == this.UserId && s.GameVersion == version); } + #nullable disable /// /// The number of slots remaining on the earth