Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 02:50 PM.


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