Page 1 of 1

BadWords filter extension

Posted: 11 Jul 2011, 08:49
by BadUser
Hello. May be this is a common topic, but i haven't found the answer for it, so, gonna ask here.

I'm going to create some extension - my own badword filer.
What steps should be done? I should disable integrated one somehow, right?
I need some help, being new to this. Thanks

Yeah

Posted: 11 Jul 2011, 11:26
by BadUser
So.
I've figured out how to write an extensions in Java (via AbstractExtension).
Now i need to serarch for badwords in internaleventobject every message, and if i've found something forbidden - dispatch it? Then what? Explain please, it'll safe much time

Posted: 12 Jul 2011, 06:16
by BigFIsh
Now i need to serarch for badwords in internaleventobject every message, and if i've found something forbidden - dispatch it? Then what? Explain please, it'll safe much time
What you said is pretty much the summary of what you need to do.

Firstly, you'll need to enable pub message internal event using: zone.setPubMsgInternalEvent(true);

Then when you intercept the message, perform your logic. Filter out bad words, or discard the message and reply with a warning, or whatever suits.

Basically, the code would look like this:

Code: Select all

if (evtName.equals(InternalEventObject.EVENT_PUBLIC_MESSAGE))
{
    Room room = (Room) ieo.getObject("room");
    User sender = (User) ieo.getObject("user");
    String message = (String) ieo.getParam("msg");

    String roomId = Integer.toString(room.getId());
    String senderId = Integer.toString(sender.getUserId());
    String senderName = sender.getName();
    
    //do your logic here

    LinkedList<SocketChannel> sendList = room.getChannellList();    
    helper.dispatchPublicMessage(message, room, sendList);
}

Posted: 12 Jul 2011, 07:19
by BadUser
Thanks!

Ok, if i consider that the current message contains some bad words, should i warn the user by myself somehow?
Config.xml gives the amuont of allowed swearing, so

Code: Select all

if (isBas(message))
// Do what? Warn, ban, kick? or it's none of my business?
else
helper.dispatchPublicMessage(message, room, sendList);
And to make it work, i should change config.xml like
<Badwords filter active = "false">
and then load my extension? But it'll work just for choosen zone and badwords filter works for everything

P. S. In addition, is there any chance to make extension work for the whole server, all zones, not just for the one?

Posted: 12 Jul 2011, 23:09
by BigFIsh
[url]Ok, if i consider that the current message contains some bad words, should i warn the user by myself somehow?[/url]

Correct.
And to make it work, i should change config.xml like
<Badwords filter active = "false">
and then load my extension? But it'll work just for choosen zone and badwords filter works for everything
Yes. If you want to implement your own custom bad word filter for every zone, you'll have to add the code for each of your extension. Disabling BadWordsFilter via config.xml will disable it as a whole.
In addition, is there any chance to make extension work for the whole server, all zones, not just for the one?
Sorry, this is not possible.

Posted: 13 Jul 2011, 06:43
by BadUser
Thanks for making it clear. Very helpful.
But i'm wondering, why smartfox doesn't allow to make server more flexible in this way? Badword filter isn't perfect and there is no chance to write something by myselft, is it?
I don't think that loading my extension in every zone is the right way.

Posted: 14 Jul 2011, 22:59
by BigFIsh
You may go ahead and create a feature request for this then.

Posted: 15 Jul 2011, 06:28
by BadUser
Got you.
Thanks for quick replies, you helped a lot in this question.
My filter works fine... Except private messages, throws an exception NullPointer Exception, when i call despatchPrivateMessage. Any ideas? All variables (msg, room, sender, recipient) aren't null, has been checked.
With public - no problem.

Posted: 15 Jul 2011, 07:15
by BadUser
I've found my bug.
http://www.smartfoxserver.com/docs/doc ... ssage.htm
from that link i thought that for private messages i should write

Code: Select all

User sender = sender = (User) ieo.getObject("user");
but actually it must be

Code: Select all

User sender = sender = (User) ieo.getObject("sender");
Spent two days on it. I should have seen properties for clear, not code for misunderstanding. Have no questions any more, thanks!