mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 16:58:38 +00:00
Check used slots for version on upload, not for all versions
This commit is contained in:
parent
7b5ce09fb4
commit
a3e8c29142
2 changed files with 16 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue