Custom Extension+Filter

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
ifernandez
Posts: 21
Joined: 16 Jul 2010, 17:02

Custom Extension+Filter

Post by ifernandez »

Hello,

Im trying to solve a problem with a custom extension i developed.

Right now I have a custom extension working, registered a custom request handler, using Multi Handler like suggested in the documentation.

The problem is that i want to create a custom filter for messages, read the docs about filters and events subscribing in custom extensions.

I have a filter set up for my extension, the filter is initializing, but is not intercepting calls made for messages like i want it to do.

Added event handlers for the required messages int he init method for the extension like this:

Code: Select all


addRequestHandler("myextension", MyExtensionRequestsHandler.class);
addFilter("myextension", new MyExtensionFilter());

addEventHandler(SFSEventType.PRIVATE_MESSAGE, 
MessageEventHandler.class);
		addEventHandler(SFSEventType.PUBLIC_MESSAGE, MessageEventHandler.class);
In the client im using to send the message:

Code: Select all

AS3:
smartfox.send(new PublicMessageRequest(message));		

But the MessageEventHandler class is not receiving any input in those cases. I think i'm missing some point of integration with SmartFox server
but i cant figure out what is missing.

In the log when a call is send to mu extension the line appears like:

Code: Select all

24 mar 2011 15:14:51,492 INFO  [com.smartfoxserver.v2.controllers.ExtensionController-1] Extensions     - {MyServerExtension}: XXXXXXXX
But when sending a message the corresponding log line is like

Code: Select all

24 mar 2011 15:15:12,207 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] v2.controllers.SystemController     - {IN}: GenericMessage
Thanks for the help
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Maybe the filter is preventing the message to be passed to the MessageEventHandler class?
Paolo Bax
The SmartFoxServer Team
ifernandez
Posts: 21
Joined: 16 Jul 2010, 17:02

Post by ifernandez »

I have added tracing in the filter as well as the event handler.

commented out all the code in the filter to see what is happening, and always returning:

Code: Select all

return FilterAction.CONTINUE;
Still the request seems to somehow pass through directly to the system extension without passing through my extension, i see the lines for the Filter, Event Handler, and Custom extension initialization in the server log, but nothing when the private, or public message is send to the server.

I don't know if this changes things but im using OpenSpace extension as a base, i use Smartfox Server +OpenSpace 2 in my project, so instead of inheriting from SFSExtension my extension inherits from OpenSpaceExtension.

thanks,

Ivan
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Filters work for Extension requests not for generic System requests such as Public Message, is this clear to you?

If you want to customize the Public Message you will need to:

1- send a custom req from client to your extension
2- implement your custom logic
3- finally invoke sendPublicMessage from the SFSApi object
4- (optional) disallow clients to use PublicMessageRequest directly, via the Permission management
Lapo
--
gotoAndPlay()
...addicted to flash games
ifernandez
Posts: 21
Joined: 16 Jul 2010, 17:02

Post by ifernandez »

I knew i was missing something,

thanks this is the response i was looking for, ill try implementing this and let you know if i have any further trouble.
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Post by Democre »

Lapo wrote:Filters work for Extension requests not for generic System requests such as Public Message, is this clear to you?
Lapo I would suggest changing the documentation, as it seems to contradict what you said.

Advanced Topics->Server-ide Extensions@Extension Filters
in the first paragraph:
they are executed in a chain and they can be used to log, filter, or handle specific requests or events before they get to the Extension itself.
in second paragraph:
Another example of usage would be logging or filtering public and private messages.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Sure, you are correct.
In that case it would be appropriate to register for a specific server event.
Updated.

thnx
Lapo
--
gotoAndPlay()
...addicted to flash games
karfau
Posts: 25
Joined: 02 Sep 2011, 17:28

Post by karfau »

The Page mentioned above still talks about filtering public/private Messages in the code-examples.

Has this changed, so that it is possible to apply a Filter to public or private messages whithout writing an extensionrequest?

If not, maybe this should be more clear in the docs what limitations apply to the filters.
Post Reply