From 54a05537c4feffeabced0b7db370d74f465e87a8 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Mon, 9 Dec 2024 23:05:35 +0100 Subject: [PATCH] refactor: fix motd showing as "..." on minecraft >1.21.1, SlotsResponse.Options now has proper typing --- .../Modes/External/WorldsController.cs | 46 ++++++++++++------- .../Realms/Controllers/WorldsController.cs | 46 ++++++++++++------- .../Shared/Responses/SlotOptionsResponse.cs | 1 + .../Shared/Responses/SlotResponse.cs | 7 ++- .../Shared/Responses/WorldResponse.cs | 2 + 5 files changed, 69 insertions(+), 33 deletions(-) diff --git a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs index 0122218..59406d3 100644 --- a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs @@ -7,7 +7,6 @@ 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,6 +72,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -114,6 +115,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -173,6 +176,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -227,6 +232,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -325,6 +332,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -368,6 +377,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -432,25 +443,26 @@ namespace Minecraft_Realms_Emulator.Modes.External slots.Add(new SlotResponse() { SlotId = slot.SlotId, - Options = JsonConvert.SerializeObject(new + Options = { - slotName = slot.SlotName, - gameMode = slot.GameMode, - 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 - }) + 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 + } }); } - var activeSlotOptions = JsonConvert.DeserializeObject(slots.Find(s => s.SlotId == activeSlot.SlotId).Options); + SlotOptionsResponse activeSlotOptions = slots.Find(s => s.SlotId == activeSlot.SlotId).Options; if (world.ParentWorld != null) { @@ -464,6 +476,8 @@ namespace Minecraft_Realms_Emulator.Modes.External OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = 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 0b722a6..fd312d2 100644 --- a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs @@ -8,7 +8,6 @@ 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; using System.Net; using System.Net.Sockets; @@ -76,6 +75,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -117,6 +118,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -176,6 +179,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -230,6 +235,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -328,6 +335,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -371,6 +380,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, @@ -435,25 +446,26 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers slots.Add(new SlotResponse() { SlotId = slot.SlotId, - Options = JsonConvert.SerializeObject(new + Options = { - slotName = slot.SlotName, - gameMode = slot.GameMode, - 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 - }) + 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 + } }); } - var activeSlotOptions = JsonConvert.DeserializeObject(slots.Find(s => s.SlotId == activeSlot.SlotId).Options); + SlotOptionsResponse activeSlotOptions = slots.Find(s => s.SlotId == activeSlot.SlotId).Options; if (world.ParentWorld != null) { @@ -467,6 +479,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers OwnerUUID = world.OwnerUUID, Name = world.Name, Motd = world.Motd, + GameMode = activeSlot.GameMode, + Hardcore = activeSlot.Difficulty == 3, State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, diff --git a/Minecraft-Realms-Emulator/Shared/Responses/SlotOptionsResponse.cs b/Minecraft-Realms-Emulator/Shared/Responses/SlotOptionsResponse.cs index fd7377d..03847ae 100644 --- a/Minecraft-Realms-Emulator/Shared/Responses/SlotOptionsResponse.cs +++ b/Minecraft-Realms-Emulator/Shared/Responses/SlotOptionsResponse.cs @@ -5,5 +5,6 @@ namespace Minecraft_Realms_Emulator.Shared.Responses public class SlotOptionsResponse : SlotOptionsRequest { public string Compatibility { get; set; } = null!; + public bool Hardcore { get; set; } } } diff --git a/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs b/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs index 4d2c738..ea0daf0 100644 --- a/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs +++ b/Minecraft-Realms-Emulator/Shared/Responses/SlotResponse.cs @@ -3,6 +3,11 @@ public class SlotResponse { public int SlotId { get; set; } - public string Options { get; set; } = null!; + public SlotOptionsResponse Options { get; set; } = null!; + + public SlotResponse() + { + Options = new SlotOptionsResponse(); + } } } diff --git a/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs index 3c3fc8f..2a57f0a 100644 --- a/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs +++ b/Minecraft-Realms-Emulator/Shared/Responses/WorldResponse.cs @@ -5,6 +5,8 @@ namespace Minecraft_Realms_Emulator.Shared.Responses public class WorldResponse : World { public string RemoteSubscriptionId { get; set; } = new Guid().ToString(); + public bool Hardcore { get; set; } + public int GameMode { get; set; } public int DaysLeft { get; set; } = 30; public bool Expired { get; set; } = false; public bool ExpiredTrial { get; set; } = false;