Phase 2: enrich passive player cache from chat GUIDs
This commit is contained in:
+55
-9
@@ -1,6 +1,7 @@
|
|||||||
local _G = ShaguTweaks.GetGlobalEnv()
|
local _G = ShaguTweaks.GetGlobalEnv()
|
||||||
local GetExpansion = ShaguTweaks.GetExpansion
|
local GetExpansion = ShaguTweaks.GetExpansion
|
||||||
local L = ShaguTweaks.L
|
local L = ShaguTweaks.L
|
||||||
|
local API = ShaguTweaks.API
|
||||||
|
|
||||||
local units = { players = {}, mobs = {} }
|
local units = { players = {}, mobs = {} }
|
||||||
local queue = { }
|
local queue = { }
|
||||||
@@ -8,11 +9,37 @@ local PASSIVE_CACHE_TTL = 90 * 24 * 60 * 60
|
|||||||
|
|
||||||
local libunitscan = CreateFrame("Frame", "ShaguTweaksUnitScan", UIParent)
|
local libunitscan = CreateFrame("Frame", "ShaguTweaksUnitScan", UIParent)
|
||||||
|
|
||||||
|
local function EnrichPlayerFromClassicAPI(name)
|
||||||
|
if not name or not API or not API.GetCachedPlayerInfoByName then return end
|
||||||
|
|
||||||
|
local _, class, _, _, _, cachedName, _, guid = API.GetCachedPlayerInfoByName(name)
|
||||||
|
if not class and not guid then return end
|
||||||
|
|
||||||
|
local key = cachedName and cachedName ~= "" and cachedName or name
|
||||||
|
units.players[key] = units.players[key] or {}
|
||||||
|
units.players[key].class = class or units.players[key].class
|
||||||
|
units.players[key].guid = guid or units.players[key].guid
|
||||||
|
|
||||||
|
return key
|
||||||
|
end
|
||||||
|
|
||||||
function ShaguTweaks.GetUnitData(name, active)
|
function ShaguTweaks.GetUnitData(name, active)
|
||||||
if units["players"][name] then
|
if units["players"][name] then
|
||||||
|
if not units["players"][name].class then
|
||||||
|
EnrichPlayerFromClassicAPI(name)
|
||||||
|
end
|
||||||
|
|
||||||
local ret = units["players"][name]
|
local ret = units["players"][name]
|
||||||
return ret.class, ret.level, ret.elite, true
|
return ret.class, ret.level, ret.elite, true
|
||||||
elseif units["mobs"][name] then
|
elseif API and API.GetCachedPlayerInfoByName then
|
||||||
|
local key = EnrichPlayerFromClassicAPI(name)
|
||||||
|
if key and units["players"][key] then
|
||||||
|
local ret = units["players"][key]
|
||||||
|
return ret.class, ret.level, ret.elite, true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if units["mobs"][name] then
|
||||||
local ret = units["mobs"][name]
|
local ret = units["mobs"][name]
|
||||||
return ret.class, ret.level, ret.elite, nil
|
return ret.class, ret.level, ret.elite, nil
|
||||||
elseif active then
|
elseif active then
|
||||||
@@ -21,12 +48,13 @@ function ShaguTweaks.GetUnitData(name, active)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function AddData(db, name, class, level, elite)
|
local function AddData(db, name, class, level, elite, guid)
|
||||||
if not name then return end
|
if not name then return end
|
||||||
units[db][name] = units[db][name] or {}
|
units[db][name] = units[db][name] or {}
|
||||||
units[db][name].class = class or units[db][name].class
|
units[db][name].class = class or units[db][name].class
|
||||||
units[db][name].level = level or units[db][name].level
|
units[db][name].level = level or units[db][name].level
|
||||||
units[db][name].elite = elite or units[db][name].elite
|
units[db][name].elite = elite or units[db][name].elite
|
||||||
|
units[db][name].guid = guid or units[db][name].guid
|
||||||
queue[name] = nil
|
queue[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,9 +65,23 @@ local function RememberPlayer(name)
|
|||||||
ShaguTweaks_cache["players"] = ShaguTweaks_cache["players"] or {}
|
ShaguTweaks_cache["players"] = ShaguTweaks_cache["players"] or {}
|
||||||
units.players = ShaguTweaks_cache["players"]
|
units.players = ShaguTweaks_cache["players"]
|
||||||
|
|
||||||
units.players[name] = units.players[name] or {}
|
-- ClassicAPI exposes the GUID of the CHAT_MSG_* sender synchronously.
|
||||||
units.players[name].lastseen = date("%a %d-%b-%Y")
|
-- Resolve class/name from the engine's existing name cache only: this is a
|
||||||
units.players[name].lastseen_ts = time()
|
-- pure cache read and never sends a /who or any other network query.
|
||||||
|
local guid = API and API.GetCurrentChatGUID and API.GetCurrentChatGUID()
|
||||||
|
local class, cachedName
|
||||||
|
if guid and API.GetPlayerInfoByGUID then
|
||||||
|
local _, apiClass, _, _, _, apiName = API.GetPlayerInfoByGUID(guid)
|
||||||
|
class = apiClass
|
||||||
|
cachedName = apiName
|
||||||
|
end
|
||||||
|
|
||||||
|
local key = cachedName and cachedName ~= "" and cachedName or name
|
||||||
|
units.players[key] = units.players[key] or {}
|
||||||
|
units.players[key].class = class or units.players[key].class
|
||||||
|
units.players[key].guid = guid or units.players[key].guid
|
||||||
|
units.players[key].lastseen = date("%a %d-%b-%Y")
|
||||||
|
units.players[key].lastseen_ts = time()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function PrunePassivePlayers()
|
local function PrunePassivePlayers()
|
||||||
@@ -99,7 +141,8 @@ libunitscan:SetScript("OnEvent", function()
|
|||||||
local name = UnitName("player")
|
local name = UnitName("player")
|
||||||
local _, class = UnitClass("player")
|
local _, class = UnitClass("player")
|
||||||
local level = UnitLevel("player")
|
local level = UnitLevel("player")
|
||||||
AddData("players", name, class, level)
|
local guid = API and API.UnitGUID and API.UnitGUID("player")
|
||||||
|
AddData("players", name, class, level, nil, guid)
|
||||||
|
|
||||||
elseif passiveChatEvents[event] then
|
elseif passiveChatEvents[event] then
|
||||||
-- Passive cache only: remember speakers already delivered by the client.
|
-- Passive cache only: remember speakers already delivered by the client.
|
||||||
@@ -129,7 +172,8 @@ libunitscan:SetScript("OnEvent", function()
|
|||||||
for i = 1, GetNumRaidMembers() do
|
for i = 1, GetNumRaidMembers() do
|
||||||
name, _, SubGroup, level, class = GetRaidRosterInfo(i)
|
name, _, SubGroup, level, class = GetRaidRosterInfo(i)
|
||||||
class = L["class"][class] or nil
|
class = L["class"][class] or nil
|
||||||
AddData("players", name, class, level)
|
local guid = API and API.UnitGUID and API.UnitGUID("raid" .. i)
|
||||||
|
AddData("players", name, class, level, nil, guid)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event == "PARTY_MEMBERS_CHANGED" then
|
elseif event == "PARTY_MEMBERS_CHANGED" then
|
||||||
@@ -139,7 +183,8 @@ libunitscan:SetScript("OnEvent", function()
|
|||||||
_, class = UnitClass(unit)
|
_, class = UnitClass(unit)
|
||||||
name = UnitName(unit)
|
name = UnitName(unit)
|
||||||
level = UnitLevel(unit)
|
level = UnitLevel(unit)
|
||||||
AddData("players", name, class, level)
|
local guid = API and API.UnitGUID and API.UnitGUID(unit)
|
||||||
|
AddData("players", name, class, level, nil, guid)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event == "WHO_LIST_UPDATE" or event == "CHAT_MSG_SYSTEM" then
|
elseif event == "WHO_LIST_UPDATE" or event == "CHAT_MSG_SYSTEM" then
|
||||||
@@ -157,7 +202,8 @@ libunitscan:SetScript("OnEvent", function()
|
|||||||
_, class = UnitClass(scan)
|
_, class = UnitClass(scan)
|
||||||
level = UnitLevel(scan)
|
level = UnitLevel(scan)
|
||||||
name = UnitName(scan)
|
name = UnitName(scan)
|
||||||
AddData("players", name, class, level)
|
local guid = API and API.UnitGUID and API.UnitGUID(scan)
|
||||||
|
AddData("players", name, class, level, nil, guid)
|
||||||
else
|
else
|
||||||
_, class = UnitClass(scan)
|
_, class = UnitClass(scan)
|
||||||
elite = UnitClassification(scan)
|
elite = UnitClassification(scan)
|
||||||
|
|||||||
Reference in New Issue
Block a user