Skip to content

Commit

Permalink
Add in-game notification for when the resource is outdated.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed Apr 30, 2018
1 parent 330d1dd commit ab87d35
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
18 changes: 16 additions & 2 deletions vMenu/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,11 +43,24 @@ public EventManager()
EventHandlers.Add("vMenu:SetupAddonWeapons", new Action<string, dynamic>(SetAddonModels));
EventHandlers.Add("vMenu:GoodBye", new Action(GoodBye));
EventHandlers.Add("vMenu:SetBanList", new Action<string>(UpdateBanList));
EventHandlers.Add("vMenu:OutdatedResource", new Action(NotifyOutdatedVersion));

Tick += WeatherSync;
Tick += TimeSync;
}

/// <summary>
/// Notifies the player that the current version of vMenu is outdated.
/// </summary>
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);

}

/// <summary>
/// Update ban list.
/// </summary>
Expand Down Expand Up @@ -267,15 +281,15 @@ private void SetTime(int newHours, int newMinutes, bool freezeTime)
/// <param name="reason"></param>
private void KickCallback(string reason)
{
MainMenu.Notify.Custom(reason, true, false);
Notify.Custom(reason, true, false);
}

/// <summary>
/// Kill this player, poor thing, someone wants you dead... R.I.P.
/// </summary>
private void KillMe()
{
MainMenu.Notify.Info("Someone wanted you dead.... Sorry.");
Notify.Info("Someone wanted you dead.... Sorry.");
SetEntityHealth(PlayerPedId(), 0);
}

Expand Down
10 changes: 9 additions & 1 deletion vMenuServer/MainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions vMenuServer/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace vMenuServer
public class UpdateChecker : BaseScript
{

public static bool CheckedForUpdates = false;

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -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/ !");
Expand All @@ -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;
}
}
}

0 comments on commit ab87d35

Please sign in to comment.