From c2f62fdffb6eb2e75a649c7a41a3e5835c1aa176 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sun, 20 Oct 2024 14:26:30 +0200 Subject: [PATCH] fix: check if world is initialized --- .../Modes/External/WorldsController.cs | 11 +++++++++++ .../Modes/Realms/Controllers/WorldsController.cs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs index a2f1245..1267279 100644 --- a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs @@ -409,6 +409,17 @@ namespace Minecraft_Realms_Emulator.Modes.External var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.ParentWorld.Subscription).FirstOrDefaultAsync(w => w.Id == wId); + if (world.State == nameof(StateEnum.UNINITIALIZED)) + { + ErrorResponse error = new() + { + ErrorCode = 400, + ErrorMsg = "Initialize the world first" + }; + + return StatusCode(400, error); + } + Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot); List slots = []; diff --git a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs index ce99c75..44c6172 100644 --- a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs @@ -412,6 +412,17 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.ParentWorld.Subscription).FirstOrDefaultAsync(w => w.Id == wId); + if (world.State == nameof(StateEnum.UNINITIALIZED)) + { + ErrorResponse error = new() + { + ErrorCode = 400, + ErrorMsg = "Initialize the world first" + }; + + return StatusCode(400, error); + } + Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot); List slots = [];