From 89a7da0bc8d13bc93d42b47d945d750e56e7d568 Mon Sep 17 00:00:00 2001 From: Erik Minekus Date: Wed, 29 Jul 2020 09:00:00 +0200 Subject: [PATCH] Clean up --- addons/sourcemod/scripting/advertisements.sp | 50 +++++++++---------- .../sourcemod/scripting/include/updater.inc | 22 ++++---- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/addons/sourcemod/scripting/advertisements.sp b/addons/sourcemod/scripting/advertisements.sp index d604dca..5ba62c5 100644 --- a/addons/sourcemod/scripting/advertisements.sp +++ b/addons/sourcemod/scripting/advertisements.sp @@ -7,7 +7,7 @@ #pragma newdecls required #pragma semicolon 1 -#define PL_VERSION "2.0.3" +#define PL_VERSION "2.0.4" #define UPDATE_URL "http://ErikMinekus.github.io/sm-advertisements/update.txt" public Plugin myinfo = @@ -53,11 +53,10 @@ public void OnPluginStart() } } -public void OnMapStart() +public void OnConfigsExecuted() { ParseAds(); - - g_hTimer = CreateTimer(g_hInterval.IntValue * 1.0, Timer_DisplayAd, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); + RestartTimer(); } public void OnLibraryAdded(const char[] name) @@ -74,11 +73,7 @@ public void ConVarChange_File(ConVar convar, const char[] oldValue, const char[] public void ConVarChange_Interval(ConVar convar, const char[] oldValue, const char[] newValue) { - if (g_hTimer) { - KillTimer(g_hTimer); - } - - g_hTimer = CreateTimer(g_hInterval.IntValue * 1.0, Timer_DisplayAd, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); + RestartTimer(); } @@ -107,7 +102,7 @@ public Action Timer_DisplayAd(Handle timer) return; } - char sCenter[1024], sChat[1024], sHint[1024], sMenu[1024], sTop[1024], sFlags[16]; + char sCenter[1024], sChat[1024], sHint[1024], sMenu[1024], sTop[1024], sFlags[22]; g_hAdvertisements.GetString("center", sCenter, sizeof(sCenter)); g_hAdvertisements.GetString("chat", sChat, sizeof(sChat)); g_hAdvertisements.GetString("hint", sHint, sizeof(sHint)); @@ -122,9 +117,7 @@ public Action Timer_DisplayAd(Handle timer) ProcessVariables(sCenter); for (int i = 1; i <= MaxClients; i++) { - if (IsClientInGame(i) && !IsFakeClient(i) && - ((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) || - (bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) { + if (IsValidClient(i, bAdmins, bFlags, iFlags)) { PrintCenterText(i, sCenter); DataPack hCenterAd; @@ -138,9 +131,7 @@ public Action Timer_DisplayAd(Handle timer) ProcessVariables(sHint); for (int i = 1; i <= MaxClients; i++) { - if (IsClientInGame(i) && !IsFakeClient(i) && - ((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) || - (bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) { + if (IsValidClient(i, bAdmins, bFlags, iFlags)) { PrintHintText(i, sHint); } } @@ -153,9 +144,7 @@ public Action Timer_DisplayAd(Handle timer) hPl.CurrentKey = 10; for (int i = 1; i <= MaxClients; i++) { - if (IsClientInGame(i) && !IsFakeClient(i) && - ((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) || - (bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) { + if (IsValidClient(i, bAdmins, bFlags, iFlags)) { hPl.Send(i, Handler_DoNothing, 10); } } @@ -170,9 +159,7 @@ public Action Timer_DisplayAd(Handle timer) ProcessVariables(sBuffer); for (int i = 1; i <= MaxClients; i++) { - if (IsClientInGame(i) && !IsFakeClient(i) && - ((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) || - (bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) { + if (IsValidClient(i, bAdmins, bFlags, iFlags)) { if (bTeamColor) { SayText2(i, sBuffer); } else { @@ -194,9 +181,7 @@ public Action Timer_DisplayAd(Handle timer) hKv.SetNum("time", 10); for (int i = 1; i <= MaxClients; i++) { - if (IsClientInGame(i) && !IsFakeClient(i) && - ((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) || - (bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) { + if (IsValidClient(i, bAdmins, bFlags, iFlags)) { CreateDialog(i, hKv, DialogType_Msg); } } @@ -232,6 +217,13 @@ public Action Timer_CenterAd(Handle timer, DataPack pack) /** * Stocks */ +bool IsValidClient(int iClient, bool bAdmins, bool bFlags, int iFlags) +{ + return IsClientInGame(iClient) && !IsFakeClient(iClient) + && ((!bAdmins && !(bFlags && CheckCommandAccess(iClient, "Advertisements", iFlags))) + || (bAdmins && CheckCommandAccess(iClient, "Advertisements", ADMFLAG_GENERIC))); +} + void ParseAds() { delete g_hAdvertisements; @@ -285,7 +277,7 @@ void ProcessVariables(char sText[1024]) } ConVar hConVar; - char sConVar[64], sSearch[64], sReplace[64]; + char sConVar[64], sSearch[64], sReplace[256]; int iEnd = -1, iStart = StrContains(sText, "{"), iStart2; while (iStart != -1) { iEnd = StrContains(sText[iStart + 1], "}"); @@ -309,3 +301,9 @@ void ProcessVariables(char sText[1024]) iStart += iStart2 + 1; } } + +void RestartTimer() +{ + delete g_hTimer; + g_hTimer = CreateTimer(float(g_hInterval.IntValue), Timer_DisplayAd, _, TIMER_REPEAT); +} diff --git a/addons/sourcemod/scripting/include/updater.inc b/addons/sourcemod/scripting/include/updater.inc index 1da709d..bd1b53c 100644 --- a/addons/sourcemod/scripting/include/updater.inc +++ b/addons/sourcemod/scripting/include/updater.inc @@ -10,7 +10,7 @@ * @param url URL to your plugin's update file. * @noreturn */ -native Updater_AddPlugin(const String:url[]); +native void Updater_AddPlugin(const char[] url); /** * Removes your plugin from the updater. This does not need to @@ -18,7 +18,7 @@ native Updater_AddPlugin(const String:url[]); * * @noreturn */ -native Updater_RemovePlugin(); +native void Updater_RemovePlugin(); /** * Forces your plugin to be checked for updates. The behaviour @@ -27,21 +27,21 @@ native Updater_RemovePlugin(); * @return True if an update was triggered. False otherwise. * @error Plugin not found in updater. */ -native bool:Updater_ForceUpdate(); +native bool Updater_ForceUpdate(); /** * Called when your plugin is about to be checked for updates. * * @return Plugin_Handled to prevent checking, Plugin_Continue to allow it. */ -forward Action:Updater_OnPluginChecking(); +forward Action Updater_OnPluginChecking(); /** * Called when your plugin is about to begin downloading an available update. * * @return Plugin_Handled to prevent downloading, Plugin_Continue to allow it. */ -forward Action:Updater_OnPluginDownloading(); +forward Action Updater_OnPluginDownloading(); /** * Called when your plugin's update files have been fully downloaded @@ -52,7 +52,7 @@ forward Action:Updater_OnPluginDownloading(); * * @noreturn */ -forward Updater_OnPluginUpdating(); +forward void Updater_OnPluginUpdating(); /** * Called when your plugin's update has been completed. It is safe @@ -60,7 +60,7 @@ forward Updater_OnPluginUpdating(); * * @noreturn */ -forward Updater_OnPluginUpdated(); +forward void Updater_OnPluginUpdated(); /** * @brief Reloads a plugin. @@ -68,15 +68,15 @@ forward Updater_OnPluginUpdated(); * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin). * @noreturn */ -stock ReloadPlugin(Handle:plugin=INVALID_HANDLE) +stock void ReloadPlugin(Handle plugin = INVALID_HANDLE) { - decl String:filename[64]; + char filename[64]; GetPluginFilename(plugin, filename, sizeof(filename)); ServerCommand("sm plugins reload %s", filename); } -public SharedPlugin:__pl_updater = +public SharedPlugin __pl_updater = { name = "updater", file = "updater.smx", @@ -88,7 +88,7 @@ public SharedPlugin:__pl_updater = }; #if !defined REQUIRE_PLUGIN -public __pl_updater_SetNTVOptional() +public void __pl_updater_SetNTVOptional() { MarkNativeAsOptional("Updater_AddPlugin"); MarkNativeAsOptional("Updater_RemovePlugin");