From fb53721d71d2ec83172ce8f544f6c7df406df316 Mon Sep 17 00:00:00 2001 From: telkar-rg Date: Mon, 21 Jul 2025 17:14:04 +0200 Subject: [PATCH] added "Func Call Spam Protection" for "BAG_UPDATE" Event in "DataStore_Mails" file --- .../DataStore_Mails/DataStore_Mails.lua | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Altoholic-Addon/DataStore_Mails/DataStore_Mails.lua b/Altoholic-Addon/DataStore_Mails/DataStore_Mails.lua index b3a940c..3d81a26 100644 --- a/Altoholic-Addon/DataStore_Mails/DataStore_Mails.lua +++ b/Altoholic-Addon/DataStore_Mails/DataStore_Mails.lua @@ -14,6 +14,9 @@ local THIS_ACCOUNT = "Default" local commPrefix = "DS_Mails" -- let's keep it a bit shorter than the addon name, this goes on a comm channel, a byte is a byte ffs :p local MAIL_EXPIRY = 30 -- Mails expire after 30 days +-- Func Call Spam Protection +local FCSP_timer_OnBagUpdate + -- Message types local MSG_SENDMAIL_INIT = 1 local MSG_SENDMAIL_END = 2 @@ -217,11 +220,28 @@ end -- *** Event Handlers *** local function OnBagUpdate(event, bag) + FCSP_timer_OnBagUpdate = nil -- manual reset (safety redundancy) + if addon.isOpen then -- if a bag is updated while the mailbox is opened, this means an attachment has been taken. + -- print("DataStore_Mails.lua -- OnBagUpdate(event, ",bag,")", DEBUG_CNT, format("%.3f",GetTime()%100)) -- DEBUG 2025 07 21 - 2 + ScanMailbox() -- I could not hook TakeInboxItem because mailbox content is not updated yet end end +local function FCSP_OnBagUpdate(event, bag) + -- this function limits calls to "OnBagUpdate" to max 1 every second + + if bag < 0 then + return + end + + if addon.isOpen then -- if a bag is updated while the mailbox is opened, this means an attachment has been taken. + if FCSP_timer_OnBagUpdate then return end + FCSP_timer_OnBagUpdate = addon:ScheduleTimer(OnBagUpdate, 1, event, bag) + end +end + local function OnMailInboxUpdate() -- process only one occurence of the event, right after MAIL_SHOW addon:UnregisterEvent("MAIL_INBOX_UPDATE") @@ -463,7 +483,8 @@ end function addon:OnEnable() addon:RegisterEvent("MAIL_SHOW", OnMailShow) - addon:RegisterEvent("BAG_UPDATE", OnBagUpdate) + -- addon:RegisterEvent("BAG_UPDATE", OnBagUpdate) + addon:RegisterEvent("BAG_UPDATE", FCSP_OnBagUpdate) addon:SetupOptions() if GetOption("CheckMailExpiry") == 1 then