From 4605ac5fef076d008ab06aaef50ece12010b82c8 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Fri, 13 Dec 2024 21:16:34 +0100 Subject: [PATCH] fix: world slots --- .../Modes/External/WorldsController.cs | 47 ++++++++++--------- .../Realms/Controllers/WorldsController.cs | 47 ++++++++++--------- .../Shared/Responses/SlotResponse.cs | 5 +- .../Shared/Responses/SlotSettingsResponse.cs | 7 +++ .../Shared/Responses/WorldResponse.cs | 3 +- 5 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Shared/Responses/SlotSettingsResponse.cs diff --git a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs index 59406d3..e36eda8 100644 --- a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs @@ -7,6 +7,7 @@ using Minecraft_Realms_Emulator.Shared.Data; using Minecraft_Realms_Emulator.Shared.Entities; using Minecraft_Realms_Emulator.Shared.Requests; using Minecraft_Realms_Emulator.Shared.Responses; +using Newtonsoft.Json; namespace Minecraft_Realms_Emulator.Modes.External { @@ -73,7 +74,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -116,7 +117,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -177,7 +178,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -233,7 +234,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -333,7 +334,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -378,7 +379,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -443,26 +444,26 @@ namespace Minecraft_Realms_Emulator.Modes.External slots.Add(new SlotResponse() { SlotId = slot.SlotId, - Options = + Options = JsonConvert.SerializeObject(new { - SlotName = slot.SlotName, - GameMode = slot.GameMode, - Hardcore = slot.GameMode == 3, - Difficulty = slot.Difficulty, - SpawnProtection = slot.SpawnProtection, - ForceGameMode = slot.ForceGameMode, - Pvp = slot.Pvp, - SpawnAnimals = slot.SpawnAnimals, - SpawnMonsters = slot.SpawnMonsters, - SpawnNPCs = slot.SpawnNPCs, - CommandBlocks = slot.CommandBlocks, - Version = slot.Version, - Compatibility = compatibility - } + slotName = slot.SlotName, + gameMode = slot.GameMode, + hardcore = slot.Difficulty == 3, + difficulty = slot.Difficulty, + spawnProection = slot.SpawnProtection, + forceGameMode = slot.ForceGameMode, + pvp = slot.Pvp, + spawnAnimals = slot.SpawnAnimals, + spawnMonsters = slot.SpawnMonsters, + spawnNPCs = slot.SpawnNPCs, + commandBlocks = slot.CommandBlocks, + version = slot.Version, + compatibility + }) }); } - SlotOptionsResponse activeSlotOptions = slots.Find(s => s.SlotId == activeSlot.SlotId).Options; + var activeSlotOptions = JsonConvert.DeserializeObject(slots.Find(s => s.SlotId == activeSlot.SlotId).Options); if (world.ParentWorld != null) { @@ -477,7 +478,7 @@ namespace Minecraft_Realms_Emulator.Modes.External Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.GameMode == 3, + IsHardcore = activeSlot.GameMode == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, diff --git a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs index fd312d2..6474e0d 100644 --- a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs @@ -10,6 +10,7 @@ using Minecraft_Realms_Emulator.Shared.Requests; using Minecraft_Realms_Emulator.Shared.Responses; using System.Net; using System.Net.Sockets; +using Newtonsoft.Json; namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers { @@ -76,7 +77,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -119,7 +120,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -180,7 +181,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -236,7 +237,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -336,7 +337,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -381,7 +382,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -446,26 +447,26 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers slots.Add(new SlotResponse() { SlotId = slot.SlotId, - Options = + Options = JsonConvert.SerializeObject(new { - SlotName = slot.SlotName, - GameMode = slot.GameMode, - Hardcore = slot.Difficulty == 3, - Difficulty = slot.Difficulty, - SpawnProtection = slot.SpawnProtection, - ForceGameMode = slot.ForceGameMode, - Pvp = slot.Pvp, - SpawnAnimals = slot.SpawnAnimals, - SpawnMonsters = slot.SpawnMonsters, - SpawnNPCs = slot.SpawnNPCs, - CommandBlocks = slot.CommandBlocks, - Version = slot.Version, - Compatibility = compatibility - } + slotName = slot.SlotName, + gameMode = slot.GameMode, + hardcore = slot.Difficulty == 3, + difficulty = slot.Difficulty, + spawnProection = slot.SpawnProtection, + forceGameMode = slot.ForceGameMode, + pvp = slot.Pvp, + spawnAnimals = slot.SpawnAnimals, + spawnMonsters = slot.SpawnMonsters, + spawnNPCs = slot.SpawnNPCs, + commandBlocks = slot.CommandBlocks, + version = slot.Version, + compatibility + }) }); } - SlotOptionsResponse activeSlotOptions = slots.Find(s => s.SlotId == activeSlot.SlotId).Options; + var activeSlotOptions = JsonConvert.DeserializeObject(slots.Find(s => s.SlotId == activeSlot.SlotId).Options); if (world.ParentWorld != null) { @@ -480,7 +481,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Name = world.Name, Motd = world.Motd, GameMode = activeSlot.GameMode, - Hardcore = activeSlot.Difficulty == 3, + IsHardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, diff --git a/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs b/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs index ea0daf0..4cc7a8d 100644 --- a/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs +++ b/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs @@ -3,11 +3,12 @@ public class SlotResponse { public int SlotId { get; set; } - public SlotOptionsResponse Options { get; set; } = null!; + public SlotSettingsResponse Settings { get; set; } = null!; + public string Options { get; set; } = null!; public SlotResponse() { - Options = new SlotOptionsResponse(); + Settings = new SlotSettingsResponse(); } } } diff --git a/Minecraft-Realms-Emulator/Shared/Responses/SlotSettingsResponse.cs b/Minecraft-Realms-Emulator/Shared/Responses/SlotSettingsResponse.cs new file mode 100644 index 0000000..c96404f --- /dev/null +++ b/Minecraft-Realms-Emulator/Shared/Responses/SlotSettingsResponse.cs @@ -0,0 +1,7 @@ +namespace Minecraft_Realms_Emulator.Shared.Responses +{ + public class SlotSettingsResponse + { + public bool Hardcore { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs index 2a57f0a..926ffef 100644 --- a/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs +++ b/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs @@ -5,11 +5,12 @@ namespace Minecraft_Realms_Emulator.Shared.Responses public class WorldResponse : World { public string RemoteSubscriptionId { get; set; } = new Guid().ToString(); - public bool Hardcore { get; set; } + public bool IsHardcore { get; set; } = false; public int GameMode { get; set; } public int DaysLeft { get; set; } = 30; public bool Expired { get; set; } = false; public bool ExpiredTrial { get; set; } = false; + public bool GracePeriod { get; set; } = false; public string Compatibility { get; set; } = null!; public List Slots { get; set; } = null!; public string ActiveVersion { get; set; } = null!;