From d182cc14188d2bb12d20e08da164d49cfb50a824 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 8 Jan 2025 17:17:08 +0100 Subject: [PATCH] Implement sniffer --- Modules/Sniffer.lua | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Modules/Sniffer.lua diff --git a/Modules/Sniffer.lua b/Modules/Sniffer.lua new file mode 100644 index 0000000..317dc98 --- /dev/null +++ b/Modules/Sniffer.lua @@ -0,0 +1,84 @@ +local addonname, shared = ... +---@cast shared HeimdallShared +---@cast addonname string +local ModuleName = "Sniffer" + +---@diagnostic disable-next-line: missing-fields +shared.Sniffer = {} +function shared.Sniffer.Init() + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Module initializing", ModuleName)) + end + local smellThrottle = {} + local SmellStinky = function(stinky) + if Heimdall_Data.config.sniffer.debug then + print(string.format("%s: SmellStinky", ModuleName)) + shared.dumpTable(Heimdall_Data.config.sniffer) + end + if not Heimdall_Data.config.sniffer.enabled then return end + if Heimdall_Data.config.sniffer.stinky and + not Heimdall_Data.config.stinkies[stinky] then + if Heimdall_Data.config.sniffer.debug then + print(string.format("%s: Stinky not found in config", ModuleName)) + end + return + end + if smellThrottle[stinky] and GetTime() - smellThrottle[stinky] < Heimdall_Data.config.sniffer.throttleTime then + if Heimdall_Data.config.sniffer.debug then + print(string.format("%s: Throttled", ModuleName)) + end + return + end + smellThrottle[stinky] = GetTime() + local msg = { + channel = "CHANNEL", + data = Heimdall_Data.config.deathReporter.notifyChannel, + message = string.format("I smell a stinky %s", stinky), + } + if Heimdall_Data.config.sniffer.debug then + print(string.format("%s: Inserting message into queue", ModuleName)) + shared.dumpTable(msg) + end + table.insert(shared.messenger.queue, msg) + end + + local cleuFrame = CreateFrame("Frame") + cleuFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") + cleuFrame:SetScript("OnEvent", function(self, event, ...) + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Received event: %s", ModuleName, event)) + end + if not Heimdall_Data.config.sniffer.enabled then + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Module disabled, ignoring event", ModuleName)) + end + return + end + local source, err = CLEUParser.GetSourceName(...) + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Processing source: %s", ModuleName, source)) + end + if err then + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Error parsing source: %s", ModuleName, err)) + end + return + end + SmellStinky(source) + local destination, err = CLEUParser.GetDestName(...) + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Processing destination: %s", ModuleName, destination)) + end + if err then + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Error parsing destination: %s", ModuleName, err)) + end + return + end + SmellStinky(destination) + end) + if Heimdall_Data.config.sniffer.debug then + print(string.format("[%s] Module initialized", ModuleName)) + end + print("[Heimdall] Sniffer loaded") +end