mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-14 22:02:26 +00:00
Implement POST request rate limiting (#490)
* Initial work for rate limiting * Refactor GameServerStartup and change default rate limit config * Adjust config naming and add Enabled option to global and override rate limits * Fix LBP3 republish bug * Fix bugs in rate limiting and allow for multiple matched overrides * Add this qualifier for private variable * Changes from self review
This commit is contained in:
parent
110d81f117
commit
3ad211e5c8
16 changed files with 451 additions and 206 deletions
|
@ -60,12 +60,12 @@ public class PublishController : ControllerBase
|
|||
Slot? oldSlot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId);
|
||||
if (oldSlot == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level reupload, could not find old slot", LogArea.Publish);
|
||||
Logger.Warn("Rejecting level republish, 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);
|
||||
Logger.Warn("Rejecting level republish, old slot's creator is not publishing user", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class PublishController : ControllerBase
|
|||
/// Endpoint actually used to publish a level
|
||||
/// </summary>
|
||||
[HttpPost("publish")]
|
||||
public async Task<IActionResult> Publish()
|
||||
public async Task<IActionResult> Publish([FromQuery] string? game)
|
||||
{
|
||||
(User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request);
|
||||
|
||||
|
@ -178,6 +178,22 @@ public class PublishController : ControllerBase
|
|||
return this.BadRequest();
|
||||
}
|
||||
|
||||
// I hate lbp3
|
||||
if (game != null)
|
||||
{
|
||||
GameVersion intendedVersion = FromAbbreviation(game);
|
||||
if (intendedVersion != GameVersion.Unknown && intendedVersion != slotVersion)
|
||||
{
|
||||
// Delete the useless rootLevel that lbp3 just uploaded
|
||||
if(slotVersion == GameVersion.LittleBigPlanet3)
|
||||
FileHelper.DeleteResource(slot.RootLevel);
|
||||
|
||||
slot.GameVersion = oldSlot.GameVersion;
|
||||
slot.RootLevel = oldSlot.RootLevel;
|
||||
slot.ResourceCollection = oldSlot.ResourceCollection;
|
||||
}
|
||||
}
|
||||
|
||||
oldSlot.Location.X = slot.Location.X;
|
||||
oldSlot.Location.Y = slot.Location.Y;
|
||||
|
||||
|
@ -277,6 +293,19 @@ public class PublishController : ControllerBase
|
|||
return this.Ok();
|
||||
}
|
||||
|
||||
private static GameVersion FromAbbreviation(string abbr)
|
||||
{
|
||||
return abbr switch
|
||||
{
|
||||
"lbp1" => GameVersion.LittleBigPlanet1,
|
||||
"lbp2" => GameVersion.LittleBigPlanet2,
|
||||
"lbp3" => GameVersion.LittleBigPlanet3,
|
||||
"lbpv" => GameVersion.LittleBigPlanetVita,
|
||||
"lbppsp" => GameVersion.LittleBigPlanetPSP,
|
||||
_ => GameVersion.Unknown,
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<Slot?> getSlotFromBody()
|
||||
{
|
||||
this.Request.Body.Position = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue