Author Topic: Announcement  (Read 7300 times)


serverside word censoring.

rudyman

  • Guest
Here's one way you can rescript the messageSent servercmd by checking for any instances of words you want to be filtered, which are loaded from a txt file.

Code: [Select]
function serverCmdMessageSent(%client,%msg)
{
   if(!isClean(%msg)){return;}    // <--- don't send the msg if it's not clean
messageAll('chatMsg','\c4%1: %2',%client.name,%msg);
}
function isClean(%msg)
{
   //  is the msg clean?
   if($pref::filterCount <= 0){loadFilters();}
   for(%i=1;%i<=$pref::filterCount;%i++)
   {
      if(strStr(strLwr(%msg),$pref::filter[%i])>=0){return 1;}
   }
return 0;
}
function loadFilters()
{
%filepath="base/directoryHere.../cussWords.txt";
%file=new FileObject();
%file.openForRead(%filepath);
   while(!%file.isEOF())
   {
   %l=%file.readLine();
   $pref::filter[$pref::filterCount++]=%l;
   }
}
« Last Edit: March 10, 2007, 05:50:24 PM by rudyman »

What about from a $pref?

Like the default prefs.

rudyman

  • Guest
From a pref, just do:
$pref::filter[$pref::filterCount++]="cuss word";

and delete the loadFilters() function.

Code: [Select]
function serverCmdMessageSent(%client,%msg)
{
   if(!isClean(%msg)){return;}    // <--- don't send the msg if it's not clean
messageAll('chatMsg','\c4%1: %2',%client.name,%msg);
}
function isClean(%msg)
{
   //  is the msg clean?
   if($pref::filterCount <= 0){loadFilters();}
   for(%i=1;%i<=$pref::filterCount;%i++)
   {
      if(strStr(strLwr(%msg),$pref::filter[%i])>=0){return 1;}
   }
return 0;
}

I mean like this:

$Pref::Server::CurseList
and
$Pref::Server::ETardList

rudyman

  • Guest
I mean like this:

$Pref::Server::CurseList
and
$Pref::Server::ETardList

Ok so basically I'm gunna redo the isClean() function because we're changing the way we get clean strings.

Code: [Select]
function serverCmdMessageSent(%client,%msg)
{
   if(!isClean(%msg)){return;}    // <--- don't send the msg if it's not clean
messageAll('chatMsg','\c4%1: %2',%client.name,%msg);
}

function isClean(%string)
{
%curses=$pref::server::CurseList;
%etards=$pref::server::ETardList;

%curses=splitBy(%curses, "," ,"Curse","CurseCount");
%etards=splitBy(%etards, "," ,"ETard","ETardCount");
   for(%i=1;%i<=$pref::server::curseCount;%i++)
   {
      if(strStr(strLwr(%string),strLwr($pref::server::curse[%i])>=0){return 1;}
   }
   for(%i=0;%i<getWordCount(%string);%i++)
   {
      for(%t=1;%i<=$pref::server::ETardCount;%t++)
      {
          if(getWord(%string,%i) $= $pref::server::Etard[%t]){return 1;}
      }
   }
return 0;
}

function splitBy(%string,%splitChar,%elementSuffix,%countSuffix)
{
%string=strReplace(%string," "@%splitChar,%splitChar);
%string=strReplace(%string,%splitChar@" ",%splitChar);
    // These two commands turn "1 , 2 , 3" into "1,2,3"

%pre="$Pref::Server::";
%element=%pre@%elementSuffix;
%count=%pre@%countSuffix;
eval(%count@"=1;");
   for(%i=1;%i<=strLen(%string);%i++)
   {
   %char=getSubStr(%string,%i-1,1);
      if(%char $= %splitChar){eval(%count@"++;");}
      else
      {
      eval("%c="@%count@";");
      eval(%element@"["@%c@"]="@%element@"["@%c@"]@\""@%char@"\";");
      }
   }
}
« Last Edit: March 10, 2007, 07:05:45 PM by rudyman »

Also, the splitby should be like this:

pref::Server::ETardList="SpammerDude , NoobGuy";

rudyman

  • Guest

Sorry to sound like a noob, but where would I put the messagesent bit:

Code: [Select]
function serverCmdMessageSent(%client, %text)
{
if(!isClean(%client.name,%msg)){return;}
messageAll('chatMsg','\c4%1: %2',%client.name,%msg);
%text = StripMLControlChars(%text);

if(strlen(%text) <= 1)
{
return;
}

%obj = %client.player;
%obj.playthread(0, talk); //fwar play talk animation
%obj.schedule(strlen(%text) * 50, stopthread, 0);
?

rudyman

  • Guest
You can put the actual code in any file you want, as long as it gets exec'd after the original script does (so it overwrites the original).

It'll only work when you're hosting, because you're the only one with this serverCmd modification.

Edit: i just fixed a typo in my code.
Edit2: you don't need anything after the second command in your serverCmdMessageSent() function
« Last Edit: March 10, 2007, 07:01:57 PM by rudyman »

I want to integrate it into my one, not override it.

rudyman

  • Guest
I want to integrate it into my one, not override it.

I didn't understand it, sorry.


Could I just add this in?

   if(!isClean(%client.name,%msg))
   {
      return;
   }