feat: world creating

This commit is contained in:
CyberL1 2024-02-03 11:48:22 +01:00
parent 94608fd792
commit e02db741d6
2 changed files with 35 additions and 0 deletions

View File

@ -75,5 +75,32 @@ namespace Minecraft_Realms_Emulator.Controllers
return world; return world;
} }
[HttpPost("{id}/initialize")]
public async Task<ActionResult<World>> Initialize(int id, WorldCreate body)
{
var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(p => p.Id == id);
if (world == null) return NotFound("World not found");
if (world.State != State.UNINITIALIZED.ToString()) return NotFound("World already initialized");
world.Name = body.Name;
world.Motd = body.Description;
world.State = State.OPEN.ToString();
_context.Worlds.Update(world);
_context.SaveChanges();
return Ok(world);
}
[HttpPost("{id}/reset")]
public ActionResult<World> Reset(int id)
{
Console.WriteLine($"Resetting world {id}");
return Ok(true);
}
} }
} }

View File

@ -0,0 +1,8 @@
namespace Minecraft_Realms_Emulator.Entities
{
public class WorldCreate
{
public string? Name { get; set; }
public string? Description { get; set; }
}
}