From c6d0e03d810d0f40c2a6fec60988a84b9cc102a8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 18 May 2024 10:42:28 +1000 Subject: [PATCH] Add /update latest to allow updating to latest commit --- MCGalaxy/Commands/Maintenance/CmdUpdate.cs | 11 +++++++--- MCGalaxy/Server/Maintenance/Updater.cs | 24 ++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/MCGalaxy/Commands/Maintenance/CmdUpdate.cs b/MCGalaxy/Commands/Maintenance/CmdUpdate.cs index a308b91de..e733da86c 100644 --- a/MCGalaxy/Commands/Maintenance/CmdUpdate.cs +++ b/MCGalaxy/Commands/Maintenance/CmdUpdate.cs @@ -30,8 +30,10 @@ public override void Use(Player p, string message, CommandData data) { p.Message("Checking for updates.."); bool needsUpdating = Updater.NeedsUpdating(); p.Message("Server {0}", needsUpdating ? "&cneeds updating" : "&ais up to date"); - } else if (message.Length == 0) { - Updater.PerformUpdate(); + } else if (message.CaselessEq("latest")) { + Updater.PerformUpdate(false); + } else if (message.Length == 0) { + Updater.PerformUpdate(true); } else { Help(p); } @@ -40,8 +42,11 @@ public override void Use(Player p, string message, CommandData data) { public override void Help(Player p) { p.Message("&T/Update check"); p.Message("&HChecks whether the server needs updating"); + p.Message("&T/Update latest"); + p.Message("&HUpdates the server to the latest unstable build"); + p.Message("&WNote unstable builds may have more bugs or issues"); p.Message("&T/Update"); - p.Message("&HForce updates the server"); + p.Message("&HUpdates the server to the latest release"); } } } diff --git a/MCGalaxy/Server/Maintenance/Updater.cs b/MCGalaxy/Server/Maintenance/Updater.cs index f8e3edc5f..46e42ca8b 100644 --- a/MCGalaxy/Server/Maintenance/Updater.cs +++ b/MCGalaxy/Server/Maintenance/Updater.cs @@ -32,7 +32,7 @@ public static class Updater const string CurrentVersionURL = BaseURL + "Uploads/current_version.txt"; const string changelogURL = BaseURL + "Changelog.txt"; - const string CDN_URL = "https://cdn.classicube.net/client/mcg/release/"; + const string CDN_URL = "https://cdn.classicube.net/client/mcg/{0}/"; #if NET_20 const string CDN_BASE = CDN_URL + "net20/"; #else @@ -76,21 +76,27 @@ public static bool NeedsUpdating() { return new Version(latest) > new Version(Server.Version); } } + - public static void PerformUpdate() { + // Backwards compatibility + public static void PerformUpdate() { PerformUpdate(true); } + + public static void PerformUpdate(bool release) { try { try { DeleteFiles("Changelog.txt", "MCGalaxy_.update", "MCGalaxy.update", "MCGalaxyCLI.update", "prev_MCGalaxy_.dll", "prev_MCGalaxy.exe", "prev_MCGalaxyCLI.exe"); } catch { } - Logger.Log(LogType.SystemActivity, "Downloading update files"); + + string mode = release ? "release" : "latest"; + Logger.Log(LogType.SystemActivity, "Downloading {0} update files", mode); WebClient client = HttpUtil.CreateWebClient(); - client.DownloadFile(DLL_URL, "MCGalaxy_.update"); + client.DownloadFile(DLL_URL.Replace("{0}", mode), "MCGalaxy_.update"); #if !MCG_STANDALONE - client.DownloadFile(GUI_URL, "MCGalaxy.update"); - client.DownloadFile(CLI_URL, "MCGalaxyCLI.update"); + client.DownloadFile(GUI_URL.Replace("{0}", mode), "MCGalaxy.update"); + client.DownloadFile(CLI_URL.Replace("{0}", mode), "MCGalaxyCLI.update"); #endif client.DownloadFile(changelogURL, "Changelog.txt"); @@ -104,9 +110,9 @@ public static void PerformUpdate() { // can overwrite original the files without breaking the server) AtomicIO.TryMove(serverDLL, "prev_MCGalaxy_.dll"); AtomicIO.TryMove("MCGalaxy.exe", "prev_MCGalaxy.exe"); - AtomicIO.TryMove("MCGalaxyCLI.exe", "prev_MCGalaxyCLI.exe"); - - // Move update files to current files + AtomicIO.TryMove("MCGalaxyCLI.exe", "prev_MCGalaxyCLI.exe"); + + // Move update files to current files AtomicIO.TryMove("MCGalaxy_.update", serverDLL); AtomicIO.TryMove("MCGalaxy.update", "MCGalaxy.exe"); AtomicIO.TryMove("MCGalaxyCLI.update", "MCGalaxyCLI.exe");