From ff325cf5f6a1e2a0f80e2bceae9fc6b6e5d586d9 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Thu, 19 Dec 2024 21:06:02 +0100 Subject: [PATCH] fix: update game version on slot if server has updates enabled --- .../Modes/Realms/Controllers/WorldsController.cs | 12 +++++++++++- .../Modes/Realms/Helpers/DockerHelper.cs | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs index 0d7a159..d5f631d 100644 --- a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs @@ -902,7 +902,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers [HttpGet("v1/{wId}/join/pc")] public async Task> Join(int wId) { - var connection = _context.Connections.Include(c => c.World).FirstOrDefault(x => x.World.Id == wId); + var connection = _context.Connections.Include(c => c.World).Include(c => c.World.Slots).FirstOrDefault(x => x.World.Id == wId); var isRunning = new DockerHelper(connection.World).IsRunning(); var query = new MinecraftServerQuery().Query(connection.Address); @@ -918,7 +918,17 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers query = new MinecraftServerQuery().Query(connection.Address); } + Slot activeSlot = connection.World.Slots.Find(s => s.SlotId == connection.World.ActiveSlot); + string cookie = Request.Headers.Cookie; + string gameVersion = cookie.Split(";")[2].Split("=")[1]; + + if (new MinecraftVersionParser.MinecraftVersion(activeSlot.Version).CompareTo(new MinecraftVersionParser.MinecraftVersion(gameVersion)) < 0 && new DockerHelper(connection.World).RunCommand("! test -f .no-update") == 0) + { + activeSlot.Version = gameVersion; + _context.SaveChanges(); + } + string playerUUID = cookie.Split(";")[0].Split(":")[2]; if (connection.World.OwnerUUID == playerUUID) diff --git a/Minecraft-Realms-Emulator/Modes/Realms/Helpers/DockerHelper.cs b/Minecraft-Realms-Emulator/Modes/Realms/Helpers/DockerHelper.cs index 19b29d6..06de2ba 100644 --- a/Minecraft-Realms-Emulator/Modes/Realms/Helpers/DockerHelper.cs +++ b/Minecraft-Realms-Emulator/Modes/Realms/Helpers/DockerHelper.cs @@ -116,7 +116,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers commandProcess.Start(); } - public void RunCommand(string command) + public int RunCommand(string command) { ProcessStartInfo commandProcessInfo = new(); @@ -127,6 +127,9 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers commandProcess.StartInfo = commandProcessInfo; commandProcess.Start(); + commandProcess.WaitForExit(); + + return commandProcess.ExitCode; } } } \ No newline at end of file