Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-30-2009, 11:56 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Clientside Swear Filter

As you may or may not know, I am one of the pioneers in removing foul language around Graal. I don't like to read it, I don't like to write it, I don't want to hear it, I don't want to see it.

However, I believe that people should have the choice as to whether or not they want to see the text or not.

So, I have devised a quick clientside swear filter for those of you who agree.

It probably needs to be improved in the future to run more efficiently, but this is a nice step in the right direction. You will still have to filter your PMs using the default graal rules.txt which is highly recommended, but now you can add a choice to whether or not the player wants to filter the swear words.

Here is the weapon script:
Graal Script Code:
//#CLIENTSIDE
function onCreated() {
  
this.swearwords = {
    {
"testing""*******"},
    {
"test2""*******"},
    {
"damn""****"}
  };
}

function 
onPlayerChats() {
  switch (
player.chat) {
    case 
"filteron":
      
client.swearfilter true;
      
player.chat "Swear filter is now on!";
    break;
    case 
"filteroff":
      
client.swearfilter false;
      
player.chat "Swear filter is now off.";
    break;
  }
}

function 
onRemotePlayerChats(objchat) {
  if (
client.swearfilter) {
    for (
temp.0temp.this.swearwords.size(); temp.++) {
      if (
obj.chat.pos(this.swearwords[temp.s][0]) >= 0) {
        
obj.chat replacetext(obj.chatthis.swearwords[temp.s][0], this.swearwords[temp.s][1]);
      } 
    }
  }
}

