Skip to content

Commit

Permalink
Fix breaking API changes in 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Chastain authored and Fylwind committed Apr 19, 2016
1 parent b07afc9 commit 48a331b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
92 changes: 46 additions & 46 deletions FZXC.lua
Expand Up @@ -35,7 +35,7 @@ local string_sub = string.sub
local BNGetFriendInfo = BNGetFriendInfo
local BNGetFriendIndex = BNGetFriendIndex
local BNGetNumFriends = BNGetNumFriends
local BNGetToonInfo = BNGetToonInfo
local BNGetGameAccountInfo = BNGetGameAccountInfo
local GetChannelName = GetChannelName
local GetChannelList = GetChannelList
local GetIgnoreName = GetIgnoreName
Expand Down Expand Up @@ -107,7 +107,7 @@ local function updateSources()
isConnectedRealm_init()
sources = {}
for friendIndex = 1, BNGetNumFriends() do
local presenceID, _, _, _, _, toonID, client, _, _, _, _, _, note
local bnetIDAccount, _, _, _, _, bnetIDGameAccount, client, _, _, _, _, _, note
= BNGetFriendInfo(friendIndex)
if note then
for source, separator, dest in string_gmatch(
Expand All @@ -122,30 +122,30 @@ local function updateSources()
dests = {}
sources[source] = dests
end
local presenceIDs = dests[dest]
if not presenceIDs then
presenceIDs = {}
dests[dest] = presenceIDs
local bnetIDAccounts = dests[dest]
if not bnetIDAccounts then
bnetIDAccounts = {}
dests[dest] = bnetIDAccounts
end

local online = false
if toonID ~= nil and toonID ~= 0 then
local _, name, _, realm, _, faction = BNGetToonInfo(toonID)
if bnetIDGameAccount ~= nil and bnetIDGameAccount ~= 0 then
local _, name, _, realm, _, faction = BNGetGameAccountInfo(bnetIDGameAccount)
if client == "WoW" and (not isConnectedRealm[realm] or
faction ~= playerFaction) then
presenceIDs[presenceID] = {
bnetIDAccounts[bnetIDAccount] = {
connected = true,
name = name,
realm = realm,
faction = faction,
toonID = toonID
bnetIDGameAccount = bnetIDGameAccount
}
online = true
end
end

if not online then
presenceIDs[presenceID] = { connected = false }
bnetIDAccounts[bnetIDAccount] = { connected = false }
end
end
end
Expand All @@ -161,17 +161,17 @@ local function updateIgnoreList()
end

-- Ensure message is not just another duplicate from a different player
local function checkMessageSent(toonID, counter, sender, channel, text)
dprint(toonID)
local function checkMessageSent(bnetIDGameAccount, counter, sender, channel, text)
dprint(bnetIDGameAccount)
local hash = string_format("%s#%s#%s", channel, sender, text)
local archive = messageArchive
local messages = archive[hash]
if not messages then
archive[hash] = {{toonID = toonID, time = GetTime()}}
archive[hash] = {{bnetIDGameAccount = bnetIDGameAccount, time = GetTime()}}
return
end
for _, message in pairs(messages) do
if message.toonID ~= toonID then
if message.bnetIDGameAccount ~= bnetIDGameAccount then
-- Message sent by a different player which we'll ignore since
-- it's most likely a duplicate (it's hard to tell)
return true
Expand All @@ -184,7 +184,7 @@ local function checkMessageSent(toonID, counter, sender, channel, text)
-- (Assuming the former case ...)
return true
end
messages[counter] = {toonID = toonID, time = GetTime()}
messages[counter] = {bnetIDGameAccount = bnetIDGameAccount, time = GetTime()}
end

local versionChecked
Expand All @@ -204,32 +204,32 @@ local ECHO_REPLY = 2
local VERSION_REQUEST = 3
local VERSION_REPLY = 4

local function replyMessage(toonID, request, data, _, data2)
local function replyMessage(bnetIDGameAccount, request, data, _, data2)
dprint("replyMessage: ")
dump({toonID, destID, request, data, data2})
dump({bnetIDGameAccount, destID, request, data, data2})
request = tonumber(request)
if request == ECHO_REQUEST then
dprint("replyMessage: received ECHO_REQUEST")
FZMP_SendMessage(
"FZXC",
{ECHO_REPLY, data, ""},
"BN_CHAT_MSG_ADDON",
toonID)
bnetIDGameAccount)
elseif request == ECHO_REPLY then
local prevTime = tonumber(data)
if prevTime then
cprintf("fzxc: ping = %.3f s from %d",
GetTime() - prevTime, toonID)
GetTime() - prevTime, bnetIDGameAccount)
else
dprint("replyMessage: received invalid ECHO_REPLY from",
toonID)
bnetIDGameAccount)
end
elseif request == VERSION_REQUEST then
FZMP_SendMessage(
"FZXC",
{VERSION_REPLY, version, "", tostring(timestamp)},
"BN_CHAT_MSG_ADDON",
toonID)
bnetIDGameAccount)
checkVersion(data, data2)
elseif request == VERSION_REPLY then
checkVersion(data, data2)
Expand Down Expand Up @@ -280,26 +280,26 @@ local function isPrimaryRecipient(recipients)
return true
end

