From 2dea13e5c953019f39564febd79a14333377c403 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Tue, 14 May 2024 06:55:29 +0200 Subject: [PATCH] feat: changing realm status changes the whitelist status --- MyMcRealms/Controllers/OpsController.cs | 12 +++++++----- MyMcRealms/Controllers/WorldsController.cs | 16 ++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/MyMcRealms/Controllers/OpsController.cs b/MyMcRealms/Controllers/OpsController.cs index 8381b21..aebdd12 100644 --- a/MyMcRealms/Controllers/OpsController.cs +++ b/MyMcRealms/Controllers/OpsController.cs @@ -13,9 +13,10 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpPost("{wId}/{uuid}")] public async Task> OpPlayer(int wId, string uuid) { - var api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); - var world = (await api.GetAllServers()).Servers[wId]; - + var _api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var world = (await _api.GetAllServers()).Servers[wId]; + var api = new MyMcAPI(world.OwnersToken); + var ops = world.Ops; var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid); @@ -40,8 +41,9 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpDelete("{wId}/{uuid}")] public async Task> DeopPlayerAsync(int wId, string uuid) { - var api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); - var world = (await api.GetAllServers()).Servers[wId]; + var _api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var world = (await _api.GetAllServers()).Servers[wId]; + var api = new MyMcAPI(world.OwnersToken); var ops = world.Ops; var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid); diff --git a/MyMcRealms/Controllers/WorldsController.cs b/MyMcRealms/Controllers/WorldsController.cs index 5187df7..8ba0d48 100644 --- a/MyMcRealms/Controllers/WorldsController.cs +++ b/MyMcRealms/Controllers/WorldsController.cs @@ -125,12 +125,14 @@ namespace MyMcRealms.Controllers [HttpPut("{id}/open")] public async Task> Open(int id) { - var worlds = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); - var world = worlds.Servers[id]; + var _api = new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + + var world = (await _api.GetAllServers()).Servers[id]; + var api = new MyMcAPI.MyMcAPI(world.OwnersToken); if (world == null) return NotFound("World not found"); - // Turn off whitelist + api.ExecuteCommand("whitelist off"); return Ok(true); } @@ -138,12 +140,14 @@ namespace MyMcRealms.Controllers [HttpPut("{id}/close")] public async Task> Close(int id) { - var worlds = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); - var world = worlds.Servers[id]; + var _api = new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + + var world = (await _api.GetAllServers()).Servers[id]; + var api = new MyMcAPI.MyMcAPI(world.OwnersToken); if (world == null) return NotFound("World not found"); - // Turn on whitelist + api.ExecuteCommand("whitelist on"); return Ok(true); }