From f9dd588e6a05c179b8ddd758f3f33f7c780d3fcc Mon Sep 17 00:00:00 2001
From: poco <107696090+poco8537@users.noreply.github.com>
Date: Tue, 10 Sep 2024 17:52:14 +0900
Subject: [PATCH 1/2] Add weather/cloud/time change security checks
---
vMenuServer/MainServer.cs | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/vMenuServer/MainServer.cs b/vMenuServer/MainServer.cs
index 9523c5992..d6069be13 100644
--- a/vMenuServer/MainServer.cs
+++ b/vMenuServer/MainServer.cs
@@ -660,8 +660,13 @@ private void RefreshWeather()
///
///
[EventHandler("vMenu:UpdateServerWeather")]
- internal void UpdateWeather(string newWeather, bool blackoutNew, bool dynamicWeatherNew, bool enableSnow)
+ internal void UpdateWeather([FromSource] Player source, string newWeather, bool blackoutNew, bool dynamicWeatherNew, bool enableSnow)
{
+ if (source != null && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.Menu") && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.All"))
+ {
+ BanManager.BanCheater(source);
+ return;
+ }
// Automatically enable snow effects whenever one of the snow weather types is selected.
if (newWeather is "XMAS" or "SNOWLIGHT" or "SNOW" or "BLIZZARD")
@@ -684,8 +689,14 @@ internal void UpdateWeather(string newWeather, bool blackoutNew, bool dynamicWea
///
///
[EventHandler("vMenu:UpdateServerWeatherCloudsType")]
- internal void UpdateWeatherCloudsType(bool removeClouds)
+ internal void UpdateWeatherCloudsType([FromSource] Player source, bool removeClouds)
{
+ if (source != null && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.RemoveClouds") && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.RandomizeClouds"))
+ {
+ BanManager.BanCheater(source);
+ return;
+ }
+
if (removeClouds)
{
TriggerClientEvent("vMenu:SetClouds", 0f, "removed");
@@ -705,8 +716,14 @@ internal void UpdateWeatherCloudsType(bool removeClouds)
///
///
[EventHandler("vMenu:UpdateServerTime")]
- internal void UpdateTime(int newHours, int newMinutes, bool freezeTimeNew)
+ internal void UpdateTime([FromSource] Player source, int newHours, int newMinutes, bool freezeTimeNew)
{
+ if (source != null && !IsPlayerAceAllowed(source.Handle, "vMenu.TimeOptions.Menu") && !IsPlayerAceAllowed(source.Handle, "vMenu.TimeOptions.All"))
+ {
+ BanManager.BanCheater(source);
+ return;
+ }
+
CurrentHours = newHours;
CurrentMinutes = newMinutes;
FreezeTime = freezeTimeNew;
From 555bea81309a63df4ae8cf14fe8b66f2f9f57211 Mon Sep 17 00:00:00 2001
From: "Christopher M."
Date: Sat, 20 Sep 2025 15:20:08 +1000
Subject: [PATCH 2/2] Refactors weather & time perms check to use
PermissionsManager.IsAllowed
What was here and written by poco8537 was bang on the money, but could be simplified by using the existing `PermissionsManager` class and it's existing funcs and enums - which is what this commit refactors.
Also adds a missing permission check for randomizing clouds, and an explicit check for setting time (versus simply having access to the time menu).
---
vMenuServer/MainServer.cs | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/vMenuServer/MainServer.cs b/vMenuServer/MainServer.cs
index d6069be13..91d657eb0 100644
--- a/vMenuServer/MainServer.cs
+++ b/vMenuServer/MainServer.cs
@@ -662,7 +662,7 @@ private void RefreshWeather()
[EventHandler("vMenu:UpdateServerWeather")]
internal void UpdateWeather([FromSource] Player source, string newWeather, bool blackoutNew, bool dynamicWeatherNew, bool enableSnow)
{
- if (source != null && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.Menu") && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.All"))
+ if (!PermissionsManager.IsAllowed(PermissionsManager.Permission.WOSetWeather, source) && !PermissionsManager.IsAllowed(PermissionsManager.Permission.WOAll, source))
{
BanManager.BanCheater(source);
return;
@@ -691,18 +691,26 @@ internal void UpdateWeather([FromSource] Player source, string newWeather, bool
[EventHandler("vMenu:UpdateServerWeatherCloudsType")]
internal void UpdateWeatherCloudsType([FromSource] Player source, bool removeClouds)
{
- if (source != null && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.RemoveClouds") && !IsPlayerAceAllowed(source.Handle, "vMenu.WeatherOptions.RandomizeClouds"))
- {
- BanManager.BanCheater(source);
- return;
- }
+ bool allWOPermissions = PermissionsManager.IsAllowed(PermissionsManager.Permission.WOAll, source);
if (removeClouds)
{
+ if (!PermissionsManager.IsAllowed(PermissionsManager.Permission.WORemoveClouds, source) && !allWOPermissions)
+ {
+ BanManager.BanCheater(source);
+ return;
+ }
+
TriggerClientEvent("vMenu:SetClouds", 0f, "removed");
}
else
{
+ if (!PermissionsManager.IsAllowed(PermissionsManager.Permission.WORandomizeClouds, source) && !allWOPermissions)
+ {
+ BanManager.BanCheater(source);
+ return;
+ }
+
var opacity = float.Parse(new Random().NextDouble().ToString());
var type = CloudTypes[new Random().Next(0, CloudTypes.Count)];
TriggerClientEvent("vMenu:SetClouds", opacity, type);
@@ -718,12 +726,25 @@ internal void UpdateWeatherCloudsType([FromSource] Player source, bool removeClo
[EventHandler("vMenu:UpdateServerTime")]
internal void UpdateTime([FromSource] Player source, int newHours, int newMinutes, bool freezeTimeNew)
{
- if (source != null && !IsPlayerAceAllowed(source.Handle, "vMenu.TimeOptions.Menu") && !IsPlayerAceAllowed(source.Handle, "vMenu.TimeOptions.All"))
+ bool allTOPermissions = PermissionsManager.IsAllowed(PermissionsManager.Permission.TOSetTime, source);
+
+ if (!PermissionsManager.IsAllowed(PermissionsManager.Permission.TOSetTime, source) && !allTOPermissions)
{
BanManager.BanCheater(source);
return;
}
+ // Chris: This logic is inherently problematic, as players WITHOUT `TOFreezeTime` can still *un*freeze time, even if they can't freeze time
+ // TODO: Move time freezing to separate event, so `TOFreezeTime` can be checked regardless of the boolean value?
+ if (freezeTimeNew)
+ {
+ if (!PermissionsManager.IsAllowed(PermissionsManager.Permission.TOFreezeTime, source) && !allTOPermissions)
+ {
+ BanManager.BanCheater(source);
+ return;
+ }
+ }
+
CurrentHours = newHours;
CurrentMinutes = newMinutes;
FreezeTime = freezeTimeNew;