local _, shared = ... ---@cast shared HeimdallShared 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.dump(Heimdall_Data.config.sniffer) end if not Heimdall_Data.config.sniffer.enabled then return end if Heimdall_Data.config.sniffer.stinky and not shared.IsStinky(stinky) then if Heimdall_Data.config.sniffer.debug then print(string.format("%s: Stinky not found in config", ModuleName)) end return end local now = GetTime() local throttle = smellThrottle[stinky] or 0 if now - throttle < Heimdall_Data.config.sniffer.throttle then if Heimdall_Data.config.sniffer.debug then print(string.format("%s: Throttled", ModuleName)) end return end smellThrottle[stinky] = now for _, channel in pairs(Heimdall_Data.config.sniffer.channels) do local locale = shared.GetLocaleForChannel(channel) local text = string.format(shared._L("snifferStinky", locale), stinky) ---@type Message local msg = { channel = "C", data = channel, message = text, } if Heimdall_Data.config.sniffer.debug then print(string.format("[%s] Queuing sniffer message", ModuleName)) shared.dump(msg) end table.insert(shared.messenger.queue, msg) end 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, destination, err 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) 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