From 9b34b07a00d1769bdcffafd15bddb114d1750a5f Mon Sep 17 00:00:00 2001 From: jenz Date: Tue, 7 Jun 2022 21:45:16 +0200 Subject: [PATCH] updated by adding a timer to check so new clients connecting wont be missed to get blocked --- SprayManager/scripting/SprayManager.sp | 220 ++++++++++++++----------- 1 file changed, 122 insertions(+), 98 deletions(-) diff --git a/SprayManager/scripting/SprayManager.sp b/SprayManager/scripting/SprayManager.sp index d89f8b0..10739c6 100644 --- a/SprayManager/scripting/SprayManager.sp +++ b/SprayManager/scripting/SprayManager.sp @@ -24,6 +24,7 @@ enum Handle g_hDatabase = null; Handle g_hTraceTimer = null; +Handle g_hHideSpray = null; Handle g_hRoundEndTimer = null; Handle g_hTopMenu = null; Handle g_hWantsToSeeNSFWCookie = null; @@ -97,113 +98,117 @@ public APLRes AskPluginLoad2(Handle hThis, bool bLate, char[] err, int iErrLen) public void OnPluginStart() { - LoadTranslations("common.phrases"); + LoadTranslations("common.phrases"); - AddFileToDownloadsTable("materials/decals/spraymanager/1.vtf"); - AddFileToDownloadsTable("materials/decals/spraymanager/1.vmt"); + AddFileToDownloadsTable("materials/decals/spraymanager/1.vtf"); + AddFileToDownloadsTable("materials/decals/spraymanager/1.vmt"); - AddFileToDownloadsTable("materials/decals/spraymanager/2.vtf"); - AddFileToDownloadsTable("materials/decals/spraymanager/2.vmt"); + AddFileToDownloadsTable("materials/decals/spraymanager/2.vtf"); + AddFileToDownloadsTable("materials/decals/spraymanager/2.vmt"); - AddFileToDownloadsTable("materials/decals/spraymanager/3.vtf"); - AddFileToDownloadsTable("materials/decals/spraymanager/3.vmt"); + AddFileToDownloadsTable("materials/decals/spraymanager/3.vtf"); + AddFileToDownloadsTable("materials/decals/spraymanager/3.vmt"); - RegConsoleCmd("sm_marknsfw", Command_MarkNSFW, "Marks your spray as NSFW"); - RegConsoleCmd("sm_marksfw", Command_MarkSFW, "Marks your spray as SFW"); - RegConsoleCmd("sm_nsfw", Command_NSFW, "Opt-in or out of seeing NSFW sprays"); - RegConsoleCmd("sm_hs", Command_HideSpray, "Hides a players spray"); - RegConsoleCmd("sm_us", Command_UnhideSpray, "Unhides a players spray"); + RegConsoleCmd("sm_marknsfw", Command_MarkNSFW, "Marks your spray as NSFW"); + RegConsoleCmd("sm_marksfw", Command_MarkSFW, "Marks your spray as SFW"); + RegConsoleCmd("sm_nsfw", Command_NSFW, "Opt-in or out of seeing NSFW sprays"); + RegConsoleCmd("sm_hs", Command_HideSpray, "Hides a players spray"); + RegConsoleCmd("sm_us", Command_UnhideSpray, "Unhides a players spray"); - RegAdminCmd("sm_spray", Command_AdminSpray, ADMFLAG_GENERIC, "Spray a clients spray"); - RegAdminCmd("sm_sprayban", Command_SprayBan, ADMFLAG_GENERIC, "Ban a client from spraying"); - RegAdminCmd("sm_sprayunban", Command_SprayUnban, ADMFLAG_GENERIC, "Unban a client and allow them to spray"); - RegAdminCmd("sm_banspray", Command_BanSpray, ADMFLAG_GENERIC, "Ban a clients spray from being sprayed (Note: This will not spray-ban the client, it will only ban the spray which they are currently using)"); - RegAdminCmd("sm_unbanspray", Command_UnbanSpray, ADMFLAG_GENERIC, "Unban a clients spray (Note: This will not spray-unban the client, it will only unban the spray which they are currently using)"); - RegAdminCmd("sm_tracespray", Command_TraceSpray, ADMFLAG_GENERIC, "Finds a spray under your crosshair"); - RegAdminCmd("sm_spraytrace", Command_TraceSpray, ADMFLAG_GENERIC, "Finds a spray under your crosshair"); - RegAdminCmd("sm_removespray", Command_RemoveSpray, ADMFLAG_GENERIC, "Finds and removes a spray under your crosshair"); - RegAdminCmd("sm_forcensfw", Command_ForceNSFW, ADMFLAG_GENERIC, "Forces a spray to be marked NSFW"); - RegAdminCmd("sm_forcesfw", Command_ForceSFW, ADMFLAG_GENERIC, "Forces a spray to be marked SFW"); - RegAdminCmd("sm_spraymanagerupdatedb", Command_SprayManager_UpdateInfo, ADMFLAG_CHEATS, "Updates all clients info"); - RegAdminCmd("sm_spraymanagerrefreshdb", Command_SprayManager_UpdateInfo, ADMFLAG_CHEATS, "Updates all clients info"); - RegAdminCmd("sm_spraymanagerreloaddb", Command_SprayManager_UpdateInfo, ADMFLAG_CHEATS, "Updates all clients info"); + RegAdminCmd("sm_spray", Command_AdminSpray, ADMFLAG_GENERIC, "Spray a clients spray"); + RegAdminCmd("sm_sprayban", Command_SprayBan, ADMFLAG_GENERIC, "Ban a client from spraying"); + RegAdminCmd("sm_sprayunban", Command_SprayUnban, ADMFLAG_GENERIC, "Unban a client and allow them to spray"); + RegAdminCmd("sm_banspray", Command_BanSpray, ADMFLAG_GENERIC, "Ban a clients spray from being sprayed (Note: This will not spray-ban the client, it will only ban the spray which they are currently using)"); + RegAdminCmd("sm_unbanspray", Command_UnbanSpray, ADMFLAG_GENERIC, "Unban a clients spray (Note: This will not spray-unban the client, it will only unban the spray which they are currently using)"); + RegAdminCmd("sm_tracespray", Command_TraceSpray, ADMFLAG_GENERIC, "Finds a spray under your crosshair"); + RegAdminCmd("sm_spraytrace", Command_TraceSpray, ADMFLAG_GENERIC, "Finds a spray under your crosshair"); + RegAdminCmd("sm_removespray", Command_RemoveSpray, ADMFLAG_GENERIC, "Finds and removes a spray under your crosshair"); + RegAdminCmd("sm_forcensfw", Command_ForceNSFW, ADMFLAG_GENERIC, "Forces a spray to be marked NSFW"); + RegAdminCmd("sm_forcesfw", Command_ForceSFW, ADMFLAG_GENERIC, "Forces a spray to be marked SFW"); + RegAdminCmd("sm_spraymanagerupdatedb", Command_SprayManager_UpdateInfo, ADMFLAG_CHEATS, "Updates all clients info"); + RegAdminCmd("sm_spraymanagerrefreshdb", Command_SprayManager_UpdateInfo, ADMFLAG_CHEATS, "Updates all clients info"); + RegAdminCmd("sm_spraymanagerreloaddb", Command_SprayManager_UpdateInfo, ADMFLAG_CHEATS, "Updates all clients info"); - g_hWantsToSeeNSFWCookie = RegClientCookie("spraymanager_wanttoseensfw", "Does this client want to see NSFW sprays?", CookieAccess_Private); + g_hWantsToSeeNSFWCookie = RegClientCookie("spraymanager_wanttoseensfw", "Does this client want to see NSFW sprays?", CookieAccess_Private); - AddTempEntHook("Player Decal", HookDecal); - AddNormalSoundHook(HookSprayer); + AddTempEntHook("Player Decal", HookDecal); + AddNormalSoundHook(HookSprayer); - TopMenu hTopMenu; + TopMenu hTopMenu; - if (LibraryExists("adminmenu") && ((hTopMenu = GetAdminTopMenu()) != null)) - OnAdminMenuReady(hTopMenu); + if (LibraryExists("adminmenu") && ((hTopMenu = GetAdminTopMenu()) != null)) + OnAdminMenuReady(hTopMenu); - g_cvarHookedDecalFrequency = FindConVar("decalfrequency"); - g_iOldDecalFreqVal = g_cvarHookedDecalFrequency.IntValue; - g_cvarHookedDecalFrequency.IntValue = 0; + g_cvarHookedDecalFrequency = FindConVar("decalfrequency"); + g_iOldDecalFreqVal = g_cvarHookedDecalFrequency.IntValue; + g_cvarHookedDecalFrequency.IntValue = 0; - g_cvarDecalFrequency = CreateConVar("sm_decalfrequency", "10.0", "Controls how often clients can spray", FCVAR_NOTIFY); + g_cvarDecalFrequency = CreateConVar("sm_decalfrequency", "10.0", "Controls how often clients can spray", FCVAR_NOTIFY); - HookConVarChange(g_cvarHookedDecalFrequency, ConVarChanged_DecalFrequency); + HookConVarChange(g_cvarHookedDecalFrequency, ConVarChanged_DecalFrequency); - g_cvarUseProximityCheck = CreateConVar("sm_spraymanager_blockoverspraying", "1", "Blocks people from overspraying each other", FCVAR_NOTIFY); + g_cvarUseProximityCheck = CreateConVar("sm_spraymanager_blockoverspraying", "1", "Blocks people from overspraying each other", FCVAR_NOTIFY); - g_cvarSendSpraysToConnectingClients = CreateConVar("sm_spraymanager_sendspraystoconnectingclients", "1", "Try to send active sprays to connecting clients"); + g_cvarSendSpraysToConnectingClients = CreateConVar("sm_spraymanager_sendspraystoconnectingclients", "1", "Try to send active sprays to connecting clients"); - g_cvarUsePersistentSprays = CreateConVar("sm_spraymanager_persistentsprays", "1", "Re-spray sprays when their client-sided lifetime (in rounds) expires"); + g_cvarUsePersistentSprays = CreateConVar("sm_spraymanager_persistentsprays", "1", "Re-spray sprays when their client-sided lifetime (in rounds) expires"); - g_cvarMaxSprayLifetime = CreateConVar("sm_spraymanager_maxspraylifetime", "2", "If not using persistent sprays, remove sprays after their global lifetime (in rounds) exceeds this number"); + g_cvarMaxSprayLifetime = CreateConVar("sm_spraymanager_maxspraylifetime", "2", "If not using persistent sprays, remove sprays after their global lifetime (in rounds) exceeds this number"); - AutoExecConfig(true, "plugin.SprayManager"); + AutoExecConfig(true, "plugin.SprayManager"); - g_hTraceTimer = CreateTimer(0.25, Timer_PerformPlayerTraces, _, TIMER_REPEAT); + g_hTraceTimer = CreateTimer(0.25, Timer_PerformPlayerTraces, _, TIMER_REPEAT); + g_hHideSpray = CreateTimer(4.0, Timer_UpdateHideSprays, _, TIMER_REPEAT); - if (g_bLoadedLate) - { - for (int i = 1; i <= MaxClients; i++) - { - if (!IsClientInGame(i) || IsFakeClient(i)) - continue; + if (g_bLoadedLate) + { + for (int i = 1; i <= MaxClients; i++) + { + if (!IsClientInGame(i) || IsFakeClient(i)) + continue; - OnClientPutInServer(i); - OnClientCookiesCached(i); - } - } + OnClientPutInServer(i); + OnClientCookiesCached(i); + } + } - InitializeSQL(); + InitializeSQL(); } public void OnPluginEnd() { - for (int i = 1; i <= MaxClients; i++) - { - if (!IsValidClient(i) || IsFakeClient(i)) - continue; + for (int i = 1; i <= MaxClients; i++) + { + if (!IsValidClient(i) || IsFakeClient(i)) + continue; - if (IsVectorZero(g_vecSprayOrigin[i])) - continue; + if (IsVectorZero(g_vecSprayOrigin[i])) + continue; - g_iAllowSpray = i; - SprayClientDecalToAll(i, 0, ACTUAL_NULL_VECTOR); - } + g_iAllowSpray = i; + SprayClientDecalToAll(i, 0, ACTUAL_NULL_VECTOR); + } - RemoveTempEntHook("Player Decal", HookDecal); - RemoveNormalSoundHook(HookSprayer); - UnhookConVarChange(g_cvarHookedDecalFrequency, ConVarChanged_DecalFrequency); + RemoveTempEntHook("Player Decal", HookDecal); + RemoveNormalSoundHook(HookSprayer); + UnhookConVarChange(g_cvarHookedDecalFrequency, ConVarChanged_DecalFrequency); - if (g_hDatabase != null) - { - SQL_UnlockDatabase(g_hDatabase); - delete g_hDatabase; - } + if (g_hDatabase != null) + { + SQL_UnlockDatabase(g_hDatabase); + delete g_hDatabase; + } - if (g_hTraceTimer != null) - delete g_hTraceTimer; + if (g_hTraceTimer != null) + delete g_hTraceTimer; - if (g_hRoundEndTimer != null) - delete g_hRoundEndTimer; + if (g_hHideSpray != null) + delete g_hHideSpray; - g_cvarHookedDecalFrequency.IntValue = g_iOldDecalFreqVal; + if (g_hRoundEndTimer != null) + delete g_hRoundEndTimer; + + g_cvarHookedDecalFrequency.IntValue = g_iOldDecalFreqVal; } public void OnMapStart() @@ -256,6 +261,7 @@ public void select_sprays_to_hide(Handle hParent, Handle hChild, const char[] er LogError("failed selecting hidden sprays (%s)", err); return; } + while (SQL_FetchRow(hChild)) { char sAuthID[32]; @@ -266,6 +272,10 @@ public void select_sprays_to_hide(Handle hParent, Handle hChild, const char[] er continue; char sAuthID_target[32]; GetClientAuthId(i, AuthId_Steam2, sAuthID_target, sizeof(sAuthID_target), false); + if (StrContains(sAuthID_target, "STEAM_0") == -1 && StrContains(sAuthID_target, "STEAM_1") == -1) + { + continue; + } if (StrEqual(sAuthID, sAuthID_target)) { g_bHasSprayHidden[client][i] = true; @@ -273,6 +283,7 @@ public void select_sprays_to_hide(Handle hParent, Handle hChild, const char[] er g_bSkipDecalHook = true; SprayClientDecalToOne(i, client, 0, ACTUAL_NULL_VECTOR); g_bSkipDecalHook = false; + break; } } } @@ -287,13 +298,6 @@ public void OnClientPostAdminCheck(int client) UpdatePlayerInfo(client); UpdateSprayHashInfo(client); UpdateNSFWInfo(client); - - char sAuthID[32]; - GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false); - char sQuery[512]; - Format(sQuery, sizeof(sQuery), "SELECT `steamidtarget` FROM `sprayhidemanage` WHERE `steamidhider` = '%s';", sAuthID); - - SQL_TQuery(g_hDatabase, select_sprays_to_hide, sQuery, client, DBPrio_High); } if (g_cvarSendSpraysToConnectingClients.BoolValue) @@ -322,25 +326,25 @@ public void OnClientPostAdminCheck(int client) public void OnClientDisconnect(int client) { - if (IsValidClient(client)) - { - for (int i = 1; i <= MaxClients; i++) - { - if (!IsValidClient(i)) - continue; + if (IsValidClient(client)) + { + for (int i = 1; i <= MaxClients; i++) + { + if (!IsValidClient(i)) + continue; - if (!g_bHasSprayHidden[i][client] && g_bWantsToSeeNSFWSprays[i]) - continue; + if (!g_bHasSprayHidden[i][client] && g_bWantsToSeeNSFWSprays[i]) + continue; - PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[client], i); - } + PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[client], i); + } - g_bSkipDecalHook = true; - SprayClientDecalToAll(client, 0, ACTUAL_NULL_VECTOR); - g_bSkipDecalHook = false; - } + g_bSkipDecalHook = true; + SprayClientDecalToAll(client, 0, ACTUAL_NULL_VECTOR); + g_bSkipDecalHook = false; + } - ClearPlayerInfo(client); + ClearPlayerInfo(client); } public Action CS_OnTerminateRound(float &fDelay, CSRoundEndReason &reason) @@ -2251,7 +2255,7 @@ public Action HookDecal(const char[] sTEName, const int[] iClients, int iNumClie if (CheckCommandAccess(i, "", ADMFLAG_CUSTOM1, true) || CheckCommandAccess(i, "sm_sprayban", ADMFLAG_GENERIC)) { - PrintToChat(client, "\x01\x04[SprayManager]\x01 Your spray is too close to \x04%N\x01's spray.", i); + PrintToChat(client, "\x01\x04[SprayManager]\x01 Your spray is too close to \x04%N\x01's spray.", i); //' return Plugin_Handled; } @@ -2341,6 +2345,26 @@ public Action HookSprayer(int iClients[MAXPLAYERS], int &iNumClients, char sSoun return Plugin_Continue; } +public Action Timer_UpdateHideSprays(Handle hTimer) +{ + for (int client = 1; client <= MaxClients; client++) + { + if (!IsValidClient(client) || IsFakeClient(client)) + continue; + + char sAuthID[32]; + GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false); + if (StrContains(sAuthID, "STEAM_0") == -1 && StrContains(sAuthID, "STEAM_1") == -1) + { + continue; + } + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT `steamidtarget` FROM `sprayhidemanage` WHERE `steamidhider` = '%s';", sAuthID); + SQL_TQuery(g_hDatabase, select_sprays_to_hide, sQuery, client, DBPrio_High); + } +} + public Action Timer_PerformPlayerTraces(Handle hTimer) { static bool bLookingatSpray[MAXPLAYERS + 1];