comparison Libs/AceComm-3.0/ChatThrottleLib.lua @ 124:e31b02b24488

Updated for 8.0 pre-patch and BfA.
author yellowfive
date Tue, 17 Jul 2018 09:57:39 -0700
parents 01b63b8ed811
children
comparison
equal deleted inserted replaced
123:7a6364917f86 124:e31b02b24488
21 -- Can run as a standalone addon also, but, really, just embed it! :-) 21 -- Can run as a standalone addon also, but, really, just embed it! :-)
22 -- 22 --
23 -- LICENSE: ChatThrottleLib is released into the Public Domain 23 -- LICENSE: ChatThrottleLib is released into the Public Domain
24 -- 24 --
25 25
26 local CTL_VERSION = 23 26 local CTL_VERSION = 24
27 27
28 local _G = _G 28 local _G = _G
29 29
30 if _G.ChatThrottleLib then 30 if _G.ChatThrottleLib then
31 if _G.ChatThrottleLib.version >= CTL_VERSION then 31 if _G.ChatThrottleLib.version >= CTL_VERSION then
211 --SendChatMessage 211 --SendChatMessage
212 hooksecurefunc("SendChatMessage", function(...) 212 hooksecurefunc("SendChatMessage", function(...)
213 return ChatThrottleLib.Hook_SendChatMessage(...) 213 return ChatThrottleLib.Hook_SendChatMessage(...)
214 end) 214 end)
215 --SendAddonMessage 215 --SendAddonMessage
216 hooksecurefunc("SendAddonMessage", function(...) 216 if _G.C_ChatInfo then
217 return ChatThrottleLib.Hook_SendAddonMessage(...) 217 hooksecurefunc(_G.C_ChatInfo, "SendAddonMessage", function(...)
218 end) 218 return ChatThrottleLib.Hook_SendAddonMessage(...)
219 end)
220 else
221 hooksecurefunc("SendAddonMessage", function(...)
222 return ChatThrottleLib.Hook_SendAddonMessage(...)
223 end)
224 end
219 end 225 end
220 self.nBypass = 0 226 self.nBypass = 0
221 end 227 end
222 228
223 229
459 error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2) 465 error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2)
460 end 466 end
461 467
462 local nSize = text:len(); 468 local nSize = text:len();
463 469
464 if RegisterAddonMessagePrefix then 470 if C_ChatInfo or RegisterAddonMessagePrefix then
465 if nSize>255 then 471 if nSize>255 then
466 error("ChatThrottleLib:SendAddonMessage(): message length cannot exceed 255 bytes", 2) 472 error("ChatThrottleLib:SendAddonMessage(): message length cannot exceed 255 bytes", 2)
467 end 473 end
468 else 474 else
469 nSize = nSize + prefix:len() + 1 475 nSize = nSize + prefix:len() + 1
476 482
477 -- Check if there's room in the global available bandwidth gauge to send directly 483 -- Check if there's room in the global available bandwidth gauge to send directly
478 if not self.bQueueing and nSize < self:UpdateAvail() then 484 if not self.bQueueing and nSize < self:UpdateAvail() then
479 self.avail = self.avail - nSize 485 self.avail = self.avail - nSize
480 bMyTraffic = true 486 bMyTraffic = true
481 _G.SendAddonMessage(prefix, text, chattype, target) 487 if _G.C_ChatInfo then
488 _G.C_ChatInfo.SendAddonMessage(prefix, text, chattype, target)
489 else
490 _G.SendAddonMessage(prefix, text, chattype, target)
491 end
482 bMyTraffic = false 492 bMyTraffic = false
483 self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize 493 self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize
484 if callbackFn then 494 if callbackFn then
485 callbackFn (callbackArg, true) 495 callbackFn (callbackArg, true)
486 end 496 end
488 return 498 return
489 end 499 end
490 500
491 -- Message needs to be queued 501 -- Message needs to be queued
492 local msg = NewMsg() 502 local msg = NewMsg()
493 msg.f = _G.SendAddonMessage 503 msg.f = _G.C_ChatInfo and _G.C_ChatInfo.SendAddonMessage or _G.SendAddonMessage
494 msg[1] = prefix 504 msg[1] = prefix
495 msg[2] = text 505 msg[2] = text
496 msg[3] = chattype 506 msg[3] = chattype
497 msg[4] = target 507 msg[4] = target
498 msg.n = (target~=nil) and 4 or 3; 508 msg.n = (target~=nil) and 4 or 3;