@ -25,36 +25,32 @@
local CTL_VERSION = 23
local _G = _G
if _G.ChatThrottleLib then
if _G.ChatThrottleLib . version >= CTL_VERSION then
if ChatThrottleLib then
if ChatThrottleLib.version >= CTL_VERSION then
-- There's already a newer (or same) version loaded. Buh-bye.
return
elseif not _G. ChatThrottleLib. securelyHooked then
elseif not ChatThrottleLib.securelyHooked then
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... >.<
_G. SendChatMessage = _G. ChatThrottleLib. ORIG_SendChatMessage
if _G.ChatThrottleLib . ORIG_SendAddonMessage then
_G. SendAddonMessage = _G. ChatThrottleLib. ORIG_SendAddonMessage
SendChatMessage = ChatThrottleLib.ORIG_SendChatMessage
if ChatThrottleLib. ORIG_SendAddonMessage then
SendAddonMessage = ChatThrottleLib.ORIG_SendAddonMessage
end
end
_G.ChatThrottleLib . ORIG_SendChatMessage = nil
_G.ChatThrottleLib . ORIG_SendAddonMessage = nil
ChatThrottleLib. ORIG_SendChatMessage = nil
ChatThrottleLib. ORIG_SendAddonMessage = nil
end
if not _G. ChatThrottleLib then
_G. ChatThrottleLib = { }
if not ChatThrottleLib then
ChatThrottleLib = { }
end
ChatThrottleLib = _G. ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh)
local ChatThrottleLib = _G. ChatThrottleLib
ChatThrottleLib = ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh)
local ChatThrottleLib = ChatThrottleLib
ChatThrottleLib.version = CTL_VERSION
------------------ TWEAKABLES -----------------
ChatThrottleLib.MAX_CPS = 800 -- 2000 seems to be safe if NOTHING ELSE is happening. let's call it 800.
@ -64,7 +60,6 @@ ChatThrottleLib.BURST = 4000 -- WoW's server buffer seems to be about 32KB. 8
ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) if FPS drops below this value
local setmetatable = setmetatable
local table_remove = table.remove
local tostring = tostring
@ -78,7 +73,6 @@ local strlower = string.lower
local unpack , type , pairs , wipe = unpack , type , pairs , wipe
local UnitInRaid , UnitInParty = UnitInRaid , UnitInParty
-----------------------------------------------------------------------
-- Double-linked ring implementation
@ -115,8 +109,6 @@ function Ring:Remove(obj)
end
end
-----------------------------------------------------------------------
-- Recycling bin for pipes
-- A pipe is a plain integer-indexed queue of messages
@ -139,9 +131,6 @@ local function NewPipe()
return { }
end
-----------------------------------------------------------------------
-- Recycling bin for messages
@ -163,14 +152,11 @@ local function NewMsg()
return { }
end
-----------------------------------------------------------------------
-- ChatThrottleLib:Init
-- Initialize queues, set up frame for OnUpdate, etc
function ChatThrottleLib : Init ( )
-- Set up queues
if not self.Prio then
self.Prio = { }
@ -191,7 +177,6 @@ function ChatThrottleLib:Init()
self.nTotalSent = 0 -- v5
end
-- Set up a frame to get OnUpdate events
if not self.Frame then
self.Frame = CreateFrame ( " Frame " )
@ -220,7 +205,6 @@ function ChatThrottleLib:Init()
self.nBypass = 0
end
-----------------------------------------------------------------------
-- ChatThrottleLib.Hook_SendChatMessage / .Hook_SendAddonMessage
@ -240,21 +224,19 @@ function ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destinati
return
end
local self = ChatThrottleLib
local size = tostring ( text or " " ) : len ( ) + tostring ( prefix or " " ) : len ( ) ;
local size = tostring ( text or " " ) : len ( ) + tostring ( prefix or " " ) : len ( )
size = size + tostring ( destination or " " ) : len ( ) + self.MSG_OVERHEAD
self.avail = self.avail - size
self.nBypass = self.nBypass + size -- just a statistic
end
-----------------------------------------------------------------------
-- ChatThrottleLib:UpdateAvail
-- Update self.avail with how much bandwidth is currently available
function ChatThrottleLib : UpdateAvail ( )
local now = GetTime ( )
local MAX_CPS = self.MAX_CPS ;
local MAX_CPS = self.MAX_CPS
local newavail = MAX_CPS * ( now - self.LastAvailUpdate )
local avail = self.avail
@ -278,7 +260,6 @@ function ChatThrottleLib:UpdateAvail()
return avail
end
-----------------------------------------------------------------------
-- Despooling logic
-- Reminder:
@ -321,7 +302,6 @@ function ChatThrottleLib:Despool(Prio)
end
end
function ChatThrottleLib . OnEvent ( this , event )
-- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too.
local self = ChatThrottleLib
@ -331,7 +311,6 @@ function ChatThrottleLib.OnEvent(this,event)
end
end
function ChatThrottleLib . OnUpdate ( this , delay )
local self = ChatThrottleLib
@ -380,12 +359,8 @@ function ChatThrottleLib.OnUpdate(this,delay)
end
end
end
end
-----------------------------------------------------------------------
-- Spooling logic
@ -410,7 +385,7 @@ function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, languag
error ( ' Usage: ChatThrottleLib:SendChatMessage("{BULK||NORMAL||ALERT}", "prefix", "text"[, "chattype"[, "language"[, "destination"]]] ' , 2 )
end
if callbackFn and type ( callbackFn ) ~= " function " then
error ( ' ChatThrottleLib:ChatMessage(): callbackFn: expected function, got ' .. type ( callbackFn ) , 2 )
error ( " ChatThrottleLib:ChatMessage(): callbackFn: expected function, got " .. type ( callbackFn ) , 2 )
end
local nSize = text : len ( )
@ -450,16 +425,15 @@ function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, languag
self : Enqueue ( prio , queueName or ( prefix .. ( chattype or " SAY " ) .. ( destination or " " ) ) , msg )
end
function ChatThrottleLib : SendAddonMessage ( prio , prefix , text , chattype , target , queueName , callbackFn , callbackArg )
if not self or not prio or not prefix or not text or not chattype or not self.Prio [ prio ] then
error ( ' Usage: ChatThrottleLib:SendAddonMessage("{BULK||NORMAL||ALERT}", "prefix", "text", "chattype"[, "target"]) ' , 2 )
end
if callbackFn and type ( callbackFn ) ~= " function " then
error ( ' ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got ' .. type ( callbackFn ) , 2 )
error ( " ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got " .. type ( callbackFn ) , 2 )
end
local nSize = text : len ( ) ;
local nSize = text : len ( )
if RegisterAddonMessagePrefix then
if nSize > 255 then
@ -472,7 +446,7 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
end
end
nSize = nSize + self.MSG_OVERHEAD ;
nSize = nSize + self.MSG_OVERHEAD
-- Check if there's room in the global available bandwidth gauge to send directly
if not self.bQueueing and nSize < self : UpdateAvail ( ) then
@ -495,7 +469,7 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
msg [ 2 ] = text
msg [ 3 ] = chattype
msg [ 4 ] = target
msg.n = ( target ~= nil ) and 4 or 3 ;
msg.n = ( target ~= nil ) and 4 or 3
msg.nSize = nSize
msg.callbackFn = callbackFn
msg.callbackArg = callbackArg
@ -503,9 +477,6 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
self : Enqueue ( prio , queueName or ( prefix .. chattype .. ( target or " " ) ) , msg )
end
-----------------------------------------------------------------------
-- Get the ball rolling!
@ -520,5 +491,3 @@ if(WOWB_VER) then
ChatThrottleLib.Frame : RegisterEvent ( " CHAT_MSG_SAY " )
end
] ]