From ab87d354ab18dc3727190e82e7dbab66f6c244a5 Mon Sep 17 00:00:00 2001 From: Vespura <31419184+TomGrobbe@users.noreply.github.com> Date: Mon, 30 Apr 2018 13:55:30 +0200 Subject: [PATCH] Add in-game notification for when the resource is outdated. --- vMenu/EventManager.cs | 18 ++++++++++++++++-- vMenuServer/MainServer.cs | 10 +++++++++- vMenuServer/UpdateChecker.cs | 7 +++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/vMenu/EventManager.cs b/vMenu/EventManager.cs index 15187bdb..152e8cbe 100644 --- a/vMenu/EventManager.cs +++ b/vMenu/EventManager.cs @@ -12,6 +12,7 @@ public class EventManager : BaseScript { // common functions. private CommonFunctions cf = MainMenu.Cf; + private Notification Notify = new Notification(); public static string currentWeatherType = "CLEAR"; public static bool blackoutMode = false; public static bool dynamicWeather = true; @@ -42,11 +43,24 @@ public EventManager() EventHandlers.Add("vMenu:SetupAddonWeapons", new Action(SetAddonModels)); EventHandlers.Add("vMenu:GoodBye", new Action(GoodBye)); EventHandlers.Add("vMenu:SetBanList", new Action(UpdateBanList)); + EventHandlers.Add("vMenu:OutdatedResource", new Action(NotifyOutdatedVersion)); Tick += WeatherSync; Tick += TimeSync; } + /// + /// Notifies the player that the current version of vMenu is outdated. + /// + private async void NotifyOutdatedVersion() + { + Debug.Write("vMenu is outdated, please update asap.\n"); + await Delay(5000); + cf.Log("Sending alert now."); + Notify.Alert("vMenu is outdated, if you are the server administrator, please update vMenu as soon as possible.", true, true); + + } + /// /// Update ban list. /// @@ -267,7 +281,7 @@ private void SetTime(int newHours, int newMinutes, bool freezeTime) /// private void KickCallback(string reason) { - MainMenu.Notify.Custom(reason, true, false); + Notify.Custom(reason, true, false); } /// @@ -275,7 +289,7 @@ private void KickCallback(string reason) /// private void KillMe() { - MainMenu.Notify.Info("Someone wanted you dead.... Sorry."); + Notify.Info("Someone wanted you dead.... Sorry."); SetEntityHealth(PlayerPedId(), 0); } diff --git a/vMenuServer/MainServer.cs b/vMenuServer/MainServer.cs index a9e65d33..c6fe04bc 100644 --- a/vMenuServer/MainServer.cs +++ b/vMenuServer/MainServer.cs @@ -13,6 +13,7 @@ namespace vMenuServer { public class MainServer : BaseScript { + public static bool UpToDate = true; // Debug shows more information when doing certain things. Leave it off to improve performance! public static bool DebugMode = GetResourceMetadata(GetCurrentResourceName(), "server_debug_mode", 0) == "true" ? true : false; @@ -656,7 +657,14 @@ private async void SendPermissionsAsync([FromSource] Player player) // Send Settings await Delay(50); TriggerClientEvent(player, "vMenu:SetOptions", options); - + while (!UpdateChecker.CheckedForUpdates) + { + await Delay(0); + } + if (!UpToDate) + { + TriggerClientEvent(player, "vMenu:OutdatedResource"); + } } private string GetRealAceName(string inputString) diff --git a/vMenuServer/UpdateChecker.cs b/vMenuServer/UpdateChecker.cs index 90329b1e..baa356fb 100644 --- a/vMenuServer/UpdateChecker.cs +++ b/vMenuServer/UpdateChecker.cs @@ -14,6 +14,8 @@ namespace vMenuServer public class UpdateChecker : BaseScript { + public static bool CheckedForUpdates = false; + /// /// Constructor /// @@ -50,15 +52,19 @@ private async void CheckUpdates() Debug.WriteLine($"[vMenu] Current version: {currentVersion}"); Debug.WriteLine($"[vMenu] Latest version: {version}"); Debug.WriteLine($"[vMenu] Release Date: {date}"); + // If up to date :) if (currentVersion == version) { // yay up to date! :) Snail is happy. Debug.WriteLine("\r\n[vMenu] You are currently using the latest version, good job!"); + } // If not up to date :( else { + MainServer.UpToDate = false; + // Snail is sad :( Debug.WriteLine("\r\n[vMenu] You are NOT using the latest version. Please update to the latest version as soon as possible."); Debug.WriteLine("[vMenu] Download the latest version here: https://github.com/tomgrobbe/vMenu/releases/ !"); @@ -77,6 +83,7 @@ private async void CheckUpdates() Debug.WriteLine("\r\n\r\n[vMenu] An error occurred while checking for updates. If you require immediate assistance email: contact@vespura.com."); Debug.WriteLine($"[vMenu] Error info: {e.Message.ToString()}\r\n\r\n"); } + CheckedForUpdates = true; } } }