diff --git a/Freewood-OctoWoW-Beasts.toc b/Freewood-OctoWoW-Beasts.toc index a00bced..470529d 100644 --- a/Freewood-OctoWoW-Beasts.toc +++ b/Freewood-OctoWoW-Beasts.toc @@ -3,7 +3,7 @@ ## Notes: Archive of wild beasts: where they live, what they eat, what taming teaches. Learns while you play, with export and import. ## Notes-deDE: Archiv wilder Tiere: wo sie leben, was sie fressen, was das Zähmen lehrt. Lernt beim Spielen, mit Export und Import. ## Author: Lacustat -## Version: 0.1.163 +## Version: 0.1.164 ## Dependencies: Freewood-OctoWoW-Core, Freewood-OctoWoW-Pet ## OptionalDeps: Freewood-OctoWoW-BeastsData, Freewood-OctoWoW-Codex diff --git a/Sync.lua b/Sync.lua index 5961cda..59d1f69 100644 --- a/Sync.lua +++ b/Sync.lua @@ -1151,9 +1151,55 @@ function Sync:OnAddonMessage(prefix, text, channel, sender) end return end + if type(text) == "string" and text:sub(1, 2) == "G|" then + self:HandleBye(sender) + return + end self:HandleMessage(channel, sender, text) end +-- Ein Spieler meldet sich ab: ihm nichts mehr senden, Warteschlange fuer ihn leeren +function Sync:HandleBye(sender) + local name = KeyOf(sender) + if not name or IsSelf(sender) then return end + state.peers[name] = nil + state.sessions[name] = nil + state.served[name] = nil + local q = state.queue + for i = #q, 1, -1 do + local item = q[i] + if not item.bn then + local who = tostring(item.text or ""):match("^%a|([^|]+)|") + if who and KeyOf(who) == name then table.remove(q, i) end + end + end +end + +-- Beim Ausloggen/Beenden "Tschuess" in den Kanal (an der Warteschlange vorbei) +function Sync:SayBye() + if not self.started or not self:AnyEnabled() then return end + local dist, target = self:Distribution("global") + if dist then Raw(dist, target, "G|") end + state.queue = {} +end + +local byeHooked = false +local function InstallByeHooks() + if byeHooked then return end + byeHooked = true + if _G.hooksecurefunc then + for _, fn in ipairs({ "Logout", "Quit" }) do + if type(_G[fn]) == "function" then pcall(hooksecurefunc, fn, function() Sync:SayBye() end) end + end + end + for _, ev in ipairs({ "PLAYER_QUITING", "PLAYER_CAMPING", "PLAYER_LOGOUT" }) do + pcall(FW.RegisterEvent, FW, ev, function() Sync:SayBye() end, Sync) + end + pcall(FW.RegisterEvent, FW, "CANCEL_LOGOUT", function() + if Sync.started then C_Timer.After(2, function() Sync:SendHello() end) end + end, Sync) +end + -- Nachricht eines Battle.net-Freundes function Sync:OnBNMessage(prefix, text, _, senderID) if prefix ~= PREFIX then @@ -1205,6 +1251,7 @@ function Sync:Start() FW:RegisterEvent("GROUP_ROSTER_UPDATE", self.OnGroupChanged, self) FW:RegisterEvent("BN_CHAT_MSG_ADDON", self.OnBNMessage, self) FW:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE", self.OnFriendOnline, self) + InstallByeHooks() FW:On("BEASTS_UPDATED", function(_, id) if id then Sync:QueueAnnounce(id)