Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Toggleable Word Censor

Newbie Spellweaver
Joined
Aug 31, 2009
Messages
13
Reaction score
4
Excessive swearing was becoming a problem in my server, so...

In Maplecharacter.java

After this line

Code:
private boolean hidden;

Add this

Code:
private boolean censor;

After this

Code:
setPosition(new Point(0, 0));

Add this

Code:
censor = true;

[Can change this to false if you just want to censor a temporarily, note: Censor will turn off after you chage channels if you change it to false]


Add this

Code:
public boolean getCensor() {
        return censor;
    }
    
public void setCensor(boolean setTo) {
        censor = setTo;
    }


After

Code:
    public void setMap(int PmapId) {
        this.mapid = PmapId;
    }

In GeneralChathandler

Add

Code:
        if(c.getPlayer().getCensor()) {
            String[] badWords = {"duck", "punt", "fag", "wigger"};
                if (c.getPlayer().getCensor()) {
                    for (int i = 0; i < 3; i++) {
                        if (text.toLowerCase().contains(badWords[i])) {
                            text = "I have a potty mouth.";
                        }
                    }
                }  
        }



        }
After

Code:
    public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
        String text = slea.readMapleAsciiString();

And Finally in

GMCommands.java [commandprocessor.java, depends which source you're using]


Add
Code:
        } else if (splitted[0].equals("!censoron"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCensor(false);
                mc.dropMessage(victim.getName() + " is now censored.");
                victim.dropMessage("You are now censored.");




        } else if (splitted[0].equals("!censoroff")) {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCensor(true);
                mc.dropMessage("You have censored " + victim.getName());
                mc.dropMessage(victim.getName() + " is no longer censored.");
                victim.dropMessage("You are no longer censored.");

If anyone could help me make this case insensitive, it would be very helpful.
 
Last edited:
Banned
Banned
Joined
Nov 17, 2009
Messages
104
Reaction score
30
loel naise rls person i don't know xdd, however the generalchathandler part can be shortened.
 
Last edited:
Newbie Spellweaver
Joined
Aug 31, 2009
Messages
13
Reaction score
4
Thanks Moogra!

GeneralchatHandler changed..
 
Skilled Illusionist
Loyal Member
Joined
Aug 4, 2008
Messages
376
Reaction score
37
Just use ||
PHP:
		if(c.getPlayer().getCensor()) {
            if (text.toLowerCase().contains("duck") || text.toLowerCase().contains("punt") || text.toLowerCase().contains("fag") || text.toLowerCase().contains("wigger")) {
                text = "I have a potty mouth.";
            }
        }

or just use arrays.
PHP:
String[] badWords = {"duck", "punt", "fag", "wigger"};
		if (c.getPlayer().getCensor()) {
			for (int i = 0; i < badWords.length(); i++) {
				if (text.toLowerCase().contains(badWords[i])) {
					text = "I have a potty mouth.";
				}
			}
		}
 
Custom Title Activated
Loyal Member
Joined
Nov 27, 2009
Messages
1,905
Reaction score
948
I figure this could be done with a string.contains thing in the gch.
Also, shouldn't there be an Ignore Case thing?

Anyways, good job. I <3 the potty mouth thing!
 
Newbie Spellweaver
Joined
Mar 29, 2009
Messages
19
Reaction score
0
quick quesion ~~ can you use the command like !censoron <charname> ?

n00b = me
 
Newbie Spellweaver
Joined
Aug 31, 2009
Messages
13
Reaction score
4
The !censoron/off are supposed to be singlepeople only.

I might make a !censorall command or something.
 
Newbie Spellweaver
Joined
Mar 29, 2009
Messages
19
Reaction score
0
The !censoron/off are supposed to be singlepeople only.

I might make a !censorall command or something.

oh sorry for being newb but i thought it censord the whole word o-o
yes i did not look but now that i do i see that

a censorall command would be nice :D

i would do it if i knew how -.-
 
Newbie Spellweaver
Joined
Aug 31, 2009
Messages
13
Reaction score
4
Here's the censor on /off for the whole world

Censor everyone that is online:

Code:
} else if (splitted[0].equals("!censorworld")) {
    for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {         
        mch.setCensor(true);
        mc.dropMessage("You have censored the world.");
        mch.dropMessage("You have been censored.");
}

Uncensor everyone that's online

Code:
} else if (splitted[0].equals("!uncensorworld")) {
    for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {
        mch.setCensor(false);
        mc.dropMessage("You have uncensored the world.");
        mch.dropMessage("You are no longed censored.")
    }
}

Note : If "censor = true;" in Maplecharacter.java, then once someone changes channels or relogs, they will be censored again. If the censor was false, they will be censored again once they change channels or relog.
 
Last edited:
Banned
Banned
Joined
Mar 22, 2009
Messages
247
Reaction score
80
even better:

Code:
String censor(String text) {
StringBuilder sb = new StringBuilder(text);
Pattern p = Pattern.compile("f.*u.*c.*k");
Matcher m = p.matcher();
while (m.find()) {
    char c[] = new char[m.end() - m.start()];
    Arrays.fill(c, '*');
    sb.replace(m.start(), m.end(), String.valueOf(c));
}
return sb.toString();
}

this finds even "fuuuck", "fck", "fuccck", etc, and it also replaces it with stars
 
Newbie Spellweaver
Joined
Mar 29, 2009
Messages
19
Reaction score
0
is mch.dropMessage supposed to be mc.dropMessage >_>
 
Newbie Spellweaver
Joined
Aug 31, 2009
Messages
13
Reaction score
4
PHP:
    for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {

mch = All the players in the game.

so mch.dropMessage sends a message to everyone in the game.
 
Back
Top