fix: slot compatibility

This commit is contained in:
CyberL1 2024-05-21 12:41:32 +02:00
parent 4546e84d8d
commit 5115c608d7
4 changed files with 24 additions and 12 deletions

View File

@ -150,14 +150,14 @@ namespace Minecraft_Realms_Emulator.Controllers
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot); Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch)); List<SlotResponse> slots = [];
string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
List<SlotsResponse> slots = [];
foreach (var slot in world.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, SlotId = slot.SlotId,
Options = JsonConvert.SerializeObject(new Options = JsonConvert.SerializeObject(new
@ -173,11 +173,13 @@ namespace Minecraft_Realms_Emulator.Controllers
spawnNPCs = slot.SpawnNPCs, spawnNPCs = slot.SpawnNPCs,
commandBlocks = slot.CommandBlocks, commandBlocks = slot.CommandBlocks,
version = slot.Version, version = slot.Version,
compatibility = isCompatible compatibility
}) })
}); });
} }
var activeSlotOptions = JsonConvert.DeserializeObject<SlotOptionsResponse>(slots.Find(s => s.SlotId == activeSlot.SlotId).Options);
WorldResponse response = new() WorldResponse response = new()
{ {
Id = world.Id, Id = world.Id,
@ -198,8 +200,8 @@ namespace Minecraft_Realms_Emulator.Controllers
DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days, DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days,
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0, Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
ExpiredTrial = false, ExpiredTrial = false,
ActiveVersion = activeSlot.Version, ActiveVersion = activeSlotOptions.Version,
Compatibility = isCompatible Compatibility = activeSlotOptions.Compatibility
}; };
return response; return response;
@ -344,7 +346,7 @@ namespace Minecraft_Realms_Emulator.Controllers
} }
[HttpPut("{wId}/slot/{sId}")] [HttpPut("{wId}/slot/{sId}")]
public async Task<ActionResult<bool>> SwitchSlot(int wId, int sId) public ActionResult<bool> SwitchSlot(int wId, int sId)
{ {
var world = _context.Worlds.Find(wId); var world = _context.Worlds.Find(wId);
@ -357,7 +359,8 @@ namespace Minecraft_Realms_Emulator.Controllers
string cookie = Request.Headers.Cookie; string cookie = Request.Headers.Cookie;
string gameVersion = cookie.Split(";")[2].Split("=")[1]; string gameVersion = cookie.Split(";")[2].Split("=")[1];
_context.Slots.Add(new() { _context.Slots.Add(new()
{
World = world, World = world,
SlotId = sId, SlotId = sId,
SlotName = "", SlotName = "",

View File

@ -0,0 +1,9 @@
using Minecraft_Realms_Emulator.Requests;
namespace Minecraft_Realms_Emulator.Responses
{
public class SlotOptionsResponse : SlotOptionsRequest
{
public string Compatibility { get; set; } = null!;
}
}

View File

@ -1,6 +1,6 @@
namespace Minecraft_Realms_Emulator.Responses namespace Minecraft_Realms_Emulator.Responses
{ {
public class SlotsResponse public class SlotResponse
{ {
public int SlotId { get; set; } public int SlotId { get; set; }
public string Options { get; set; } = null!; public string Options { get; set; } = null!;

View File

@ -9,7 +9,7 @@ namespace Minecraft_Realms_Emulator.Entities
public bool Expired { get; set; } = false; public bool Expired { get; set; } = false;
public bool ExpiredTrial { get; set; } = false; public bool ExpiredTrial { get; set; } = false;
public string Compatibility { get; set; } = null!; public string Compatibility { get; set; } = null!;
public List<SlotsResponse> Slots { get; set; } = null!; public List<SlotResponse> Slots { get; set; } = null!;
public string ActiveVersion { get; set; } = null!; public string ActiveVersion { get; set; } = null!;
} }
} }