Skip to content

Commit

Permalink
Attempt to fix broken cross-realm addon communications
Browse files Browse the repository at this point in the history
  • Loading branch information
linaori committed Feb 16, 2023
1 parent 37182d8 commit 86232bd
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ globals = {
'GetLFGRoleUpdate',
'GetLocale',
'GetMaxBattlefieldID',
'GetNormalizedRealmName',
'GetNumGroupMembers',
'GetPlayerAuraBySpellID',
'GetRealmName',
'GetTime',
'GetUnitName',
'InCombatLockdown',
Expand Down
16 changes: 12 additions & 4 deletions BattlegroundTools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local GetGroupLeaderData = Namespace.PlayerData.GetGroupLeaderData
local GetPlayerDataByUnit = Namespace.PlayerData.GetPlayerDataByUnit
local Role = Namespace.PlayerData.Role
local GetMessageDestination = Namespace.Communication.GetMessageDestination
local PackData = Namespace.Communication.PackData
local UnpackData = Namespace.Communication.UnpackData
local GroupType = Namespace.Utils.GroupType
local GetGroupType = Namespace.Utils.GetGroupType
local ForEachUnitData = Namespace.PlayerData.ForEachUnitData
Expand Down Expand Up @@ -625,7 +627,10 @@ function Module:GetZoneId(zoneId)
return Namespace.Database.profile.BattlegroundTools.InstructionFrame.zones[zoneId]
end

function Private.OnAcknowledgeWantBattlegroundLead(_, _, _, sender)
function Private.OnAcknowledgeWantBattlegroundLead(_, text, _, sender)
local payload = UnpackData(text)
sender = payload and payload.sender or sender

if sender == GetRealUnitName('player') then return end

local mem = Memory.WantBattlegroundLead
Expand All @@ -643,14 +648,17 @@ function Private.CanRequestLead()
return InActiveBattleground()
end

function Private.OnWantBattlegroundLead(_, _, _, sender)
function Private.OnWantBattlegroundLead(_, text, _, sender)
local payload = UnpackData(text)
sender = payload and payload.sender or sender

if sender == GetRealUnitName('player') then return end
if not UnitIsGroupLeader('player') then return end

local channel = GetMessageDestination()
if channel == Channel.Whisper then return end

Module:SendCommMessage(CommunicationEvent.AcknowledgeWantBattlegroundLead, '1', channel)
Module:SendCommMessage(CommunicationEvent.AcknowledgeWantBattlegroundLead, PackData({}), channel)

local config = Namespace.Database.profile.BattlegroundTools.WantBattlegroundLead
if config.wantLead then return end
Expand Down Expand Up @@ -717,7 +725,7 @@ function Private.SendWantBattlegroundLead()
end
end

Module:SendCommMessage(CommunicationEvent.WantBattlegroundLead, '1', channel)
Module:SendCommMessage(CommunicationEvent.WantBattlegroundLead, PackData({}), channel)
end

function Private.RequestRaidLead()
Expand Down
148 changes: 77 additions & 71 deletions Changelog.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
local _, Namespace = ...

Namespace.Changelog = {
{
version = '10.0.5-21',
bugs = {
'Fixed an issue with the addon not sending and receiving data cross-realm due to "sender" losing its realm information. For now all names in group information will include the realm.',
},
},
{
version = '10.0.5-20',
improvements = {
Expand Down Expand Up @@ -44,77 +50,77 @@ Namespace.Changelog = {
'Fixed a bug where the "status" column was not set to "OK" for group members after entering a battleground',
},
},
{
version = '10.0.2-14',
features = {
'Added a preferred icon for player configuration. When configured and you get lead, the player will be marked with the selected icon, or get another available icon if available. Players with a preferred icon will take precedence over players with "any available icon"',
},
improvements = {
'Removed "add player by name" for now, as it was limited to the combination of the other two ways of adding users'
},
},
{
version = '10.0.2-13',
bugs = {
'Fixed an issue where the new "BGC: Configure" option would show up in places it does not belong',
},
},
{
version = '10.0.2-12',
features = {
'Added shortcuts in the config to configure players options: "Add player from group", "Add recently played with", "Add player by name"',
},
improvements = {
'Reworked the config for player management. Each player now has a dedicated config section under "Battleground Tools -> Player Management"',
'Replaced /bgca and /bgcm by a right click context menu item: "BGC: Configure"'
},
bugs = {
'Fixed a bug where the instruction frame did not properly update after reloading in a battleground',
},
},
{
version = '10.0.2-11',
bugs = {
'Fixed an issue where the instruction window sometimes would not go away',
},
},
{
version = '10.0.2-10',
improvements = {
'Players who are marked should no longer be randomly swapping marks',
'Ensured internal logic works the same everywhere when it comes to detecting battleground status',
'When "Requesting Lead -> Send Raid is enabled, it will now also use the instance chat',
'Removed "Open World" as option from the instructions window',
'Changing "Leader Setup" settings now also re-marks accordingly',
},
bugs = {
'Fixed an error when opening the group info while not in a group',
},
},
{
version = '10.0.2-9',
features = {
'Added an option to automatically mark raid members. Target a player and run /bgcm in chat to add them to the list. You can also manually add players in the "Battleground Tools -> Leader Setup -> Decision Automation" section',
},
},
{
version = '10.0.2-8',
improvements = {
'Updated TOC for 10.0.2, pre-patch phase 2',
},
},
{
version = '10.0.0-7',
bugs = {
'Fixed the issue of demoting assists automatically back to member if not listed when manually promoted',
},
},
{
version = '10.0.0-6',
improvements = {
'Added a toggle to control automatic promotion and demotion behavior',
},
},
--{
-- version = '10.0.2-14',
-- features = {
-- 'Added a preferred icon for player configuration. When configured and you get lead, the player will be marked with the selected icon, or get another available icon if available. Players with a preferred icon will take precedence over players with "any available icon"',
-- },
-- improvements = {
-- 'Removed "add player by name" for now, as it was limited to the combination of the other two ways of adding users'
-- },
--},
--{
-- version = '10.0.2-13',
-- bugs = {
-- 'Fixed an issue where the new "BGC: Configure" option would show up in places it does not belong',
-- },
--},
--{
-- version = '10.0.2-12',
-- features = {
-- 'Added shortcuts in the config to configure players options: "Add player from group", "Add recently played with", "Add player by name"',
-- },
-- improvements = {
-- 'Reworked the config for player management. Each player now has a dedicated config section under "Battleground Tools -> Player Management"',
-- 'Replaced /bgca and /bgcm by a right click context menu item: "BGC: Configure"'
-- },
-- bugs = {
-- 'Fixed a bug where the instruction frame did not properly update after reloading in a battleground',
-- },
--},
--{
-- version = '10.0.2-11',
-- bugs = {
-- 'Fixed an issue where the instruction window sometimes would not go away',
-- },
--},
--{
-- version = '10.0.2-10',
-- improvements = {
-- 'Players who are marked should no longer be randomly swapping marks',
-- 'Ensured internal logic works the same everywhere when it comes to detecting battleground status',
-- 'When "Requesting Lead -> Send Raid is enabled, it will now also use the instance chat',
-- 'Removed "Open World" as option from the instructions window',
-- 'Changing "Leader Setup" settings now also re-marks accordingly',
-- },
-- bugs = {
-- 'Fixed an error when opening the group info while not in a group',
-- },
--},
--{
-- version = '10.0.2-9',
-- features = {
-- 'Added an option to automatically mark raid members. Target a player and run /bgcm in chat to add them to the list. You can also manually add players in the "Battleground Tools -> Leader Setup -> Decision Automation" section',
-- },
--},
--{
-- version = '10.0.2-8',
-- improvements = {
-- 'Updated TOC for 10.0.2, pre-patch phase 2',
-- },
--},
--{
-- version = '10.0.0-7',
-- bugs = {
-- 'Fixed the issue of demoting assists automatically back to member if not listed when manually promoted',
-- },
--},
--{
-- version = '10.0.0-6',
-- improvements = {
-- 'Added a toggle to control automatic promotion and demotion behavior',
-- },
--},
--{
-- version = '10.0.0-5',
-- features = {
Expand Down
2 changes: 2 additions & 0 deletions Communication.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ local Channel = {
Namespace.Communication.Channel = Channel

function Namespace.Communication.PackData(data)
if not data.sender then data.sender = GetRealUnitName('player') end

return Encoder:Encode(LibCompress:CompressHuffman(AceSerializer:Serialize(data)))
end

Expand Down
22 changes: 16 additions & 6 deletions QueueTools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,17 @@ function Private.OnSyncData(_, text, _, sender)
local payload = UnpackData(text)
if not payload then return end

local data = GetPlayerDataByName(sender)
local data = GetPlayerDataByName(payload.sender or sender)
if not data then return end

Private.ProcessSyncData(payload, data)
end

function Private.OnReadyCheckHeartbeat(_, text, _, sender)
local payload = UnpackData(text)
text = payload and payload.text or text
sender = payload and payload.sender or sender

if sender == GetRealUnitName('player') then return end

local acceptReadyCheck = function (skipVisibility)
Expand All @@ -521,7 +525,7 @@ end

function Private.OnClickEnterBattleground()
local channel, player = GetMessageDestination()
Module:SendCommMessage(CommunicationEvent.EnterBattleground, '1', channel, player)
Module:SendCommMessage(CommunicationEvent.EnterBattleground, PackData({}), channel, player)

if not IsLeaderOrAssistant('player') then return end

Expand All @@ -532,7 +536,10 @@ function Private.OnClickEnterBattleground()
end
end

function Private.OnEnterBattleground(_, _, _, sender)
function Private.OnEnterBattleground(_, text, _, sender)
local payload = UnpackData(text)
sender = payload and payload.sender or sender

local data = GetPlayerDataByName(sender)
if not data then return Namespace.Debug.Log('Missing player data on enter', sender) end

Expand Down Expand Up @@ -574,7 +581,10 @@ function Private.DisableEntryButton(text)
end, 0.3)
end

function Private.OnDeclineBattleground(_, _, _, sender)
function Private.OnDeclineBattleground(_, text, _, sender)
local payload = UnpackData(text)
sender = payload and payload.sender or sender

local data = GetPlayerDataByName(sender)
if not data then return end

Expand Down Expand Up @@ -698,7 +708,7 @@ function Private.SendReadyCheckHeartbeat(message)

DoReadyCheck()
Addon:Print(format(L['Sending automated ready check with message: "%s"'], message))
Module:SendCommMessage(CommunicationEvent.ReadyCheckHeartbeat, message, GetMessageDestination())
Module:SendCommMessage(CommunicationEvent.ReadyCheckHeartbeat, PackData({ message = message }), GetMessageDestination())
end

function Private.ScheduleReadyCheckHeartbeat(message, delay, preventReadyCheckCallback)
Expand Down Expand Up @@ -801,7 +811,7 @@ function Private.DetectQueueCancelAfterConfirm(previousState, newState)
if previousState.status ~= QueueStatus.Confirm then return end
if newState.status ~= QueueStatus.None then return end

Module:SendCommMessage(CommunicationEvent.DeclineBattleground, '1', GetMessageDestination())
Module:SendCommMessage(CommunicationEvent.DeclineBattleground, PackData({}), GetMessageDestination())
Private.RestoreEntryButton()

if not IsLeaderOrAssistant('player') then return end
Expand Down
8 changes: 7 additions & 1 deletion Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ local GetPlayerAuraBySpellID = C_UnitAuras.GetPlayerAuraBySpellID
local UnitIsGroupLeader = UnitIsGroupLeader
local UnitIsGroupAssistant = UnitIsGroupAssistant
local UnitNameUnmodified = UnitNameUnmodified
local GetNormalizedRealmName = GetNormalizedRealmName
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
local UNKNOWNOBJECT = UNKNOWNOBJECT
local floor = math.floor
local ceil = math.ceil
local format = string.format
Expand Down Expand Up @@ -137,7 +139,11 @@ end

function Namespace.Utils.GetRealUnitName(unit)
local name, realm = UnitNameUnmodified(unit)
if realm == nil then return name end
if realm == nil then
realm = GetNormalizedRealmName()
-- can return nil during loading screen, UNKNOWNOBJECT resolves it later
if realm == nil then return UNKNOWNOBJECT end
end

return name .. '-' .. realm
end
Expand Down

0 comments on commit 86232bd

Please sign in to comment.