Swear filter..


public class GeneralChatHandler extends AbstractPacketHandler {
    public static String[] swearWords = {
        "f.*?u.*?k",
        "s.*?h.*?t",
        "bi.*?h",
        "bas.*?d",
        "m.*?f.*?",
        "c.*?nt",
        "as.*?s",
        "s.*?ck",
        "w.*?nk",
        "co.*?on",
        "wo.*?g",
        "ni.*?g.*?r",
        "c.*?c.*?k",
        "penis",
        "vagina",
        "c.*?um",
        "p.*?i.*?s",
        "p.*?orn",
        "ar.*?se",
        "nexon",
        "ho.*?r.*?ny",
        "dil.*?do",
        "doggystyle",
        "cl.*?it",
        "fann.*?y",
        "ho.*?re.*?",
        "kn.*?ob",
        "mastur.*?",
        "nazi",
        "hitler",
        "n.*?uts",
        "sob.*?",
        "shag.*?",
        "sl.*?ut.*?",
        "testi.*?",
        "t.*?wa.*?t",
        "viagr.*?a",
        "wil.*?ly",
        "wil.*?lie",
        "jism",
        "dog.*?gy",
        "donkeyri.*?b",
        "breas.*?t",
        "bl.*?wjo.*?b",
        "b.*?b",
        "beastiality",
        "an.*?al",
        "cawk",
        "pus.*?s.*?",
        "rim.*?m",
        "ejaculate",
        "ejakulate",
        "er.*?ct",
        "horni",
        "horna",
        "se.*?x",
        "se.*?ck",
        "ga.*?y",
        "fk",
        "we*?nis"
    };
	
    @Override public void handlePacket(SeekableLittleEndianAccessor slea, RenoriaClient c) {
        String text = slea.readRenoriaAsciiString();
        if (!CommandProcessor.executeCommand(c, c.getMessageCallback(), text.split(" "))) {
            c.getPlayer().getMap().broadcastMessage(PacketCreator.getChatBubble(c.getPlayer(), filter(text), c.getPlayer().isGM()));
        }
    }
	
    public static String filter(String in) {
        for (String swearWord : swearWords) {
            String stars;
            Pattern pat = Pattern.compile(swearWord, Pattern.CASE_INSENSITIVE);
            Matcher mat = pat.matcher(in);
            while (mat.find()) {
                char[] haha = new char[mat.end() - mat.start()];
                for (int i = 0; i < mat.end() - mat.start(); i++) {
                    haha[i] = '*';
                }
                stars = new String(haha);
                in = mat.replaceFirst(stars);
            }
        }
		return in;
	}
}

I’m using RegEXP to make the swear filter, but now I have 2 problems:

  1. Ass is a swear word, but saying Assassin is blocked out too.

  2. If I want to say “fuck”, I can just say “fucl(”.

any way around these problems?

Well, no, there’s really no way around that.

In my opinion, don’t do swear filters. It’s not productive.
If someone wants to be offensive, they will be, either by using other words or by simply circumventing the filters.
It’s possible to be VERY offensive without cursing at all, you know, and sometimes these stronger words are good for making a point.

If you HAVE to make a filter, make it just filter obvious the most offensive and obvious ones, like fu​ck. It’ll make the users realize that you don’t want them to swear and hopefully this will stop them. If they don’t want to be stopped, you can’t stop them.

Easy to break any swear filter. Just do the main words.
What I have added to our forums and soon the game is a word swap on swear word. Which makes the person looks silly/stupid, I don’t know if this will reduce the swearing but its a interesting theory I’m looking into.
For example shit is slime, cock is rooster, fuck is fudge cake…

Never thounght about this solution… but I know some people that will swear only for the stupid result ;D

Most of the time a swear filter is more annoying than usefull. People will still swear and the swear filter will filter sentence that should’nt be. If you want to put a system, do a (automatic ?) report system (far more works for GM/moderator though)

One nice trick is to filter swear words at the recipient’s end, but not at the sender, and combine this with the idea of swapping out swear words for silly alternatives. That way I see that my message shows up as “You’re all a bunch of shits” but everyone else sees “You’re all a bunch of kittens”. Because the sender sees their message unchanged they don’t bother trying to get around it with “sh!t” or similar.

Then your filter just becomes a simple exact word find and replace and you don’t get problems with people from scunthorpe.

I just did the basic bad words on my site. Seems to work well:


		pText = pText.replaceAll("(?i)clit","c***");
		pText = pText.replaceAll("(?i)cock","c**k");
		pText = pText.replaceAll("(?i)cunt","c**t");
		pText = pText.replaceAll("(?i)dick","d**k");
		pText = pText.replaceAll("(?i)f**k","f**k");
		pText = pText.replaceAll("(?i)prick","p***k");
		pText = pText.replaceAll("(?i)shit","s**t");
		pText = pText.replaceAll("(?i)slut","s***");

EDIT: I see there is a swear filter on this site too for the F word which changes it exactly like I do. :slight_smile:

I would do it both on the sending and receiving of the client.
Both to make it harder for people to view swear words and on the client to take the load off the server.

[quote]but I know some people that will swear only for the stupid result
[/quote]
Our forums have been fine, though we have warned people not to abuse it. But the real test when we add it in game which be soon hopefully.

It also has made the forums a friendlier place and less fighting when small insults are replaced like: noob to newbie, ass to bottom, crap to cream, etc.

I like to share a quote of a post(hidden in our bad post area) which has been filtered which I found really funny :wink:

[quote]man get a life u pathetic fool… s*ck my fudge cake rooster u fudge cake plateless hopless daisy you can eat my rooster meat sandiwch all day you little goose boy…
[/quote]

awesome idea, now I just need a list of those words looooooooooooool

Heh heh that’s pretty awesome. Good work.

If I would like to censor “ass” but not “assassin” then my non-regex bubblegum solution would be to replace " ass " with something like " a** ". Pay attention to spaces. Assassin doesn’t contain space after ass so it won’t be touched.

yeah for censoring whole words just use the space character " " at both ends.

Also one decent options is how youtube colapses spam.
So make it difficult on the clients end to access offencive material. This way the poster (who wants the attention) will be less likely to make there message viewed by less people.

I think this is a very good idea. A game I used to play called Infantry (or Cosmic Rift) had this implemented.

If you swore it would appear completely normal, such as “for f**ks sake”, but every other recipient wouldn’t receive this message.

It worked very well. It took most people a long time to realise that swear words wern’t allowed, and even if you knew, it was easy to forget as the messages all appeared like normal on your side.

Then you could just write assassassassassfuckfuckfuckballsshitcrap etc.

You can’t beat creativity, think about misspellings.

It’s all just about raising the bar, and filtering everybody except yourself (as described above) is a pretty nice high bar.

Well as I said, anyone can break a swear filter.
If you wanted a swear filter that targeted all swear words easily, then you would have 2 lists of words, one for the bad words and another list which has words like ‘Assassin’ and not filter those words out.
Therefore even if people try to “assassassassassfkfkf**kballsshitcrap” it would be filtered out.
You would have to do a lot of testing to make sure good words are not filtered out.

Just a thought what about foreign swear words ?

User generated ‘content’.

–> a list of ‘bad words’ that is managed by your users.

someone could make “cheese” as swear word :/, word require some admin.

That’s why it’s not ‘added’ by users, but ‘managed’ by users.

If the majority of users thinks ‘cheese’ is a bad word… so be it.

hehe, cheese :-X I gotta watch my language.