Skip to content

Commit

Permalink
Merge branch 'release/3.10.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
evil-morfar committed Jan 17, 2024
2 parents db578ce + af74bfc commit e934775
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 8 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -165,7 +165,7 @@ function private.ReceiveComm(prefix, encodedMsg, distri, sender)
local decoded = ld:DecodeForWoWAddonChannel(encodedMsg)
local decompressed = ld:DecompressDeflate(decoded)
Log:f("<Comm>", decompressed, distri, senderName)
local test, command, data = self:Deserialize(decompressed)
local test, command, data = self:Deserialize(decompressed or "")
if not test then
-- luacov: disable
return Log:e("<Comm>", "Deserialization failed with:", decompressed)
Expand Down
5 changes: 4 additions & 1 deletion Classes/Utils/GroupLoot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function GroupLoot:OnStartLootRoll(_, rollID)
if not addon.enabled then return self.Log:d("Addon disabled, ignoring group loot") end
local link = GetLootRollItemLink(rollID)
local _, _, _, quality, _, canNeed, _, _, _, _, _, _, canTransmog = GetLootRollItemInfo(rollID)
if not link then return end -- Sanity check
if not link then -- Sanity check
self.Log:d("No link!", rollID)
return
end
if quality and quality >= Enum.ItemQuality.Legendary then
self.Log:d("Ignoring legendary quality:", quality)
return
Expand Down
6 changes: 3 additions & 3 deletions RCLootCouncil.toc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Author: Potdisc
## Interface: 100200
## Notes: Interface for running a Loot Council v3.10.4
## Interface: 100205
## Notes: Interface for running a Loot Council v3.10.5
## Title: RCLootCouncil
## Version: 3.10.4
## Version: 3.10.5
## SavedVariables: RCLootCouncilDB, RCLootCouncilLootDB
## OptionalDeps: LibStub, CallbackHandler-1.0, Ace3, lib-st, LibWindow-1.1, LibDialog-1.0
## X-Curse-Project-ID: 39928
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
119 changes: 119 additions & 0 deletions __tests/SavedVariables/CommsAnalysis.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
local Analysis = {}
dofile "__tests/wow_api.lua"

local function RunAnalysis()
dofile "__tests/SavedVariables/sv_to_process.lua"
local comms = Analysis:ExtractCommsLinesFromSV(_G.RCLootCouncilDB["global"]["log"])
local commsAnalyzed = Analysis:AnalyzeComms(comms)
commsAnalyzed = Analysis:PerformStatistics(commsAnalyzed)
Analysis:PrintResults(commsAnalyzed)
local commsAnalyzed2 = Analysis:AnalyzeComms(comms, true)
commsAnalyzed2 = Analysis:PerformStatistics(commsAnalyzed2)
Analysis:PrintResults(commsAnalyzed2)
end

---@param sv string[]
---@return string[]
function Analysis:ExtractCommsLinesFromSV(sv)
-- "<20:49:32> <Comm> ^1^Scouncil_request^T^t^^ WHISPER Denzema-TarrenMill", -- [10]
local ret = {}
for _, v in ipairs(sv) do
if (v:find("<Comm>")) then
tinsert(ret, v:match("(%^1.+%^%^)"))
end
end
return ret
end

---@alias AnalyzedComms table<string, number[]>

---@param comms string[]
---@return AnalyzedComms
function Analysis:AnalyzeComms(comms, useCompressed)
local ret = {}
--- @param line string
local function ExtractCommand(line)
return line:match("%^1%^S(.-)%^")
end
dofile("Libs/LibStub/LibStub.lua")
dofile("Libs/LibDeflate/LibDeflate.lua")
local LibDef = LibStub("LibDeflate")
local compressLvl = { level = 3, }
for i, v in ipairs(comms) do
local cmd = ExtractCommand(v)
if not ret[cmd] then ret[cmd] = {} end
tinsert(ret[cmd],
useCompressed and #LibDef:EncodeForWoWAddonChannel(LibDef:CompressDeflate(v, compressLvl)) or #v)
end

return ret
end

---@alias AnalysisResult table<int, {min:number,name:string, max:number, average:number, count:int}>

---@param comms AnalyzedComms
---@return AnalysisResult
function Analysis:PerformStatistics(comms)
local ret = {}
---@param t number[]
---@param max boolean
local function minMax(t, max)
local min = max and 0 or math.huge
for _, v in ipairs(t) do
if (max and v > min) or (not max and v < min) then min = v end
end
return min
end

---@param t number[]
local function average(t)
local num = 0
for _, v in ipairs(t) do
num = num + v
end
return num / #t
end

for i, v in pairs(comms) do
tinsert(ret, {
name = i,
min = minMax(v, false),
max = minMax(v, true),
average = average(v),
count = #v,
})
end
table.sort(ret, function(a, b)
return a.count > b.count
end)
return ret
end

---@param analysis AnalysisResult
function Analysis:PrintResults(analysis)
print(string.format("%-17s count min \t max \t average msg \t p.msg", "name"))
print "---------------------------------------------------------------"
local totals = { count = 0, min = 0, max = 0, average = 0, msg = 0, pmsg = 0, }
for _, v in ipairs(analysis) do
local msg = v.average / 255
local pmsg = 1 / msg
print(string.format("%-17s %d \t %d \t %d \t %d \t %.2f \t %.2f", v.name, v.count, v.min, v.max, v.average,
msg, pmsg))
totals.count = totals.count + v.count
totals.min = totals.min + v.min * v.count
totals.max = totals.max + v.max * v.count
totals.average = totals.average + v.average * v.count
totals.msg = totals.msg + msg * v.count
totals.pmsg = totals.pmsg + pmsg * v.count
end
print "---------------------------------------------------------------"
print(string.format("Total: \t\t%d \t%.2f \t%.2f \t%.2f \t%.2f \t%.2f",
totals.count,
totals.min/totals.count,
totals.max / totals.count,
totals.average/totals.count,
totals.msg / totals.count,
totals.pmsg / totals.count))
end

RunAnalysis()
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
Loading

0 comments on commit e934775

Please sign in to comment.