Skip to content

Commit

Permalink
Comms whispers change.
Browse files Browse the repository at this point in the history
Updated comms to also whisper any targets on a connected realm
  • Loading branch information
evil-morfar committed Jan 15, 2024
1 parent 9e73e9d commit 601f459
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Classes/Services/Comms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function private:SendComm(prefix, target, prio, callback, callbackarg, command,
-- Just Log and return
if not target.GetRealm then return Log:e("Invalid target:", target, serialized) end
if not target:GetRealm() then return Log:e("Couldn't get realm for target:", target, serialized) end
if target:GetRealm() == addon.realmName then -- Our realm
if addon.Utils:IsWhisperTarget(target) then
self.AceComm:SendCommMessage(prefix, encoded, "WHISPER", target:GetName(), prio, callback, callbackarg)
else
-- Remake command to be "xrealm" and put target and command in the table
Expand Down
7 changes: 7 additions & 0 deletions Utils/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ function Utils:GetLootThreshold()
end
end

--- Returns true if the target can receive addon messages from the whisper channel.
---@param target Player
function Utils:IsWhisperTarget(target)
if not target:GetGUID() then return false end
return C_PlayerInfo.UnitIsSameServer(_G.PlayerLocation:CreateFromGUID(target:GetGUID()))
end

---@deprecated
---@see Utils.Item.GetTransmittableItemString
function Utils:GetTransmittableItemString(link)
Expand Down
7 changes: 7 additions & 0 deletions __tests/wow_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local _G = getfenv(0)
require "/wow_api/API/Mixin"
require "/wow_api/API/Color"
require "/wow_api/API/TableUtil"
require "wow_api/API/PlayerLocation"
require "wow_api/FrameAPI/Constructor"
local strbyte, strchar, gsub, gmatch, format, tinsert = string.byte, string.char, string.gsub, string.gmatch,
string.format, table.insert
Expand Down Expand Up @@ -1037,6 +1038,12 @@ C_CreatureInfo = {
end,
}

C_PlayerInfo = {
UnitIsSameServer = function (target)
return false
end
}

UISpecialFrames = {}
_G.GameTooltip = CreateFrame("GameTooltip", "GameTooltip", UIParent)
------------------------------------------
Expand Down
193 changes: 193 additions & 0 deletions __tests/wow_api/API/PlayerLocation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
PlayerLocation = {};
PlayerLocationMixin = {};
--[[static]]
function PlayerLocation:CreateFromGUID(guid)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetGUID(guid);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromUnit(unit)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetUnit(unit);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromChatLineID(lineID)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetChatLineID(lineID);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromCommunityChatData(clubID, streamID, epoch, position)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetCommunityData(clubID, streamID, epoch, position);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromCommunityInvitation(clubID, guid)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetCommunityInvitation(clubID, guid);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromBattlefieldScoreIndex(battlefieldScoreIndex)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetBattlefieldScoreIndex(battlefieldScoreIndex);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromVoiceID(memberID, channelID)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetVoiceID(memberID, channelID);
return playerLocation;
end

--[[static]]
function PlayerLocation:CreateFromBattleNetID(battleNetID)
local playerLocation = CreateFromMixins(PlayerLocationMixin);
playerLocation:SetBattleNetID(battleNetID);
return playerLocation;
end

--[[public api]]
function PlayerLocationMixin:SetGUID(guid)
self:ClearAndSetField("guid", guid);
end

function PlayerLocationMixin:IsValid()
if self:IsGUID() then
return C_PlayerInfo.GUIDIsPlayer(self:GetGUID()) or C_AccountInfo.IsGUIDBattleNetAccountType(self:GetGUID());
elseif self:IsCommunityData() then
return C_Club.CanResolvePlayerLocationFromClubMessageData(self.communityClubID, self.communityStreamID,
self.communityEpoch, self.communityPosition);
elseif self:IsUnit() then
return UnitIsPlayer(self:GetUnit());
end
return true;
end

function PlayerLocationMixin:IsGUID()
return self.guid ~= nil;
end

function PlayerLocationMixin:IsBattleNetGUID()
return self.guid and C_AccountInfo.IsGUIDBattleNetAccountType(self.guid);
end

function PlayerLocationMixin:GetGUID()
return self.guid or self.communityClubInviterGUID;
end

function PlayerLocationMixin:SetUnit(unit)
self:ClearAndSetField("unit", unit);
end

function PlayerLocationMixin:IsUnit()
return self.unit ~= nil;
end

function PlayerLocationMixin:GetUnit()
return self.unit;
end

function PlayerLocationMixin:SetChatLineID(lineID)
self:ClearAndSetField("chatLineID", lineID);
end

function PlayerLocationMixin:IsChatLineID()
return self.chatLineID ~= nil;
end

function PlayerLocationMixin:GetChatLineID()
return self.chatLineID;
end

function PlayerLocationMixin:SetBattlefieldScoreIndex(index)
self:ClearAndSetField("battlefieldScoreIndex", index);
end

function PlayerLocationMixin:IsBattlefieldScoreIndex()
return self.battlefieldScoreIndex ~= nil;
end

function PlayerLocationMixin:GetBattlefieldScoreIndex()
return self.battlefieldScoreIndex;
end

function PlayerLocationMixin:SetVoiceID(memberID, channelID)
self:Clear();
self.voiceMemberID = memberID;
self.voiceChannelID = channelID;
end

function PlayerLocationMixin:IsVoiceID()
return self.voiceMemberID ~= nil and self.voiceChannelID ~= nil;
end

function PlayerLocationMixin:GetVoiceID()
return self.voiceMemberID, self.voiceChannelID;
end

function PlayerLocationMixin:SetBattleNetID(battleNetID)
self:Clear();
self.battleNetID = battleNetID;
end

function PlayerLocationMixin:IsBattleNetID()
return self.battleNetID ~= nil;
end

function PlayerLocationMixin:GetBattleNetID()
return self.battleNetID;
end

function PlayerLocationMixin:SetCommunityData(clubID, streamID, epoch, position)
self:Clear();
self.communityClubID = clubID;
self.communityStreamID = streamID;
self.communityEpoch = epoch;
self.communityPosition = position;
end

function PlayerLocationMixin:IsCommunityData()
return self.communityClubID ~= nil and self.communityStreamID ~= nil and self.communityEpoch ~= nil and
self.communityPosition ~= nil;
end

function PlayerLocationMixin:SetCommunityInvitation(clubID, guid)
self:Clear();
self.communityClubID = clubID;
self.communityClubInviterGUID = guid;
end

function PlayerLocationMixin:IsCommunityInvitation()
return self.communityClubID ~= nil and self.communityClubInviterGUID ~= nil;
end

--[[private api]]
function PlayerLocationMixin:Clear()
self.guid = nil;
self.unit = nil;
self.chatLineID = nil;
self.battlefieldScoreIndex = nil;
self.voiceMemberID = nil;
self.voiceChannelID = nil;
self.communityClubID = nil;
self.communityStreamID = nil;
self.communityEpoch = nil;
self.communityPosition = nil;
self.communityClubInviterGUID = nil;
self.battleNetID = nil;
end

function PlayerLocationMixin:ClearAndSetField(fieldName, field)
self:Clear();
self[fieldName] = field;
end

0 comments on commit 601f459

Please sign in to comment.