local function receiveTransmission(_, data, _, toonID)
local function receiveTransmission(_, data, _, bnetIDGameAccount)
dprint("receiveTransmission: data =")
dump(data)
local counter, sender, channel, text, realm, faction, recipients
= unpack(data)
if channel == "" then
replyMessage(toonID, unpack(data))
replyMessage(bnetIDGameAccount, unpack(data))
return
end
if not sources[channel] then -- Reject if channel tag absent
dprint("receiveTransmission: rejected (absent channel tag):",
toonID, counter, sender, channel, text)
bnetIDGameAccount, counter, sender, channel, text)
return
end
if not realm then
dprint("receiveTransmission: rejected (realm missing):")
return
end
dprint("receiveTransmission:", toonID, counter, sender, channel, text)
if checkMessageSent(toonID, counter, sender, channel, text) then
dprint("receiveTransmission:", bnetIDGameAccount, counter, sender, channel, text)
if checkMessageSent(bnetIDGameAccount, counter, sender, channel, text) then
return
end
if realm == playerRealm and faction == playerFaction then
Expand Down Expand Up @@ -334,8 +334,8 @@ local function onChatMsgChannel(text, sender, _, _, _, _, _,
end
text = string_gsub(text, "|", "\027")
local messages = {}
for dest, presenceIDs in pairs(dests) do
for presenceID, info in pairs(presenceIDs) do
for dest, bnetIDAccounts in pairs(dests) do
for bnetIDAccount, info in pairs(bnetIDAccounts) do
if info.connected then
local name = info.name
local hash = string_format(
Expand All @@ -348,13 +348,13 @@ local function onChatMsgChannel(text, sender, _, _, _, _, _,
-- The player with the "Z"-most name gets to broadcast it
if message.name < name then
message.name = name
message.presenceID = presenceID
message.bnetIDAccount = bnetIDAccount
end
else
message = {
dest = dest,
name = name,
presenceID = presenceID
bnetIDAccount = bnetIDAccount
}
messages[hash] = message
end
Expand All @@ -364,8 +364,8 @@ local function onChatMsgChannel(text, sender, _, _, _, _, _,
local recipients = {} -- FactionDest -> NameRealm
for _, message in pairs(messages) do
local dest = message.dest
local presenceIDs = dests[dest]
local info = presenceIDs[message.presenceID]
local bnetIDAccounts = dests[dest]
local info = bnetIDAccounts[message.bnetIDAccount]
local factionDest = string_format("%s#%s", info.faction, dest)

-- append to recipients[factionDest]
Expand All @@ -383,9 +383,9 @@ local function onChatMsgChannel(text, sender, _, _, _, _, _,
recipients[0] = nil
for _, message in pairs(messages) do
local dest = message.dest
local info = dests[dest][message.presenceID]
local destID = info.toonID
if destID == nil or destID == 0 then destID = message.presenceID end
local info = dests[dest][message.bnetIDAccount]
local destID = info.bnetIDGameAccount
if destID == nil or destID == 0 then destID = message.bnetIDAccount end
local factionDest = string_format("%s#%s", info.faction, dest)
local data = {counter, sender, dest, text, playerRealm, playerFaction,
recipients[factionDest]}
Expand Down Expand Up @@ -460,15 +460,15 @@ local slashCommands = {
cprint(L"fzxc: displaying all channels ...")
updateSources()
for source, dests in pairs(sources) do
for dest, presenceIDs in pairs(dests) do
for dest, bnetIDAccounts in pairs(dests) do
if source == dest then
cprintf("#%s", source)
else
cprintf("#%s:%s", source, dest)
end
for presenceID, info in pairs(presenceIDs) do
for bnetIDAccount, info in pairs(bnetIDAccounts) do
local _, name =
BNGetFriendInfo(BNGetFriendIndex(presenceID))
BNGetFriendInfo(BNGetFriendIndex(bnetIDAccount))
local status
if info.connected then
status = string_format("|cff00ff00%s|r",
Expand Down Expand Up @@ -576,13 +576,13 @@ local slashCommands = {
},
ping = {
action = function(name)
local presenceID = GetAutoCompletePresenceID(name)
if not presenceID then
local bnetIDAccount = GetAutoCompletePresenceID(name)
if not bnetIDAccount then
cprint("fzxc: invalid name")
return
end
FZMP_SendMessage("FZXC", {ECHO_REQUEST, tostring(GetTime()), ""},
"BN_CHAT_MSG_ADDON", presenceID)
"BN_CHAT_MSG_ADDON", bnetIDAccount)
end
},
}
Expand Down Expand Up @@ -612,11 +612,11 @@ local function initialize()
-- Query version of other player's addons
local connectedDestIDs = {}
for source, dests in pairs(sources) do
for dest, presenceIDs in pairs(dests) do
for presenceID, info in pairs(presenceIDs) do
for dest, bnetIDAccounts in pairs(dests) do
for bnetIDAccount, info in pairs(bnetIDAccounts) do
if info.connected then
local destID = info.toonID
if destID == nil or destID == 0 then destID = presenceID end
local destID = info.bnetIDGameAccount
if destID == nil or destID == 0 then destID = bnetIDAccount end
connectedDestIDs[destID] = true
end
end
Expand Down
2 changes: 1 addition & 1 deletion FZXC.toc
@@ -1,4 +1,4 @@
## Interface: 60100
## Interface: 60200
## Title: FZ Cross-realm Communicator
## Author: Fylwind, Wraithstrike
## Notes: Allows communication to be shared across realm through Battle.net.
Expand Down
4 changes: 2 additions & 2 deletions LibFZMP.lua
Expand Up @@ -45,8 +45,8 @@ local string_sub = string.sub
local table_concat = table.concat

local BNGetFriendInfo = BNGetFriendInfo
local BNGetNumFriendToons = BNGetNumFriendToons
local BNGetToonInfo = BNGetToonInfo
local BNGetNumFriendGameAccounts = BNGetNumFriendGameAccounts
local BNGetGameAccountInfo = BNGetGameAccountInfo
local BNSendWhisper = BNSendWhisper
local ChatFrame_AddMessageEventFilter = ChatFrame_AddMessageEventFilter
local GetChannelName = GetChannelName
Expand Down

0 comments on commit 48a331b

Please sign in to comment.