Check used slots for version on upload, not for all versions

This commit is contained in:
jvyden 2022-02-18 17:42:53 -05:00
commit a3e8c29142
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 16 additions and 5 deletions

View file

@ -33,10 +33,18 @@ public class PublishController : ControllerBase
[HttpPost("startPublish")]
public async Task<IActionResult> 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

View file

@ -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
/// <summary>
/// The number of slots remaining on the earth