Thread Tools Display Modes
12-30-14, 01:57 AM   #1
BlueRaja
A Defias Bandit
Join Date: Dec 2014
Posts: 3
Is there a way to order event callbacks (by plugin)?

I'm extending a chat-filter plugin to work with several other chat-based plugins. The other plugins handle the "CHAT_MSG_CHANNEL" event, and return true, indicating they've handled the message and (I assume) stopping the event from bubbling to other plugins.

In order to filter these messages, I need to handle them before the other plugins. Is there some way of guaranteeing the order that events are passed to plugins?
  Reply With Quote
12-30-14, 06:25 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) Chat filters are processed in the order registered. There's no way to tell WoW to load your addon before some other addon (without modifying the other addon to list your addon as an optional dependency). If you really need to run your filters first (though I'm not really sure why; if you have some other addon blocking messages, it's still going to block messages if its filter gets run after yours) then depending on the addon it may be possible to remove and re-add its filter (thus moving it to the end of the list) or you can take the nuclear approach and remove all other filters for the given event(s) and re-add them.

2) Returning true means the filter has blocked the message, and prevents any further processing for that message, including other filters.

3) Returning false or nil means the filter did not block the message, and filters continue to be run in order.

3b) If a filter returns any arguments in addition to false/nil it must return all of the event arguments that were passed into it (note that the first two arguments it receives are not event arguments and should not be returned) but it may modify them, and they replace the original event arguments. Additional filters are called with these new event arguments.

You can see how the default UI does this in FrameXML/ChatFrame.lua.

Finally, I assume you're talking about Trade Chat Cleaner since you just submitted some patches for it (thanks BTW) but I'm not really sure why you'd need it to run before other addons. Like I said, if you have some other addon blocking stuff, that stuff will still be blocked no matter what order the filters are run in.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-30-14, 10:59 AM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
What kind of goal do you have for your addon that you need to watch every chat message unfiltered? It's still possible, (using "Phanx's nuclear approach") but I guess It'd be nice if there was some kind of way to register for unfiltered events, similar to how combat logging events can be unfiltered (CLEU).
  Reply With Quote
12-30-14, 11:49 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ravagernl View Post
It'd be nice if there was some kind of way to register for unfiltered events, similar to how combat logging events can be unfiltered (CLEU).
You can. Just register for the events directly instead of adding filters for them.

Also, the OP submitted this pull request which leads me to believe they're having some kind of compatibility issue with TradeForwarder. I haven't looked at the code of that addon yet, but after reading your post it occurs to me that the problem OP is trying to solve may be that TradeForwarder is using filters instead of normal event registrations and therefore isn't working with my addon which uses filters for their intended purpose of filtering messages. But, until OP clarifies, or I have time to look at the other addon's code, who knows.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-30-14 at 11:54 AM.
  Reply With Quote
12-30-14, 12:03 PM   #5
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Phanx View Post
[...] which leads me to believe they're having some kind of compatibility issue with TradeForwarder. I haven't looked at the code of that addon yet, but after reading your post it occurs to me that the problem OP is trying to solve may be that TradeForwarder is using filters instead of normal event registrations and therefore isn't working with my addon which uses filters for their intended purpose of filtering messages. But, until OP clarifies, or I have time to look at the other addon's code, who knows.
I see. I'm presuming TradeForwarder uses filters for outgoing messages because nobody wants to see their own echo's, or when in city, echo's from other users.

You can. Just register for the events directly instead of adding filters for them.
/selfpalm I can say that I'm glad to be off till the 5th. It's been a long week for me (am I spoiled?)

Last edited by ravagernl : 12-30-14 at 12:07 PM.
  Reply With Quote
12-30-14, 03:51 PM   #6
BlueRaja
A Defias Bandit
Join Date: Dec 2014
Posts: 3
TradeForwarder is a plugin that allows you to view Trade-Channel messages no matter where you are. It works by having people who are in town forward the trade-messages to a hidden channel. TradeForwarder then subscribes to that hidden channel, blocks all the messages from that channel from being seen, and parses/displays the messages manually.

So, the problem is that if TradeForwarder handles the messages before TradeChatCleaner, then TradeChatCleaner never gets a chance to filter them, and every trade messages is displayed. If TradeChatCleaner goes first, it can filter the ones I don't want to see before TradeForwarder sees them.

Last edited by BlueRaja : 12-30-14 at 03:54 PM.
  Reply With Quote
12-30-14, 06:05 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by BlueRaja View Post
So, the problem is that if TradeForwarder handles the messages before TradeChatCleaner, then TradeChatCleaner never gets a chance to filter them, and every trade messages is displayed. If TradeChatCleaner goes first, it can filter the ones I don't want to see before TradeForwarder sees them.
That doesn't really make sense, or I'm not understanding the problem... if TradeForwarder says "block this message", it doesn't matter if it says that before or after TCC says "this message is OK" -- in either order, the message gets blocked, as I explained in my earlier post. Likewise, if TF says "this message is OK" but TCC says "block this message" it still doesn't matter what order that happens in -- the message is blocked if any filter says to block it, even if 1000000000 other filters said it was OK first. Every single filter is checked until either one filter says "block this" or there are no more filters to check.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-30-14, 06:51 PM   #8
BlueRaja
A Defias Bandit
Join Date: Dec 2014
Posts: 3
Trade Forwarder prints the message itself and tells WoW to block the message.

Trade Forwarder gets loaded first:
Trade Forwarder: Parses the message, prints it to chat. Tells WoW to block the message.
Trade Chat Cleaner: Never sees the message.
Result: Message gets printed.

Trade Chat Cleaner gets loaded first:
Trade Chat Cleaner: Blocks the message.
Trade Forwarder: Never sees the message.
Result: Message gets blocked.

I'm not sure how I can make this any clearer.
  Reply With Quote
12-30-14, 07:49 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, I'm just not going to be able to help until I have the time and motivation to dig through someone else's addon code, because this is just not how chat filters work:

Originally Posted by BlueRaja View Post
Trade Forwarder gets loaded first:
Trade Forwarder: Parses the message, prints it to chat. Tells WoW to block the message.
Trade Chat Cleaner: Never sees the message.
Result: Message gets printed.
If that's really what's happening, then Trade Forwarder is not using chat filters, or at least not using them correctly. Go look at the default UI code in ChatFrame.lua where it handles filtering.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-01-15, 05:07 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Alright, after installing Trade Forwarder and glancing through it's code, I think I finally understand what problem you're complaining about, and why it's happening. When you're in town, and Trade Forwarder is forwarding messages you see in Trade to its custom channel, everything seems to be working correctly:

1. Trade Chat Cleaner sees the message in Trade channel via a chat filter, and either blocks it or lets it pass.
2. Trade Forwarder sees the message in Trade channel via an event handler (which is not affected by filters) and sends it to the custom channel.
3. Trade Chat Cleaner sees the message in the custom channel via a chat filter, and lets it pass, because it doesn't apply any filtering to custom channels.

The problem happens when you are out of town, when messages forwarded to you from other players are getting shown in your chat frame, even though Trade Chat Cleaner would hide them if they were really in Trade chat. The reason this is happening is that Trade Forwarder is (as suspected) not using chat filters correctly. It's using them incorrectly in a different way that I thought, but it's still incorrect.

What it's doing is getting a list of chat filters for the CHAT_MSG_CHANNEL event and calling them, just like would normally happen for a channel message, but the arguments it's passing to the filters are wrong -- it's passing the name and number of its own custom channel instead of the name and number of the Trade channel, so as far as Trade Chat Cleaner or any other filtering addon is concerned, the message is not in the Trade channel.

The ideal solution for this problem would be for Trade Forwarder to do a better job of emulating the Trade channel. This could be done in one of two ways:

1) Pass better arguments to the chat filters so that messages actually get filtered like Trade chat messages, instead of like custom channel messages.

2) Just call ChatFrame_MessageEventHandler (with appropriate arguments) instead of handling all this itself.

Additionally, Trade Forwarder should probably update to using SendAddonMessage instead of SendChatMessage to do its forwarding; as of 6.0 "CHANNEL" is a viable target for SendAddonMessage (see this and this). This way it wouldn't have to worry about hiding its own messages from the chat frame.

In any case, Trade Chat Cleaner is working exactly as it should, and I don't plan to add any special checks to work around other addons' idiosyncracies.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 01-01-15 at 05:14 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Is there a way to order event callbacks (by plugin)?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off