mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-08 03:22:27 +00:00
Implement Redis for storing rooms
This commit is contained in:
parent
e998e59607
commit
e12a798fd5
14 changed files with 194 additions and 67 deletions
|
@ -74,10 +74,10 @@ public class MatchController : ControllerBase
|
|||
if (matchData is UpdateMyPlayerData playerData)
|
||||
{
|
||||
MatchHelper.SetUserLocation(user.UserId, gameToken.UserLocation);
|
||||
Room? room = RoomHelper.FindRoomByUser(user, gameToken.GameVersion, gameToken.Platform, true);
|
||||
Room? room = RoomHelper.FindRoomByUser(user.UserId, gameToken.GameVersion, gameToken.Platform, true);
|
||||
|
||||
if (playerData.RoomState != null)
|
||||
if (room != null && Equals(room.Host, user))
|
||||
if (room != null && Equals(room.HostId, user.UserId))
|
||||
room.State = (RoomState)playerData.RoomState;
|
||||
}
|
||||
|
||||
|
@ -101,12 +101,12 @@ public class MatchController : ControllerBase
|
|||
|
||||
if (matchData is CreateRoom createRoom && MatchHelper.UserLocations.Count >= 1)
|
||||
{
|
||||
List<User> users = new();
|
||||
List<int> users = new();
|
||||
foreach (string playerUsername in createRoom.Players)
|
||||
{
|
||||
User? player = await this.database.Users.FirstOrDefaultAsync(u => u.Username == playerUsername);
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
if (player != null) users.Add(player);
|
||||
if (player != null) users.Add(player.UserId);
|
||||
else return this.BadRequest();
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class MatchController : ControllerBase
|
|||
|
||||
if (matchData is UpdatePlayersInRoom updatePlayersInRoom)
|
||||
{
|
||||
Room? room = RoomHelper.Rooms.FirstOrDefault(r => r.Host == user);
|
||||
Room? room = RoomHelper.Rooms.FirstOrDefault(r => r.HostId == user.UserId);
|
||||
|
||||
if (room != null)
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ public class MatchController : ControllerBase
|
|||
else return this.BadRequest();
|
||||
}
|
||||
|
||||
room.Players = users;
|
||||
room.PlayerIds = users.Select(u => u.UserId).ToList();
|
||||
RoomHelper.CleanupRooms(null, room);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue