Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove filtering of 'Player is offline' messages #57

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ read_globals = {
"C_BattleNet.GetGameAccountInfoByID",
"C_ChatInfo.IsAddonMessagePrefixRegistered",
"C_ChatInfo.RegisterAddonMessagePrefix",
"ChatFrame_AddMessageEventFilter",
"CreateFrame",
"ERR_CHAT_PLAYER_NOT_FOUND_S",
"FULL_PLAYER_NAME",
"GetAutoCompleteRealms",
"GetNetStats",
"GetRealmName",
"GetTime",
"hooksecurefunc",
"IsLoggedIn",
"LE_PARTY_CATEGORY_HOME",
"LE_REALM_RELATION_COALESCED",
Expand Down
80 changes: 1 addition & 79 deletions Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]

local VERSION = 26
local VERSION = 28

if IsLoggedIn() then
error(("Chomp Message Library (embedded: %s) cannot be loaded after login."):format((...)))
Expand Down Expand Up @@ -250,81 +250,6 @@ function Internal:TriggerEvent(event, ...)
return self.callbacks:Fire(event, ...)
end

--[[
FUNCTION HOOKS
]]

-- Hooks don't trigger if the hooked function errors, so there's no need to
-- check parameters, if those parameters cause errors (which most don't now).

local FILTER_PATTERN = ERR_CHAT_PLAYER_NOT_FOUND_S:format("(.+)")
local lastFilteredLineID = nil

if not Internal.MessageFilterKeyCache then
Internal.MessageFilterKeyCache = {}
end

local function GenerateMessageFilterKey(target)
-- Due to systemic issues across ourselves, LibMSP, TRP, etc. this
-- filter has been hacked to only use the character name of the player
-- and to discard the realm.

local filterKey = string.split("-", target, 2)

if string.utf8lower then
filterKey = string.utf8lower(filterKey)
else
filterKey = string.lower(filterKey)
end

return filterKey
end

setmetatable(Internal.MessageFilterKeyCache, {
__index = function(self, target)
local filterKey = GenerateMessageFilterKey(target)
self[target] = filterKey
return filterKey
end,
})

local function MessageEventFilter_SYSTEM (self, event, text, ...)
local name = text:match(FILTER_PATTERN)
if not name then
return false
end

local filterKey = Internal.MessageFilterKeyCache[name]

if not Internal.Filter[filterKey] or Internal.Filter[filterKey] < GetTime() then
Internal.Filter[filterKey] = nil
return false
end

local lineID = select(10, ...)

if lineID ~= lastFilteredLineID then
Internal:TriggerEvent("OnError", name)
lastFilteredLineID = lineID
end

return true
end

local function HookSendAddonMessage(prefix, text, kind, target)
if kind == "WHISPER" and target then
local filterKey = Internal.MessageFilterKeyCache[target]
Internal.Filter[filterKey] = GetTime() + (select(3, GetNetStats()) * 0.001) + 5.000
end
end

local function HookSendAddonMessageLogged(prefix, text, kind, target)
if kind == "WHISPER" and target then
local filterKey = Internal.MessageFilterKeyCache[target]
Internal.Filter[filterKey] = GetTime() + (select(3, GetNetStats()) * 0.001) + 5.000
end
end

--[[
BATTLE.NET WRAPPER API
]]
Expand Down Expand Up @@ -469,9 +394,6 @@ Internal:SetScript("OnEvent", function(self, event, ...)
Internal:UpdateBattleNetAccountData()
elseif event == "PLAYER_LOGIN" then
_G.__chomp_internal = nil
hooksecurefunc(C_ChatInfo, "SendAddonMessage", HookSendAddonMessage)
hooksecurefunc(C_ChatInfo, "SendAddonMessageLogged", HookSendAddonMessageLogged)
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", MessageEventFilter_SYSTEM)
self.SameRealm = {}
self.SameRealm[(GetRealmName():gsub("[%s%-]", ""))] = true
for i, realm in ipairs(GetAutoCompleteRealms()) do
Expand Down