Initial commit
This commit is contained in:
125
Adapters/BliZziInterrupts.lua
Normal file
125
Adapters/BliZziInterrupts.lua
Normal file
@@ -0,0 +1,125 @@
|
||||
local Bridge = _G.HMGT_Bridge
|
||||
if not Bridge then return end
|
||||
|
||||
local PREFIX = "BliZziIT"
|
||||
local HEADER = "B1"
|
||||
local SOURCE = "BliZzi_Interrupts"
|
||||
|
||||
local Adapter = {
|
||||
key = SOURCE,
|
||||
}
|
||||
|
||||
local frame = CreateFrame("Frame")
|
||||
|
||||
local function IsSecret(value)
|
||||
return type(issecretvalue) == "function" and issecretvalue(value)
|
||||
end
|
||||
|
||||
local function ParseMessage(message)
|
||||
if IsSecret(message) then
|
||||
return nil
|
||||
end
|
||||
|
||||
local text = tostring(message or "")
|
||||
if text == "" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local parts = { strsplit(";", text) }
|
||||
if parts[1] ~= HEADER then
|
||||
return nil
|
||||
end
|
||||
|
||||
return parts
|
||||
end
|
||||
|
||||
local function NormalizeSender(sender)
|
||||
if IsSecret(sender) then
|
||||
return nil
|
||||
end
|
||||
|
||||
local text = tostring(sender or "")
|
||||
if text == "" then
|
||||
return nil
|
||||
end
|
||||
if Ambiguate then
|
||||
text = Ambiguate(text, "short")
|
||||
end
|
||||
return Bridge:NormalizePlayerName(text)
|
||||
end
|
||||
|
||||
function Adapter:HandleHello(parts, senderName)
|
||||
local class = tostring(parts[3] or "")
|
||||
local spellId = tonumber(parts[4])
|
||||
local cooldown = tonumber(parts[5])
|
||||
if class == "" or not spellId or spellId <= 0 then
|
||||
Bridge:RememberResult("known", false, "invalid_hello", tostring(senderName or ""))
|
||||
return
|
||||
end
|
||||
Bridge:Count("hello")
|
||||
Bridge:ApplyKnownSpell(SOURCE, senderName, spellId, class, cooldown)
|
||||
end
|
||||
|
||||
function Adapter:HandleHelloSync(parts, senderName)
|
||||
local class = tostring(parts[3] or "")
|
||||
local specId = tonumber(parts[5])
|
||||
if class == "" or not specId or specId <= 0 then
|
||||
Bridge:RememberResult("spec", false, "invalid_hello_sync", tostring(senderName or ""))
|
||||
return
|
||||
end
|
||||
Bridge:Count("helloSync")
|
||||
Bridge:ApplySpecInfo(SOURCE, senderName, class, specId)
|
||||
end
|
||||
|
||||
function Adapter:HandleKick(parts, senderName)
|
||||
local spellId = tonumber(parts[3])
|
||||
local cooldown = tonumber(parts[4])
|
||||
if not spellId or spellId <= 0 or not cooldown or cooldown <= 0 then
|
||||
Bridge:RememberResult("cooldown", false, "invalid_kick", tostring(senderName or ""))
|
||||
return
|
||||
end
|
||||
Bridge:Count("kick")
|
||||
Bridge:ApplyCooldown(SOURCE, senderName, spellId, cooldown)
|
||||
end
|
||||
|
||||
function Adapter:OnAddonMessage(prefix, message, channel, sender)
|
||||
if prefix ~= PREFIX then
|
||||
return
|
||||
end
|
||||
Bridge:Count("received")
|
||||
|
||||
local senderName = NormalizeSender(sender)
|
||||
if not senderName or senderName == Bridge:NormalizePlayerName(UnitName("player")) then
|
||||
Bridge:RememberResult("message", false, "ignored_sender", tostring(sender or ""))
|
||||
return
|
||||
end
|
||||
|
||||
local parts = ParseMessage(message)
|
||||
if not parts then
|
||||
Bridge:RememberResult("message", false, "invalid_message", tostring(senderName or ""))
|
||||
return
|
||||
end
|
||||
|
||||
local command = tostring(parts[2] or "")
|
||||
if command == "HELLO" then
|
||||
self:HandleHello(parts, senderName)
|
||||
elseif command == "HELLOSYNC" then
|
||||
self:HandleHelloSync(parts, senderName)
|
||||
elseif command == "KICK" then
|
||||
self:HandleKick(parts, senderName)
|
||||
end
|
||||
end
|
||||
|
||||
function Adapter:Register()
|
||||
if C_ChatInfo and type(C_ChatInfo.RegisterAddonMessagePrefix) == "function" then
|
||||
pcall(C_ChatInfo.RegisterAddonMessagePrefix, PREFIX)
|
||||
end
|
||||
frame:RegisterEvent("CHAT_MSG_ADDON")
|
||||
frame:RegisterEvent("CHAT_MSG_ADDON_LOGGED")
|
||||
frame:SetScript("OnEvent", function(_, _, ...)
|
||||
Adapter:OnAddonMessage(...)
|
||||
end)
|
||||
end
|
||||
|
||||
Bridge:RegisterAdapter(Adapter)
|
||||
Adapter:Register()
|
||||
Reference in New Issue
Block a user