mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 01:58:40 +00:00
Fix bad request instead of 403 on getting slots
This commit is contained in:
parent
92ffcf3c41
commit
e92b1bf2c9
2 changed files with 33 additions and 5 deletions
|
@ -29,7 +29,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> GetLevelQueue(string username)
|
public async Task<IActionResult> GetLevelQueue(string username)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
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;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> GetFavouriteSlots(string username)
|
public async Task<IActionResult> GetFavouriteSlots(string username)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
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;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
@ -37,9 +38,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
(
|
(
|
||||||
p =>
|
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;
|
return gotValue;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -97,7 +101,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
(
|
(
|
||||||
new List<User>
|
new List<User>
|
||||||
{
|
{
|
||||||
user
|
user,
|
||||||
},
|
},
|
||||||
slot
|
slot
|
||||||
);
|
);
|
||||||
|
@ -112,6 +116,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
};
|
};
|
||||||
|
|
||||||
Rooms.Add(room);
|
Rooms.Add(room);
|
||||||
|
|
||||||
|
CleanupRooms(room.Host, room);
|
||||||
|
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,5 +133,26 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
}
|
}
|
||||||
return null;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue