From 1377f7e5a186dd744ec0276841303ae5fcf1ec9e Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sun, 17 Mar 2024 20:43:27 +0100 Subject: [PATCH] feat: world leaving --- .../Controllers/InvitesController.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Minecraft-Realms-Emulator/Controllers/InvitesController.cs b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs index 1b45e4b..0458375 100644 --- a/Minecraft-Realms-Emulator/Controllers/InvitesController.cs +++ b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs @@ -157,5 +157,26 @@ namespace Minecraft_Realms_Emulator.Controllers return Ok(true); } + + [HttpDelete("{wId}")] + public async Task> LeaveWorld(int wId) + { + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId); + + if (world == null) return NotFound("World not found"); + + var players = world.Players.ToList(); + + var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == playerUUID); + + _context.Players.Remove(player); + + _context.SaveChanges(); + + return Ok(true); + } } }