mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Reorganize RoomHelper
This commit is contained in:
parent
9ee2778595
commit
92d8512090
2 changed files with 18 additions and 23 deletions
|
@ -18,14 +18,6 @@ public class RoomHelper
|
||||||
{
|
{
|
||||||
public static readonly StorableList<Room> Rooms = RoomStore.GetRooms();
|
public static readonly StorableList<Room> Rooms = RoomStore.GetRooms();
|
||||||
|
|
||||||
public static readonly RoomSlot PodSlot = new()
|
|
||||||
{
|
|
||||||
SlotType = SlotType.Pod,
|
|
||||||
SlotId = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
private static int roomIdIncrement;
|
|
||||||
|
|
||||||
public static void StartCleanupThread()
|
public static void StartCleanupThread()
|
||||||
{
|
{
|
||||||
// ReSharper disable once FunctionNeverReturns
|
// ReSharper disable once FunctionNeverReturns
|
||||||
|
@ -42,6 +34,7 @@ public class RoomHelper
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int roomIdIncrement;
|
||||||
internal static int RoomIdIncrement => roomIdIncrement++;
|
internal static int RoomIdIncrement => roomIdIncrement++;
|
||||||
|
|
||||||
public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, RoomSlot? slot, Platform? platform, string? location)
|
public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, RoomSlot? slot, Platform? platform, string? location)
|
||||||
|
@ -163,7 +156,7 @@ public class RoomHelper
|
||||||
RoomId = RoomIdIncrement,
|
RoomId = RoomIdIncrement,
|
||||||
PlayerIds = users,
|
PlayerIds = users,
|
||||||
State = RoomState.Idle,
|
State = RoomState.Idle,
|
||||||
Slot = slot ?? PodSlot,
|
Slot = slot ?? RoomSlot.PodSlot,
|
||||||
RoomVersion = roomVersion,
|
RoomVersion = roomVersion,
|
||||||
RoomPlatform = roomPlatform,
|
RoomPlatform = roomPlatform,
|
||||||
};
|
};
|
||||||
|
@ -177,23 +170,22 @@ public class RoomHelper
|
||||||
|
|
||||||
public static Room? FindRoomByUser(int userId, GameVersion roomVersion, Platform roomPlatform, bool createIfDoesNotExist = false)
|
public static Room? FindRoomByUser(int userId, GameVersion roomVersion, Platform roomPlatform, bool createIfDoesNotExist = false)
|
||||||
{
|
{
|
||||||
lock(Rooms)
|
foreach (Room room in Rooms.Where(room => room.PlayerIds.Any(player => userId == player)))
|
||||||
foreach (Room room in Rooms.Where(room => room.PlayerIds.Any(player => userId == player)))
|
return room;
|
||||||
return room;
|
|
||||||
|
|
||||||
return createIfDoesNotExist ? CreateRoom(userId, roomVersion, roomPlatform) : null;
|
return createIfDoesNotExist ? CreateRoom(userId, roomVersion, roomPlatform) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Room? FindRoomByUserId(int userId)
|
public static Room? FindRoomByUserId(int userId)
|
||||||
{
|
{
|
||||||
lock(Rooms)
|
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||||
foreach (Room room in Rooms)
|
foreach (Room room in Rooms)
|
||||||
|
{
|
||||||
|
if (room.PlayerIds.Any(p => p == userId))
|
||||||
{
|
{
|
||||||
if (room.PlayerIds.Any(p => p == userId))
|
return room;
|
||||||
{
|
|
||||||
return room;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -201,9 +193,7 @@ public class RoomHelper
|
||||||
[SuppressMessage("ReSharper", "InvertIf")]
|
[SuppressMessage("ReSharper", "InvertIf")]
|
||||||
public static void CleanupRooms(int? hostId = null, Room? newRoom = null, Database? database = null)
|
public static void CleanupRooms(int? hostId = null, Room? newRoom = null, Database? database = null)
|
||||||
{
|
{
|
||||||
lock(Rooms)
|
int roomCountBeforeCleanup = Rooms.Count();
|
||||||
{
|
|
||||||
int roomCountBeforeCleanup = Rooms.Count();
|
|
||||||
|
|
||||||
// Remove offline players from rooms
|
// Remove offline players from rooms
|
||||||
foreach (Room room in Rooms)
|
foreach (Room room in Rooms)
|
||||||
|
@ -244,6 +234,5 @@ public class RoomHelper
|
||||||
{
|
{
|
||||||
Logger.LogDebug($"Cleaned up {roomCountBeforeCleanup - roomCountAfterCleanup} rooms.", LogArea.Match);
|
Logger.LogDebug($"Cleaned up {roomCountBeforeCleanup - roomCountAfterCleanup} rooms.", LogArea.Match);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,4 +6,10 @@ public class RoomSlot
|
||||||
{
|
{
|
||||||
public int SlotId { get; set; }
|
public int SlotId { get; set; }
|
||||||
public SlotType SlotType { get; set; }
|
public SlotType SlotType { get; set; }
|
||||||
|
|
||||||
|
public static readonly RoomSlot PodSlot = new()
|
||||||
|
{
|
||||||
|
SlotType = SlotType.Pod,
|
||||||
|
SlotId = 0,
|
||||||
|
};
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue