-- Manages AddOn chat output to keep player from getting kicked off.
--
-- ChatThrottleLib:SendChatMessage/:SendAddonMessage functions that accept
-- a Priority ("BULK", "NORMAL", "ALERT") as well as prefix for SendChatMessage.
--
-- Priorities get an equal share of available bandwidth when fully loaded.
-- Communication channels are separated on extension+chattype+destination and
-- get round-robinned. (Destination only matters for whispers and channels,
-- obviously)
--
-- Will install hooks for SendChatMessage and SendAddonMessage to measure
-- bandwidth bypassing the library and use less bandwidth itself.
--
--
-- Fully embeddable library. Just copy this file into your addon directory,
-- add it to the .toc, and it's done.
--
-- Can run as a standalone addon also, but, really, just embed it! :-)
--
-- LICENSE: ChatThrottleLib is released into the Public Domain
--
localCTL_VERSION=24
local_G=_G
if_G.ChatThrottleLibthen
if_G.ChatThrottleLib.version>=CTL_VERSIONthen
-- There's already a newer (or same) version loaded. Buh-bye.
return
elseifnot_G.ChatThrottleLib.securelyHookedthen
print("ChatThrottleLib: Warning: There's an ANCIENT ChatThrottleLib.lua (pre-wow 2.0, <v16) in an addon somewhere. Get the addon updated or copy in a newer ChatThrottleLib.lua (>=v16) in it!")
-- ATTEMPT to unhook; this'll behave badly if someone else has hooked...
-- ... and if someone has securehooked, they can kiss that goodbye too... >.<
avail=math_max(avail,0-(MAX_CPS*2))-- Can go negative when someone is eating bandwidth past the lib. but we refuse to stay silent for more than 2 seconds; if they can do it, we can.
localfirst=notrawget(events,eventname)ornotnext(events[eventname])-- test for empty before. not test for one member after. that one member may have been overwritten.
forself,funcinpairs(callbacks)do
events[eventname][self]=func
-- fire OnUsed callback?
iffirstandregistry.OnUsedthen
registry.OnUsed(registry,target,eventname)
first=nil
end
end
end
registry.insertQueue=nil
end
end
-- Registration of a callback, handles:
-- self["method"], leads to self["method"](self, ...)
-- self with function ref, leads to functionref(...)
-- "addonId" (instead of self) with function ref, leads to functionref(...)
-- all with an optional arg, which, if present, gets passed as first argument (after self if present)
target[RegisterName]=function(self,eventname,method,...--[[actually just a single arg]])
localfirst=notrawget(events,eventname)ornotnext(events[eventname])-- test for empty before. not test for one member after. that one member may have been overwritten.