Fix bad request instead of 403 on getting slots

This commit is contained in:
jvyden 2021-11-16 18:40:03 -05:00
commit e92b1bf2c9
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 33 additions and 5 deletions

View file

@ -29,7 +29,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
public async Task<IActionResult> GetLevelQueue(string username)
{
Token? token = await this.database.TokenFromRequest(this.Request);
if (token == null) return this.BadRequest();
if (token == null) return this.StatusCode(403, "");
GameVersion gameVersion = token.GameVersion;
@ -91,7 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
public async Task<IActionResult> GetFavouriteSlots(string username)
{
Token? token = await this.database.TokenFromRequest(this.Request);
if (token == null) return this.BadRequest();
if (token == null) return this.StatusCode(403, "");
GameVersion gameVersion = token.GameVersion;

View file

@ -1,5 +1,6 @@
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
@ -37,9 +38,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers
(
p =>
{
bool gotValue = MatchHelper.UserLocations.TryGetValue(p.UserId, out string? value) && value != null;
bool gotValue = MatchHelper.UserLocations.TryGetValue(p.UserId, out string? value);
if (gotValue) relevantUserLocations.Add(p.UserId, value!);
if (gotValue && value != null)
{
relevantUserLocations.Add(p.UserId, value);
}
return gotValue;
}
);
@ -97,7 +101,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
(
new List<User>
{
user
user,
},
slot
);
@ -112,6 +116,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers
};
Rooms.Add(room);
CleanupRooms(room.Host, room);
return room;
}
@ -126,5 +133,26 @@ namespace LBPUnion.ProjectLighthouse.Helpers
}
return null;
}
[SuppressMessage("ReSharper", "InvertIf")]
public static void CleanupRooms(User? host = null, Room? newRoom = null)
{
// Delete old rooms based on host
if (host != null)
{
Rooms.RemoveAll(r => r.Host == host);
}
// Remove players in this new room from other rooms
if (newRoom != null)
{
foreach (Room room in Rooms)
{
if (room == newRoom) continue;
foreach (User newRoomPlayer in newRoom.Players) room.Players.RemoveAll(p => p == newRoomPlayer);
}
}
}
}
}