From 54a61570bde0cefd0229d75f2fe77eb138112cb6 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 31 Oct 2021 18:28:25 -0400 Subject: [PATCH] Fix LBP1 minimum players --- .../Controllers/PublishController.cs | 6 ++++++ ProjectLighthouse/Program.cs | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ProjectLighthouse/Controllers/PublishController.cs b/ProjectLighthouse/Controllers/PublishController.cs index 4efb4176..a19b7bb8 100644 --- a/ProjectLighthouse/Controllers/PublishController.cs +++ b/ProjectLighthouse/Controllers/PublishController.cs @@ -96,6 +96,12 @@ namespace LBPUnion.ProjectLighthouse.Controllers slot.FirstUploaded = TimeHelper.UnixTimeMilliseconds(); slot.LastUpdated = TimeHelper.UnixTimeMilliseconds(); + if (slot.MinimumPlayers == 0 || slot.MaximumPlayers == 0) + { + slot.MinimumPlayers = 1; + slot.MaximumPlayers = 4; + } + this.database.Slots.Add(slot); await this.database.SaveChangesAsync(); diff --git a/ProjectLighthouse/Program.cs b/ProjectLighthouse/Program.cs index 804f9c94..4ea2009c 100644 --- a/ProjectLighthouse/Program.cs +++ b/ProjectLighthouse/Program.cs @@ -45,6 +45,9 @@ namespace LBPUnion.ProjectLighthouse Logger.Log("Fixing broken timestamps...", LoggerLevelDatabase.Instance); FixTimestamps(database); + Logger.Log("Fixing old LBP1 MinimumPlayers columns", LoggerLevelDatabase.Instance); + FixMinimumPlayers(database); + stopwatch.Stop(); Logger.Log($"Ready! Startup took {stopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LoggerLevelStartup.Instance); @@ -79,6 +82,23 @@ namespace LBPUnion.ProjectLighthouse Logger.Log($"Fixing timestamps took {stopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance); } + public static void FixMinimumPlayers(Database database) + { + Stopwatch stopwatch = new(); + stopwatch.Start(); + + foreach (Slot slot in database.Slots.Where(s => s.MinimumPlayers == 0)) + { + slot.MinimumPlayers = 1; + slot.MaximumPlayers = 4; + } + + database.SaveChanges(); + + stopwatch.Stop(); + Logger.Log($"Fixing minimum players took {stopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance); + } + public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults