From 5115c608d7f72101cd9a6e1a964170ca7a270867 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Tue, 21 May 2024 12:41:32 +0200 Subject: [PATCH] fix: slot compatibility --- .../Controllers/WorldsController.cs | 23 +++++++++++-------- .../Responses/SlotOptionsResponse.cs | 9 ++++++++ .../{SlotsResponse.cs => SlotResponse.cs} | 2 +- .../Responses/WorldResponse.cs | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Responses/SlotOptionsResponse.cs rename Minecraft-Realms-Emulator/Responses/{SlotsResponse.cs => SlotResponse.cs} (83%) diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 1c6677b..cca05ee 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -150,14 +150,14 @@ namespace Minecraft_Realms_Emulator.Controllers Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot); - int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch)); - string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE"; - - List slots = []; + List slots = []; foreach (var slot in world.Slots) { - slots.Add(new SlotsResponse() + int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(slot.Version, SemVersionStyles.OptionalPatch)); + string compatibility = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE"; + + slots.Add(new SlotResponse() { SlotId = slot.SlotId, Options = JsonConvert.SerializeObject(new @@ -173,11 +173,13 @@ namespace Minecraft_Realms_Emulator.Controllers spawnNPCs = slot.SpawnNPCs, commandBlocks = slot.CommandBlocks, version = slot.Version, - compatibility = isCompatible + compatibility }) }); } + var activeSlotOptions = JsonConvert.DeserializeObject(slots.Find(s => s.SlotId == activeSlot.SlotId).Options); + WorldResponse response = new() { Id = world.Id, @@ -198,8 +200,8 @@ namespace Minecraft_Realms_Emulator.Controllers DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days, Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0, ExpiredTrial = false, - ActiveVersion = activeSlot.Version, - Compatibility = isCompatible + ActiveVersion = activeSlotOptions.Version, + Compatibility = activeSlotOptions.Compatibility }; return response; @@ -344,7 +346,7 @@ namespace Minecraft_Realms_Emulator.Controllers } [HttpPut("{wId}/slot/{sId}")] - public async Task> SwitchSlot(int wId, int sId) + public ActionResult SwitchSlot(int wId, int sId) { var world = _context.Worlds.Find(wId); @@ -357,7 +359,8 @@ namespace Minecraft_Realms_Emulator.Controllers string cookie = Request.Headers.Cookie; string gameVersion = cookie.Split(";")[2].Split("=")[1]; - _context.Slots.Add(new() { + _context.Slots.Add(new() + { World = world, SlotId = sId, SlotName = "", diff --git a/Minecraft-Realms-Emulator/Responses/SlotOptionsResponse.cs b/Minecraft-Realms-Emulator/Responses/SlotOptionsResponse.cs new file mode 100644 index 0000000..287ff59 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/SlotOptionsResponse.cs @@ -0,0 +1,9 @@ +using Minecraft_Realms_Emulator.Requests; + +namespace Minecraft_Realms_Emulator.Responses +{ + public class SlotOptionsResponse : SlotOptionsRequest + { + public string Compatibility { get; set; } = null!; + } +} diff --git a/Minecraft-Realms-Emulator/Responses/SlotsResponse.cs b/Minecraft-Realms-Emulator/Responses/SlotResponse.cs similarity index 83% rename from Minecraft-Realms-Emulator/Responses/SlotsResponse.cs rename to Minecraft-Realms-Emulator/Responses/SlotResponse.cs index cf32daf..27d8e3d 100644 --- a/Minecraft-Realms-Emulator/Responses/SlotsResponse.cs +++ b/Minecraft-Realms-Emulator/Responses/SlotResponse.cs @@ -1,6 +1,6 @@ namespace Minecraft_Realms_Emulator.Responses { - public class SlotsResponse + public class SlotResponse { public int SlotId { get; set; } public string Options { get; set; } = null!; diff --git a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs index acd68fb..d839c15 100644 --- a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs +++ b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs @@ -9,7 +9,7 @@ namespace Minecraft_Realms_Emulator.Entities public bool Expired { get; set; } = false; public bool ExpiredTrial { get; set; } = false; public string Compatibility { get; set; } = null!; - public List Slots { get; set; } = null!; + public List Slots { get; set; } = null!; public string ActiveVersion { get; set; } = null!; } } \ No newline at end of file