From 0cb0136d83610ce1342d53e3f60950801b65d752 Mon Sep 17 00:00:00 2001 From: Eric Frechette Date: Wed, 17 Apr 2024 22:39:08 -0500 Subject: [PATCH] send new raid roster history events to officers, handle receiving the events, housekeep timer --- CalamityEPGP/CalamityEPGP.toc | 2 +- CalamityEPGP/main.lua | 32 +++++++++++++++++++++++++++--- CalamityEPGP/sync.lua | 37 ++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/CalamityEPGP/CalamityEPGP.toc b/CalamityEPGP/CalamityEPGP.toc index 7728847..f720a9e 100644 --- a/CalamityEPGP/CalamityEPGP.toc +++ b/CalamityEPGP/CalamityEPGP.toc @@ -1,7 +1,7 @@ ## Title: CalamityEPGP ## Notes: EPGP addon for WOTLK ## Author: Kardiir-Atiesh -## Version: 0.20.2 +## Version: 0.21.0 ## Interface: 30403 ## SavedVariables: CalamityEPGP ## DefaultState: enabled diff --git a/CalamityEPGP/main.lua b/CalamityEPGP/main.lua index 99cfa23..83bce1a 100644 --- a/CalamityEPGP/main.lua +++ b/CalamityEPGP/main.lua @@ -286,6 +286,13 @@ function addon:init() self.clearAwarded() self.clearAwardedTimer = self:ScheduleRepeatingTimer(function() self.clearAwarded() end, 60) + self:housekeepRaidRosterHistory() + self.housekeepRaidRosterHistoryTimer = self:ScheduleRepeatingTimer(function() self:housekeepRaidRosterHistory() end, 600) + + table.sort(ns.db.raid.rosterHistory, function(left, right) + return left[1] < right[1] + end) + self:RegisterChatCommand('ce', 'handleSlashCommand') self:RegisterEvent('CHAT_MSG_SYSTEM', 'handleChatMsg') self:RegisterEvent('CHAT_MSG_PARTY', 'handleChatMsg') @@ -467,13 +474,17 @@ function addon:loadRaidRoster() ns.MainWindow:refresh() ns.RaidWindow:refresh() - if prevPlayers ~= self.raidRoster:len() and ns.Lib.isOfficer() then + if ns.Lib.isOfficer() and prevPlayers ~= self.raidRoster:len() then local ts = time() - local players = ns.Lib.deepcopy(self.raidRoster:keys()) + + local players = {} + for player in self.raidRoster:iter() do + ns.Lib.bininsert(players, player) + end tinsert(ns.db.raid.rosterHistory, {ts, players}) - -- TODO: sync to officers + ns.Sync:sendRosterHistoryEventToOfficers(ts, players) end end @@ -854,6 +865,21 @@ function addon:housekeepPeers() end +function addon:housekeepRaidRosterHistory() + local threshold = time() - 86400 -- 24 hours old + + local newRaidRosterHistory = {} + + for _, event in ipairs(ns.db.raid.rosterHistory) do + if event[1] > threshold then + tinsert(newRaidRosterHistory, event) + end + end + + ns.db.raid.rosterHistory = newRaidRosterHistory +end + + ---@param players table ---@param mode 'ep' | 'gp' ---@param value number diff --git a/CalamityEPGP/sync.lua b/CalamityEPGP/sync.lua index cd534b8..6386c5e 100644 --- a/CalamityEPGP/sync.lua +++ b/CalamityEPGP/sync.lua @@ -352,6 +352,15 @@ function Sync:sendLmSettingsToGuild() ns.Comm:send(ns.Comm.msgTypes.DATA_SEND, toSend, 'GUILD') end +---@param ts number +---@param players table +function Sync:sendRosterHistoryEventToOfficers(ts, players) + local event = {ts, players} + local toSend = {{}, {}, {event}} + + ns.Comm:send(ns.Comm.msgTypes.DATA_SEND, toSend, 'GUILD') +end + function Sync.handleSync0(message, sender) -- if we are both guildies, drop the message @@ -625,6 +634,8 @@ function Sync.handleDataSend(message, sender) local events = data[1] ---@type table? local lmSettings = data[2] + ---@type table? + local raidRosterHistoryEvents = data[3] local recompute = false local sortedEvents = {} @@ -663,7 +674,7 @@ function Sync.handleDataSend(message, sender) Sync:computeIndices() end - if lmSettings ~= nil then + if lmSettings ~= nil and #lmSettings > 0 then ns.debug(('received lmSettings from %s'):format(sender)) local newSyncAltEp = lmSettings[3] @@ -700,6 +711,30 @@ function Sync.handleDataSend(message, sender) ns.addon:computeStandings() end end + + if ns.Lib.isOfficer() and raidRosterHistoryEvents ~= nil and #raidRosterHistoryEvents > 0 then + local fcomp = function(left, right) + return left[1] < right[1] + end + + for _, newEvent in ipairs(raidRosterHistoryEvents) do + ns.Lib.bininsert(ns.db.raid.rosterHistory, newEvent, fcomp) + end + + -- initialize with first event + local newHistory = {ns.db.raid.rosterHistory[1]} + + for i = 2, #ns.db.raid.rosterHistory do + local prevEvent = ns.db.raid.rosterHistory[i - 1] + local thisEvent = ns.db.raid.rosterHistory[i] + + if prevEvent[2] ~= thisEvent[2] then + tinsert(newHistory, thisEvent) + end + end + + ns.db.raid.rosterHistory = newHistory + end end