Author: tandanu
Date: Fri Jul 09 21:10:22 CEST 2010
Revision: 4322
Log:

* encapsulate BNSendWhisper/SendChatMessage stuff in the local function sendWhisper
* sendWhisper prevents DBM from sending real ID messages to yourself, this could currently happen if you send a realID message to yourself during a boss fight resulting in an auto-response from DBM to yourself which might be detected as privacy issue by some addons trying to protect you
* mod:SendWhisper(msg, target) now accepts b.net presence IDs as target

Updated
trunk/DBM-Core/DBM-Core.lua

trunk/DBM-Core/DBM-Core.lua
Action: modified
Old revision: 4321
Old date: 2010-07-09 14:08:59 UTC

@@ -220,9 +220,9 @@
local pformat
do
-- fail-safe format, replaces missing arguments with unknown
- -- note: doesn't handle cases like %%%s correct at the moment (should become %unknown, but becomes %%s)
+ -- note: doesn't handle cases like %%%s correctly at the moment (should become %unknown, but becomes %%s)
-- also, the end of the format directive is not detected in all cases, but handles everything that occurs in our boss mods ;)
- --> not suitable for general-purpose use, just for our warnings and timers (where an argument like a spell-target might be nil due to missing target information)
+ --> not suitable for general-purpose use, just for our warnings and timers (where an argument like a spell-target might be nil due to missing target information from unreliable detection methods)

local function replace(cap1, cap2)
return cap1 == "%" and DBM_CORE_UNKNOWN
@@ -234,7 +234,23 @@
end
end

+-- sends a whisper to a player by his or her character name or BNet presence id
+-- returns true if the message was sent, nil otherwise
+local function sendWhisper(target, msg)
+ if type(target) == "number" then
+ if not BNIsSelf(target) then -- never send BNet whispers to ourselves
+ BNSendWhisper(target, msg)
+ return true
+ end
+ elseif type(target) == "string" then
+ -- whispering to ourselves here is okay and somewhat useful for whisper-warnings
+ SendChatMessage(msg, "WHISPER", nil, target)
+ return true
+ end
+end
+local BNSendWhisper = sendWhisper

+
--------------
-- Events --
--------------
@@ -1804,12 +1820,8 @@
local msg
for k, v in pairs(autoRespondSpam) do
msg = msg or chatPrefixShort..DBM_CORE_WHISPER_COMBAT_END_WIPE:format(UnitName("player"), (mod.combatInfo.name or ""))
- if type(k) == "string" then
- SendChatMessage(msg, "WHISPER", nil, k)
- elseif type(k) == "number" then
- BNSendWhisper(k, msg)
+ sendWhisper(k, msg)
end
- end
fireEvent("wipe", mod)
else
local thisTime = GetTime() - mod.combatInfo.pull
@@ -2045,12 +2057,7 @@
mod = not v.isCustomMod and v
end
mod = mod or inCombat[1]
- local msg = chatPrefix..DBM_CORE_STATUS_WHISPER:format((mod.combatInfo.name or ""), mod:GetHP() or "unknown", getNumAlivePlayers(), math.max(GetNumRaidMembers(), GetNumPartyMembers() + 1))
- if isRealIdMessage then
- BNSendWhisper(sender, msg)
- else
- SendChatMessage(msg, "WHISPER", nil, sender)
- end
+ sendWhisper(sender, chatPrefix..DBM_CORE_STATUS_WHISPER:format((mod.combatInfo.name or ""), mod:GetHP() or "unknown", getNumAlivePlayers(), math.max(GetNumRaidMembers(), GetNumPartyMembers() + 1)))
elseif #inCombat > 0 and DBM.Options.AutoRespond and
(isRealIdMessage and (not isOnSameServer(sender) or DBM:GetRaidUnitId((select(4, BNGetFriendInfoByID(sender)))) == "none") or not isRealIdMessage and DBM:GetRaidUnitId(sender) == "none") then
local mod
@@ -2059,12 +2066,7 @@
end
mod = mod or inCombat[1]
if not autoRespondSpam[sender] then
- local msg = chatPrefix..DBM_CORE_AUTO_RESPOND_WHISPER:format(UnitName("player"), mod.combatInfo.name or "", mod:GetHP() or "unknown", getNumAlivePlayers(), math.max(GetNumRaidMembers(), GetNumPartyMembers() + 1))
- if isRealIdMessage then
- BNSendWhisper(sender, msg)
- else
- SendChatMessage(msg, "WHISPER", nil, sender)
- end
+ sendWhisper(sender, chatPrefix..DBM_CORE_AUTO_RESPOND_WHISPER:format(UnitName("player"), mod.combatInfo.name or "", mod:GetHP() or "unknown", getNumAlivePlayers(), math.max(GetNumRaidMembers(), GetNumPartyMembers() + 1)))
DBM:AddMsg(DBM_CORE_AUTO_RESPONDED)
end
autoRespondSpam[sender] = true
@@ -2358,12 +2360,8 @@
end

function bossModPrototype:SendWhisper(msg, target)
- if not DBM.Options.DontSendBossWhispers then
- return SendChatMessage(chatPrefixShort..msg, "WHISPER", nil, target)
- else
- return nil
+ return not DBM.Options.DontSendBossWhispers and sendWhisper(target, chatPrefixShort..msg)
end
-end

function bossModPrototype:GetUnitCreatureId(uId)
local guid = UnitGUID(uId)