From 3b9fd1fa646d057e6cdf1c7a3f6ad991ff2cc4a1 Mon Sep 17 00:00:00 2001 From: Clark Date: Fri, 25 Sep 2020 16:30:46 +0200 Subject: [PATCH] Fix updatecheck; Update .travis.yml Several improvements @tomrhollis --- .travis.yml | 20 +++++--------- src/Automation/Watchdog.cs | 13 +++++++++- src/Networking/UpdateChecker.cs | 46 +++++++++++++++++++++++++++++++++ src/Program.cs | 16 +++++++----- src/vellum.csproj | 4 +-- 5 files changed, 75 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index f148b79..d66b462 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,26 +17,23 @@ before-install: - chmod +x ./* - REPO_NAME=$(./get_repo-name.sh $TRAVIS_REPO_SLUG) - TAG_CLEAN=$(./get_tag_clean.sh $(echo $TRAVIS_TAG | sed -E 's/\-\w+//')) + - TAG_SUFFIX=$(echo $TRAVIS_TAG | sed -r 's/.+\-//') - ASSEMBLY_VERSION=$(./format_assembly-version.sh $TAG_CLEAN $TRAVIS_BUILD_NUMBER) before-script: - cd ~/build/${TRAVIS_REPO_SLUG}/src script: - ARTIFACT_SUFFIX=$(if [ "$SELF_CONTAINED" == "true" ]; then echo "-bundled"; elif [ "$OUTPUT_TYPE" == "Library" ]; then echo "-lib"; else echo ""; fi) - - ARTIFACT_NAME=${REPO_NAME}_${RUNTIME}${ARTIFACT_SUFFIX}_v${TAG_CLEAN}-${TRAVIS_BUILD_NUMBER} - - VERSION_SUFFIX=$(echo $TRAVIS_TAG | sed -E 's/.+\-//') - - dotnet publish vellum.csproj -c Release -r ${RUNTIME} /property:Version=${ASSEMBLY_VERSION} /property:OutputType=${OUTPUT_TYPE} /p:PublishTrimmed=${SELF_CONTAINED} --self-contained ${SELF_CONTAINED} $(if [[ ! -z $VERSION_SUFFIX ]]; then echo "/p:DefineConstants=\"$(echo $VERSION_SUFFIX | tr [:lower:] [:upper:])\""; fi) + - ARTIFACT_NAME=${REPO_NAME}_${RUNTIME}${ARTIFACT_SUFFIX}_v${TAG_CLEAN}$(if [[ ! -z $TAG_SUFFIX ]]; then echo "-$TAG_SUFFIX"; fi)-${TRAVIS_BUILD_NUMBER} + - dotnet publish vellum.csproj -c Release -r ${RUNTIME} /property:Version=${ASSEMBLY_VERSION} /property:OutputType=${OUTPUT_TYPE} /p:PublishTrimmed=${SELF_CONTAINED} --self-contained ${SELF_CONTAINED} $(if [[ ! -z $TAG_SUFFIX ]]; then echo "/p:DefineConstants=\"$(echo $TAG_SUFFIX | tr [:lower:] [:upper:])\""; fi) before_deploy: - cd bin/Release/netcoreapp3.1/${RUNTIME}/publish && zip ${ARTIFACT_NAME}.zip ./* - wget -q https://github.com/${TRAVIS_REPO_SLUG}/releases/download/${TRAVIS_TAG}/sha256sums.txt || true - - sha256sum ${ARTIFACT_NAME}.zip >> sha256sums.txt deploy: provider: releases token: secure: "bkpf8FnXooiKvbjgm/5kFV6y+5Apgi6sQm1iIdOfRTF4dkAdJG/p0fATFoR1V8HINIF9gN2bV7HefQz3UbgspbawPE/DK+HcHj1gHSjZ7QiabTSX4PgM5KfV0q54abIyot5kfyf+fj5RRrEsARFeDVpIi+B/VnyKJKb+5X9uTG8CzS1w4Afacjfh4gGFAW1aBAue/Oii96u42SZGk/gDX62kYUoiG1RXcx8acYSJOG241RfqiXN3zxZorhxItBLlAJUdC9n2FXPVw9awi/Joc643SE8TdBcqcggLKBieX8NVIk1YPIipanPZsubGafje78cqiMVquAxpq3BBamJEzKy4UPbW9SzI9/pkQtDuoaG6RvbtEjobKVKsKLeaP/uXE3fVorTeIpdNKmqkbag9yG0gOMu6JHkfEZCOHDBQXYSo22bevzO9dcWP8VmYwreaiUfYoZB3i+VEvZHH1k3ymEr4ckKchrg+/Enkj1SwzdDNdgl6PWsVt6Di+I8IMSMQ/Zqh3p6IhFWaX6WwIMbGcK2wkN1eqGg/aGfXCHoTatBi55zRYfvY3NlMzkuHX7Gn1Bf7Su6GR4NfBD7PbweQDI6dXO5bqfst9Dvq2a57SaDeRBzKtrPHWZ50ri3ppImucIUZmus4dCJlJSr2f1FVublzF2lI7EJI3u5eb8f7KH4=" file: - ${ARTIFACT_NAME}.zip - - sha256sums.txt - overwrite: true skip_cleanup: true on: repo: clarkx86/vellum @@ -45,21 +42,18 @@ jobs: include: - if: tag IS present env: - - secure: "QrNeuR+zCypZYVdECiIST4/vGPUCEmrPgu8BxuvX4ODYkPRai8YSAC1tEe075p2rcibnRcTL9Z2qz6C1zddGRtPM5YJZXU6u9beJB6Lr0rYOXCWeEEOmHSrAK6bH6gQDFMTnVMTErIJXImf+pJ9IkWDxetnR5W9Sc+rDvDWu0CNqizyypFXWtpNnYVgZ4jvwo67RSLAHxK9JmGUGpzzmqSxLAf5EwS1WXm5kjWLkmxsIGm6LfKvlWJkc/DWUGlxdZz56PXb6oOBhTHiHTTZ8POFN4y0o/znYB7JWFnv8No2xmi9nqep5RbT3tntgDTBJzbCCYMn8n/0X54P8r3wTNBaGfWTpsKcJbsMUEpHXw1+4U+J/fSKNTgvHwtryZqqrK9ZNaPm2c+eBBwXuHgyTTva5xcQ8YpXa08VfHXoi0ebEepLgPUl6Yc5UGH5+9NAHZimScszFF9TSn8Yw+UWo2NN4ihn2ISmmZpmXZpsr80cwZ27qPDrEmCnNl7v4AUaeq368y+QniKZBQJR9XPVblGnRDClXk5TNDryMEIXdAbHgMp2aMpg4UtavACqUlJCoMimTPpwCksmM/8X/wgv4gWHv9VmV4SRrxG9yg5qmkFazdoQDWcXUh8tgoV7Bw3oraIHFQvz5ihKjmh84hK7yDBdFGOAuH9YMi94VjV/8jpw=" + - secure: "WPihvGloAthhzpooE4uldwIVK6djl71CMQOj7AkfSMoZEPruV9kShIU1hipB7rH9Ek6+IbrdV4aajAKMzSGC6vlK2dhGDeSyuKmngcmffZzpW3dWahQT0GUxKXjzNPszyi7Gcln1L57l0oofTk4ScOKg1C6Nuzze/tKYxwzP1Ex1YG0JaQrNyCBfvOpw+b+oSl6UmFS30Sj+1EWfWFfdXP4Jn9k9zYEzdq+TsCY3FAME2LT/XYftS8mq/rHvYu7hrZdJtxTt/cOjOsWLHErNMlcxXiq3Jv1ZCUl6MtKxkrb3vMKVjxTV/ikuPVpzQdZgtgNyEPLA2wuEZaGVHpKM96MEKb/GM/ImqyrgXog1msUgoImix12rvLGxGKT9FUFu1Il0d2J+621jDzgifK1JlmGV1ci+E72AQAhd0ELAGTzEkR/8N1YFIhbUDkDTWfZSFMJWuV8JsIxaexNdM3JU+iS3BNGFV6xQBnWp+Gb4uxegJI/TgiWr3VqTN9Mfj1eBrcH4MZ9+pQciC90nB5zxdNT157/5YvhVGjsOZ//kxTHOw03fRzN1S2zwjzB1FUWKNf3Dsk3voLMgpIAe9pn5wL/bBLIRG5IfTpXrrQ3AqPKCuBGWKbScjp5xcv25XhpTQ5cOAXLHWu4sCJzipy+FOAVfb15GNa/IBX3CIWFFCWE=" - OUTPUT_TYPE=Library script: - - ARTIFACT_NAME=${REPO_NAME}.${TAG_CLEAN} + - ARTIFACT_NAME=${REPO_NAME}.${TAG_CLEAN}$(if [[ ! -z $TAG_SUFFIX ]]; then echo $(echo $TAG_SUFFIX | sed -r 's/[^ab]\w+//'); fi) - dotnet pack -c Release /property:Version=${TAG_CLEAN} /property:OutputType=${OUTPUT_TYPE} before_deploy: - - echo '' >> nuget.config - - dotnet nuget add source "https://nuget.pkg.github.com/clarkx86/index.json" --configfile "nuget.config" -n "github" -u "clarkx86" -p "${GITHUB_TOKEN}" --store-password-in-clear-text + - cd bin/Release/ deploy: provider: script skip_cleanup: true - script: dotnet nuget push "bin/Release/${ARTIFACT_NAME}.nupkg" -s "github" + script: dotnet nuget push "${ARTIFACT_NAME}.nupkg" --api-key $API_KEY --source https://api.nuget.org/v3/index.json on: repo: clarkx86/vellum branch: master tags: true - after_script: - - rm -f nuget.config diff --git a/src/Automation/Watchdog.cs b/src/Automation/Watchdog.cs index d7838ba..a13cb69 100644 --- a/src/Automation/Watchdog.cs +++ b/src/Automation/Watchdog.cs @@ -8,6 +8,7 @@ public class Watchdog : InternalPlugin { public uint RetryLimit = 3; private uint _failRetryCount = 0; + private bool _enable = true; #region PLUGIN public Version Version { get; } @@ -25,7 +26,7 @@ public Watchdog(ProcessManager processManager) processManager.Process.EnableRaisingEvents = true; processManager.Process.Exited += (object sender, EventArgs e) => { - if (processManager.Process.ExitCode != 0) + if (processManager.Process.ExitCode != 0 && _enable) { CallHook((byte)Hook.CRASH, new HookEventArgs() { Attachment = processManager.Process.ExitCode }); @@ -53,5 +54,15 @@ public Watchdog(ProcessManager processManager) _failRetryCount = 0; }); } + + public void Disable() + { + _enable = false; + } + + public void Enable() + { + _enable = true; + } } } \ No newline at end of file diff --git a/src/Networking/UpdateChecker.cs b/src/Networking/UpdateChecker.cs index e39e5a1..cf1336f 100644 --- a/src/Networking/UpdateChecker.cs +++ b/src/Networking/UpdateChecker.cs @@ -156,5 +156,51 @@ public static Version ParseVersion(string version, VersionFormatting formatting) return formattedVersion; } + + ///Compares two versions with each other. + ///Returns -1 if the primary version is older than the secondary version, 0 if equal or 1 if newer. + public static short CompareVersions(Version primary, Version secondary, VersionFormatting formatting) + { + Version[] versions = new Version[] { primary, secondary }; + int[,] versionNumbers = new int[2, 4]; + + switch (formatting) + { + case VersionFormatting.MAJOR_MINOR_REVISION_BUILD: + versionNumbers = new int[2, 4] + { + { primary.Major, primary.Minor, primary.Revision, primary.Build }, + { secondary.Major, secondary.Minor, secondary.Revision, secondary.Build } + }; + break; + + case VersionFormatting.MAJOR_MINOR_BUILD_REVISION: + versionNumbers = new int[2, 4] + { + { primary.Major, primary.Minor, primary.Build, primary.Revision }, + { secondary.Major, secondary.Minor, secondary.Build, secondary.Revision } + }; + break; + + case VersionFormatting.MAJOR_MINOR_REVISION: + versionNumbers = new int[2, 3] + { + { primary.Major, primary.Minor, primary.Revision }, + { secondary.Major, secondary.Minor, secondary.Revision } + }; + break; + } + + // Compare versions + for (int i = 0; i < versionNumbers.GetLength(1); i++) + { + if (versionNumbers[0, i] < versionNumbers[1, i]) + return -1; + else if (versionNumbers[0, i] > versionNumbers[1, i]) + return 1; + } + + return 0; + } } } \ No newline at end of file diff --git a/src/Program.cs b/src/Program.cs index 187f0c0..b12ead1 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -30,7 +30,6 @@ public class VellumHost : Host private static UpdateChecker _updateChecker = new UpdateChecker(ReleaseProvider.GITHUB_RELEASES, @"https://api.github.com/repos/clarkx86/vellum/releases/latest", @"^v?(\d+)\.(\d+)\.(\d+)"); private static uint playerCount; private static Version _localVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; - private Version _bdsVersion = new Version(); public enum Hook { RELOAD_CONFIG, @@ -85,6 +84,8 @@ public VellumHost(string[] args) System.Environment.Exit(0); } + Version bdsVersion = new Version(); + if (File.Exists(_configPath)) { // Load configuration @@ -203,7 +204,7 @@ public VellumHost(string[] args) // Store current BDS version bds.RegisterMatchHandler(CommonRegex.Version, (object sender, MatchedEventArgs e) => { - _bdsVersion = UpdateChecker.ParseVersion(e.Matches[0].Groups[1].Value, VersionFormatting.MAJOR_MINOR_REVISION_BUILD); + bdsVersion = UpdateChecker.ParseVersion(e.Matches[0].Groups[1].Value, VersionFormatting.MAJOR_MINOR_REVISION_BUILD); }); playerCount = 0; @@ -249,7 +250,7 @@ public VellumHost(string[] args) foreach (IPlugin plugin in GetPlugins()) { if (plugin.PluginType == PluginType.EXTERNAL) - Console.WriteLine($"Loaded plugin \"{plugin.GetType().Name} v{UpdateChecker.ParseVersion(System.Reflection.Assembly.GetAssembly(plugin.GetType()).GetName().Version, VersionFormatting.MAJOR_MINOR_REVISION)}\""); + Console.WriteLine($"Loaded plugin: {plugin.GetType().Name} v{UpdateChecker.ParseVersion(System.Reflection.Assembly.GetAssembly(plugin.GetType()).GetName().Version, VersionFormatting.MAJOR_MINOR_REVISION)}"); } Console.WriteLine(); @@ -282,10 +283,10 @@ public VellumHost(string[] args) { if (nextBackup) { - InvokeBackup(worldPath, tempWorldPath); - if (RunConfig.Backups.OnActivityOnly && playerCount == 0) nextBackup = false; + + InvokeBackup(worldPath, tempWorldPath); } else Console.WriteLine("Skipping this backup because no players were online since the last one was taken..."); @@ -423,6 +424,7 @@ public VellumHost(string[] args) shutdownTimer.Elapsed += (object sender, ElapsedEventArgs e) => { // _renderManager.Abort(); + _bdsWatchdog.Disable(); bds.SendInput("stop"); bds.Process.WaitForExit(); bds.Close(); @@ -487,13 +489,13 @@ public VellumHost(string[] args) // BDS UpdateChecker bdsUpdateChecker = new UpdateChecker(ReleaseProvider.HTML, "https://minecraft.net/en-us/download/server/bedrock/", @"https:\/\/minecraft\.azureedge\.net\/bin-" + (System.Environment.OSVersion.Platform == PlatformID.Win32NT ? "win" : "linux") + @"\/bedrock-server-(\d+\.\d+\.\d+(?>\.\d+)?)\.zip"); if (bdsUpdateChecker.GetLatestVersion()) - Console.WriteLine(String.Format("Bedrock Server:\t{0} -> {1}\t({2})", UpdateChecker.ParseVersion(_bdsVersion, VersionFormatting.MAJOR_MINOR_REVISION_BUILD), UpdateChecker.ParseVersion(bdsUpdateChecker.RemoteVersion, VersionFormatting.MAJOR_MINOR_REVISION_BUILD), bdsUpdateChecker.RemoteVersion > _bdsVersion ? "outdated" : "up to date")); + Console.WriteLine(String.Format("Bedrock Server:\t{0} -> {1}\t({2})", UpdateChecker.ParseVersion(bdsVersion, VersionFormatting.MAJOR_MINOR_REVISION_BUILD), UpdateChecker.ParseVersion(bdsUpdateChecker.RemoteVersion, VersionFormatting.MAJOR_MINOR_REVISION_BUILD), UpdateChecker.CompareVersions(bdsVersion, bdsUpdateChecker.RemoteVersion, VersionFormatting.MAJOR_MINOR_REVISION_BUILD) < 0 ? "outdated" : "up to date")); else Console.WriteLine("Could not check for Bedrock server updates..."); // vellum if (_updateChecker.GetLatestVersion()) - Console.WriteLine(String.Format("vellum:\t\t{0} -> {1}\t({2})", UpdateChecker.ParseVersion(_localVersion, VersionFormatting.MAJOR_MINOR_REVISION), UpdateChecker.ParseVersion(_updateChecker.RemoteVersion, VersionFormatting.MAJOR_MINOR_REVISION), _updateChecker.RemoteVersion > _localVersion ? "outdated" : "up to date")); + Console.WriteLine(String.Format("vellum:\t\t{0} -> {1}\t({2})", UpdateChecker.ParseVersion(_localVersion, VersionFormatting.MAJOR_MINOR_REVISION), UpdateChecker.ParseVersion(_updateChecker.RemoteVersion, VersionFormatting.MAJOR_MINOR_REVISION), UpdateChecker.CompareVersions(_localVersion, _updateChecker.RemoteVersion, VersionFormatting.MAJOR_MINOR_REVISION) < 0 ? "outdated" : "up to date")); else Console.WriteLine("Could not check for vellum updates..."); diff --git a/src/vellum.csproj b/src/vellum.csproj index b409a97..3f5bef2 100644 --- a/src/vellum.csproj +++ b/src/vellum.csproj @@ -14,9 +14,7 @@ all - - all - +