mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-26 11:19:07 +00:00
Add automatic room cleanup
This commit is contained in:
parent
487ec5bc8f
commit
3f29934628
2 changed files with 29 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
|
@ -23,6 +24,22 @@ public class RoomHelper
|
|||
|
||||
private static int roomIdIncrement;
|
||||
|
||||
public static void StartCleanupThread()
|
||||
{
|
||||
// ReSharper disable once FunctionNeverReturns
|
||||
Task.Factory.StartNew
|
||||
(
|
||||
async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
CleanupRooms();
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
internal static int RoomIdIncrement => roomIdIncrement++;
|
||||
|
||||
public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, string? location)
|
||||
|
@ -167,6 +184,8 @@ public class RoomHelper
|
|||
{
|
||||
lock(Rooms)
|
||||
{
|
||||
int roomCountBeforeCleanup = Rooms.Count;
|
||||
|
||||
// Remove offline players from rooms
|
||||
foreach (Room room in Rooms)
|
||||
{
|
||||
|
@ -198,6 +217,13 @@ public class RoomHelper
|
|||
|
||||
Rooms.RemoveAll(r => r.Players.Count == 0); // Remove empty rooms
|
||||
Rooms.RemoveAll(r => r.Players.Count > 4); // Remove obviously bogus rooms
|
||||
|
||||
int roomCountAfterCleanup = Rooms.Count;
|
||||
|
||||
if (roomCountBeforeCleanup != roomCountAfterCleanup)
|
||||
{
|
||||
Logger.Log($"Cleaned up {roomCountBeforeCleanup - roomCountAfterCleanup} rooms.", LoggerLevelMatch.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -80,6 +80,9 @@ public static class Program
|
|||
|
||||
FileHelper.ConvertAllTexturesToPng();
|
||||
|
||||
Logger.Log("Starting room cleanup thread...", LoggerLevelStartup.Instance);
|
||||
RoomHelper.StartCleanupThread();
|
||||
|
||||
stopwatch.Stop();
|
||||
Logger.Log($"Ready! Startup took {stopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LoggerLevelStartup.Instance);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue