BadWords filter extension

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
BadUser
Posts: 10
Joined: 11 Jul 2011, 08:40

BadWords filter extension

Post 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
BadUser
Posts: 10
Joined: 11 Jul 2011, 08:40

Yeah

Post 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
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post 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);
}
Smartfox's forum is my daily newspaper.
BadUser
Posts: 10
Joined: 11 Jul 2011, 08:40

Post 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?
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post 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.
Smartfox's forum is my daily newspaper.
BadUser
Posts: 10
Joined: 11 Jul 2011, 08:40

Post 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.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

You may go ahead and create a feature request for this then.
Smartfox's forum is my daily newspaper.
BadUser
Posts: 10
Joined: 11 Jul 2011, 08:40

Post 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.
BadUser
Posts: 10
Joined: 11 Jul 2011, 08:40

Post 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!
Post Reply