93 lines
3.1 KiB
Lua
93 lines
3.1 KiB
Lua
local _, shared = ...
|
|
---@cast shared HeimdallShared
|
|
local ModuleName = "Sniffer"
|
|
|
|
---@class HeimdallSnifferConfig
|
|
---@field enabled boolean
|
|
---@field debug boolean
|
|
---@field channels string[]
|
|
---@field throttle number -- throttleTime in the original code, matching config name now
|
|
---@field zoneOverride string?
|
|
---@field stinky boolean
|
|
|
|
---@class Sniffer
|
|
shared.Sniffer = {
|
|
Init = function()
|
|
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
|
|
if smellThrottle[stinky] and GetTime() - smellThrottle[stinky] < Heimdall_Data.config.sniffer.throttle then
|
|
if Heimdall_Data.config.sniffer.debug then print(string.format("%s: Throttled", ModuleName)) end
|
|
return
|
|
end
|
|
smellThrottle[stinky] = GetTime()
|
|
|
|
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,
|
|
}
|