Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-19-2011, 04:03 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Clientside Swear Filter

This is a clientside swear filter. It's fairly efficient as far as I can see. It's used on Era right now and it doesn't seem to cause any issues.

There are three levels (it's easy to add more):
  • Off
  • Moderate (recommended)
  • Strict (for babies only)

Players can choose any one. Only chat is filtered, so you will want to use the default wordfilter for PMs, nicks, and toalls.

PHP Code:
//#CLIENTSIDE
enum LEVEL {
  
OFF,
  
MODERATE,
  
STRICT
}

const 
DEFAULT_LEVEL LEVEL.MODERATE;

function 
onCreated() {
  
this.setDefaultFilterLevel();
  
this.loadFilterRules();
}

// filter rules
function loadFilterRules() {
  
this.resetRules();
  
  if (
getFilterLevel() <= LEVEL.OFF) {
    return;
  }
  
  
// rules shouald be in all lowercase and contain no spaces
  // if words contain eachother use the one which is most inclusive
  // first, e.g. if you want to have "pooping" and "oop", 
  // put "pooping" first since otherwise it is filtered to
  // p***ing which looks odd
  
  // moderate rules (also apply to strict)
  
temp.rulesToAdd = {
    
"drat",
    
"darn"
  
};
  
  
this.addRules(rulesToAdd);
  
  
  if (
getFilterLevel() <= LEVEL.MODERATE) {
    return;
  }
  
  
// strict rules
  
temp.rulesToAdd = {
    
"crap",
    
"poo"
  
};
  
  
this.addRules(rulesToAdd);
}

// filtering
function onRemotePlayerChats(pl) {
  
this.filterChat(pl);
}

function 
onPlayerChats() {
  
this.filterChat(player);
}

function 
onPlayerEnters() {
  for (
temp.pl players) {
    if (
pl == player) {
      continue;
    }
    
    
this.filterChat(pl);
  }
}

function 
filterChat(pl) {
  if (
pl.chat.trim().length() <= 0) {
    return;
  }
  
  
temp.testChat "";
  
temp.newChat pl.chat;
  
temp.chatPositions null;
  
  for (
temp.0pl.chat.length(); ++) {
    
temp.char pl.chat.charat(i);
    
    if (
char == " ") {
      continue;
    }
    
    
chatPositions.add(i);
    
testChat @= char.lower();
  }
  
  for (
temp.rule this.getRules()) {
    
temp.positions testChat.positions(rule);
    
temp.lastFix = (- 1);
    
    for (
temp.position positions) {
      if (
lastFix != (- 1) && position < (lastFix rule.length())) {
        continue; 
// was already fixed partially
      
}
      
      
temp.replacement getReplacement(rule.length());
      
testChat testChat.substring(0position) @ replacement testChat.substring(position rule.length());
      
newChat newChat.substring(0chatPositions[position]) @ replacement newChat.substring(chatPositions[position rule.length() - 1] + 1);
    }
  }
  
  if (
newChat != pl.chat) {
    
pl.chat newChat;
  }
}

function 
getReplacement(characters) {
  
// you could easily change this to like @#$%! if you wanted
  
temp.replacement "******************************";
  return 
replacement.substring(0characters);
}

public function 
setFilterLevel(newFilterLevel) {
  
player.client.option.filter.level newFilterLevel;
  
this.loadFilterRules();
}

public function 
getFilterLevel() {
  return 
player.client.option.filter.level;
}

function 
setDefaultFilterLevel() {
  if (! 
player.client.option.filter.init) {
    
player.client.option.filter.init true;
    
this.setFilterLevel(DEFAULT_LEVEL);
  }
}

function 
resetRules() {
  
this.rules null;
}

function 
addRules(rulesToAdd) {
  for (
temp.ruleToAdd rulesToAdd) {
    
this.rules.add(ruleToAdd);
  }
}

function 
getRules() {
  return 
this.rules;

Use the public functions getFilterLevel() and setFilterLevel(int newFilterLevel) for getting/setting the level with chat commands or a GUI.

If you want Era's word list I'm happy to give you them, just send me a PM. I don't think Darlene would be happy if I posted it.
__________________
Reply With Quote
  #2  
Old 03-19-2011, 04:46 AM
Rufus Rufus is offline
Registered User
Join Date: Jun 2004
Location: United Kingdom
Posts: 4,698
Rufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud of
This should be just implemented globally as a central system. @#$%! also beats *****
__________________
Quote:
Originally Posted by Loriel View Post
Seriously, you have ****-all for content and you're not exactly pulling in new developer talent, angling for prestigious titles should be your last concern.
Reply With Quote
  #3  
Old 03-19-2011, 05:13 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Rufus View Post
This should be just implemented globally as a central system. @#$%! also beats *****
Replace the provided function with:

PHP Code:
function getReplacement(characters) {
  
temp.symbols "!@#$%&";
  
temp.int(random(0symbols.length()));
  for (
temp.0temp.characterstemp.i++) {
    
temp.newstr @= symbols.charat((temp.temp.i)%symbols.length());
  }
  return 
temp.newstr;

Perhaps a getReplacementSymbols config option could be added.
__________________
Quote:

Last edited by fowlplay4; 03-19-2011 at 05:23 AM..
Reply With Quote
  #4  
Old 03-19-2011, 05:21 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by fowlplay4 View Post
Replace the provided function with:

PHP Code:
function getReplacement(str) {
  
temp.symbols "!@#$%&";
  
temp.int(random(0symbols.length()));
  for (
temp.0temp.str.length(); temp.i++) {
    
temp.newstr @= symbols.charat((temp.temp.i)%symbols.length());
  }
  return 
temp.newstr;

Perhaps a getReplacementSymbols config option could be added.
getReplacement's parameter is the length of the string to replace, not the string—otherwise that should work.
__________________
Reply With Quote
  #5  
Old 03-19-2011, 05:23 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
getReplacement's parameter is the length of the string to replace, not the string—otherwise that should work.
Right, well fixed my post.
__________________
Quote:
Reply With Quote
  #6  
Old 03-20-2011, 01:08 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
http://forums.graalonline.com/forums...ad.php?t=85382

I see this one has a few more filtering and moderation options over Tig's one though
__________________
Reply With Quote
  #7  
Old 03-20-2011, 04:11 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Chompy View Post
http://forums.graalonline.com/forums...ad.php?t=85382

I see this one has a few more filtering and moderation options over Tig's one though
Indeed. It doesn't look like Tig's even checks for uppercase/mixed-case words.
__________________
Reply With Quote
  #8  
Old 03-20-2011, 04:21 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
cool cool- you can make swearing npcs now
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.