diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index c0325f0..da84a49 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -81,7 +81,7 @@ namespace Minecraft_Realms_Emulator.Controllers { var worlds = await _context.Worlds.ToListAsync(); - var world = worlds.Find(p => p.Id == id); + var world = worlds.Find(w => w.Id == id); if (world == null) return NotFound("World not found"); if (world.State != State.UNINITIALIZED.ToString()) return NotFound("World already initialized"); @@ -97,10 +97,42 @@ namespace Minecraft_Realms_Emulator.Controllers } [HttpPost("{id}/reset")] - public ActionResult Reset(int id) + public ActionResult Reset(int id) { Console.WriteLine($"Resetting world {id}"); return Ok(true); } + + [HttpPut("{id}/open")] + public async Task> Open(int id) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.Find(w => w.Id == id); + + if (world == null) return NotFound("World not found"); + + world.State = State.OPEN.ToString(); + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPut("{id}/close")] + public async Task> Close(int id) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.Find(w => w.Id == id); + + if (world == null) return NotFound("World not found"); + + world.State = State.CLOSED.ToString(); + + _context.SaveChanges(); + + return Ok(true); + } } }