// edited version of my replacetext function in the code gallery
// http://forums.graalonline.com/forums/showthread.php?t=79538
// this one is not case sensitive
function replacetext(textoldtextnewtext) {
  
temp.oldlen   oldtext.length();
  
temp.textdiff newtext.length() - temp.oldlen;
  
  for (
temp.ptext.lower().positions(oldtext.lower())) {
    
temp.pos temp.temp.textdiff * (temp.index ++);
    
text text.substring(0temp.pos) @ newtext text.substring(temp.pos temp.oldlen);
  }
  
  return 
text;

As you can see, I added an example of how to turn on/off the sear filter by using the commands "filteron" and "filteroff."

I'd like to start seeing these sort of methods used around Graal to prevent foul language.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 12-06-2012 at 08:59 PM.. Reason: Edited the replacetext and also made it not case-sensitive.
Reply With Quote
  #2  
Old 05-01-2009, 12:25 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
Neat, I'm just confused by that continue.

On Zodiac, players can right click the target and ignore the players chat entirely.
__________________
Quote:
Reply With Quote
  #3  
Old 05-01-2009, 12:28 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by fowlplay4 View Post
Neat, I'm just confused by that continue.
I was going to add some more stuff under it but I decided not to and just never removed the continue, I've removed it now though.

Quote:
Originally Posted by fowlplay4 View Post
On Zodiac, players can right click the target and ignore the players chat entirely.
That's a nice feature. I thought about adding something like that to GK but figured it might be a little excessive.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 05-01-2009, 12:29 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
Nice, I like it better than a mandatory filter.

However, it would be better if it cached filtered text, e.g. something like...

Graal Script Code:
if (this.cache.(@ pl.chat) != null && pl.chat != null) {
  
pl.chat this.cache.(@ pl.chat);
} else {
  
// filter chat and save to cache

Only problem is it could potentially become a huge cache. Could help by using a single character to represent chat that doesn't need to be removed, rather than storing every single chat tidbit. I'm sure you'll think of something.

It just seems really inefficient to filter every single players chat twenty times a second.
__________________
Reply With Quote
  #5  
Old 05-01-2009, 12:31 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
Nice, I like it better than a mandatory filter.

However, it would be better if it cached filtered text, e.g. something like...

Graal Script Code:
if (this.cache.(@ pl.chat) != null && pl.chat != null) {
  
pl.chat this.cache.(@ pl.chat);
} else {
  
// filter chat and save to cache

Only problem is it could potentially become a huge cache. Could help by using a single character to represent chat that doesn't need to be removed, rather than storing every single chat tidbit. I'm sure you'll think of something.

It just seems really inefficient to filter every single players chat twenty times a second.
Yes, I also thought of some nice innovative ways of remaking it, but this sample is supposed to be about as simple as possible so it will hopefully motivate people to build on top of it and make a nice filter system.

Also, usually when Graal is loading very long strings into vars it sometimes pauses the screen for up to 5-20 seconds depending on the size, which wouldn't be good.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 05-01-2009, 12:35 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Ideally we would petition Stefan for a callback that gets fired if other players chat. I am not a huge fan of the timeout loop, especially since it keeps running even while the check is disabled.
Reply With Quote
  #7  
Old 05-01-2009, 12:37 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 Loriel View Post
Ideally we would petition Stefan for a callback that gets fired if other players chat. I am not a huge fan of the timeout loop, especially since it keeps running even while the check is disabled.
Timeouts in themselves are not really inefficient, and the code Tig is using if not enabled simply schedules an event in another twentieth of a second.

Keep in mind that computers these days are extremely fast, and running a single check for something that is already loaded into memory will cause virtually no performance drops.
__________________
Reply With Quote
  #8  
Old 05-01-2009, 12:43 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Loriel View Post
Ideally we would petition Stefan for a callback that gets fired if other players chat. I am not a huge fan of the timeout loop
I agree completely.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #9  
Old 05-01-2009, 12:05 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
Quite neat I must say.

I did a little edit to remove that timeout

Graal Script Code:
//#CLIENTSIDE
function onCreated() {
  
this.swearwords = {
    {
"testing""*******"},
    {
"test2""*******"},
    {
"damn""****"}
  };
}

function 
onPlayerChats() {
  switch (
player.chat) {
    case 
"filteron":
      
client.swearfilter true;
      
player.chat "Swear filter is now on!";
    break;
    case 
"filteroff":
      
client.swearfilter false;
      
player.chat "Swear filter is now off.";
    break;
  }
}

function 
onRemotePlayerChats(objchat) {
  if (
client.swearfilter) {
    for (
temp.0temp.this.swearwords.size(); temp.++) {
      if (
obj.chat.pos(this.swearwords[temp.s][0]) >= 0) {
        
obj.chat replacetext(obj.chatthis.swearwords[temp.s][0], this.swearwords[temp.s][1]);
      } 
    }
  }
}

// DustyPorViva's replacetext function.
function replacetext(txt,a,b) {
  if (
txt.pos(a)<0) return txt;
  
temp.txtpos txt.positions(a);
  
temp.newtxt txt.substring(0,txtpos[0]);
  for (
temp.i=0;i<txtpos.size();i++) {
    
newtxt @= b;
    
newtxt @= txt.substring(txtpos[i]+a.length(),txt.substring(txtpos[i]+a.length()).pos(a));
  }
  return 
newtxt;

__________________

Last edited by Chompy; 05-01-2009 at 12:39 PM..
Reply With Quote
  #10  
Old 05-01-2009, 06:16 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Chompy View Post
Quite neat I must say.

I did a little edit to remove that timeout

Graal Script Code:
//#CLIENTSIDE
function onPlayerChats() {
  switch (
player.chat) {
    case 
"filteron":
      
client.swearfilter true;
      
player.chat "Swear filter is now on!";
    break;
    case 
"filteroff":
      
client.swearfilter false;
      
player.chat "Swear filter is now off.";
    break;
  }


There is no need to use a switch() in this case and it's bad habit to do so. Not sure about how many other languages this applies to, but with Java you can't compare strings using switch(), so you wouldn't be able to apply the same method in Java. There are only select instances where it would actually make sense to use switch() instead of if-then-else, and this isn't one of them.

Also, it would benefit you to get into the habit of doing client.whatever = !client.whatever since it would save you an unnecessary clutter when doing something like this.
Reply With Quote
  #11  
Old 05-01-2009, 07:12 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Chompy View Post
Quite neat I must say.

I did a little edit to remove that timeout
Oh, nice, there IS an event for it. Thanks

Quote:
Originally Posted by Gambet View Post
There is no need to use a switch() in this case and it's bad habit to do so. Not sure about how many other languages this applies to, but with Java you can't compare strings using switch(), so you wouldn't be able to apply the same method in Java. There are only select instances where it would actually make sense to use switch() instead of if-then-else, and this isn't one of them.
That's correct, Java's switch() statements only allow ints, but that doesn't mean I should model my code after the standards Java runs. You may notice that GScript2 utilizes strings much differently than most coding languages. Following that logic I should also declare all of my variables before using them even though they're automatically declared when they're not equal to NULL.

Quote:
Originally Posted by Gambet View Post
Also, it would benefit you to get into the habit of doing client.whatever = !client.whatever since it would save you an unnecessary clutter when doing something like this.
It really isn't necessary for this... if someone said filteron and it was currently on it would just switch it off. An extra line or two really isn't a big deal in my opinion.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 05-01-2009 at 07:44 PM..
Reply With Quote
  #12  
Old 05-01-2009, 07:40 PM
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
Quote:
Originally Posted by Tigairius View Post
I'd like to start seeing these sort of methods used around Graal to prevent foul language.
Why don't you try to get it added as a default feature, rather than some servers using it and others not?
__________________
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
  #13  
Old 05-01-2009, 07:46 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Rufus View Post
Why don't you try to get it added as a default feature, rather than some servers using it and others not?
I'd like to try to, there will also need to be one for PMs and one for nick names (nick names are easy to do).
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #14  
Old 05-01-2009, 08:06 PM
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
Quote:
Originally Posted by Tigairius View Post
I'd like to try to, there will also need to be one for PMs and one for nick names (nick names are easy to do).
Well, I fully agree with the concept so I hope it is added. I think it'd be way more convenient if it was a part of the default Graal options, with the filter enabled by default of course. I believe that using asterisks represent the profanity too much though and it carries the negative/offensive connotation, just not as direct. A better way of conveying a more 'family friendly' message would be using random non-letter and non-punctuation (# & § @ %) symbols as a replacement like comic books do. With this you don't really notice that people are swearing, and unlike the current visual representation of obscenities, it no longer offends.
__________________
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.

Last edited by Rufus; 05-01-2009 at 08:22 PM..
Reply With Quote
  #15  
Old 05-01-2009, 08:16 PM
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
Thanks to Chompy my filter script is now down to a couple lines!

Graal Script Code:
//#CLIENTSIDE
function onRemotePlayerChats(objchat) {
  if (
obj.account in client.chatignorelist)
    
obj.chat ".CI."

__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:42 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.