Skip to content

Commit

Permalink
send new raid roster history events to officers, handle receiving the…
Browse files Browse the repository at this point in the history
… events, housekeep timer
  • Loading branch information
Frechetta committed Apr 18, 2024
1 parent a2ddb70 commit 0cb0136
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CalamityEPGP/CalamityEPGP.toc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 29 additions & 3 deletions CalamityEPGP/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
37 changes: 36 additions & 1 deletion CalamityEPGP/sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 0cb0136

Please sign in to comment.