Creation/Dev/wordFilter: Difference between revisions

From Graal Bible
(New page: == Introduction == The NPC server has a built-in word filter. This feature comes in handy for servers who want to implement a swear filter. == Functions == <pre>wordfiltertext(text, type...)
 
No edit summary
Line 3: Line 3:


== Functions ==
== Functions ==
<pre>wordfiltertext(text, type) - returns integer - filters text with the rules defined in wordfilter/rules.txt, second parameter is the text type (chat, pm, toall or nick), result is a combination of 1 (log) + 2 (tell admins) + 4 (replace) + 8 (warn) + 16 (jail) + 32 (ban); use getWordFilterNewText(), getWordFilterMessage() and getWordFilterMatches() for more information about the filtered text
* wordfiltertext(text, type) - returns integer - filters text with the rules defined in wordfilter/rules.txt, second parameter is the text type (chat, pm, toall or nick), result is a combination of 1 (log) + 2 (tell admins) + 4 (replace) + 8 (warn) + 16 (jail) + 32 (ban); use getWordFilterNewText(), getWordFilterMessage() and getWordFilterMatches() for more information about the filtered text


getwordfiltermatches(int) - returns object - returns an array of words which matched the word filter after calling wordFilterText(), parameter is the maximum number of matches you want
* getwordfiltermatches(int) - returns object - returns an array of words which matched the word filter after calling wordFilterText(), parameter is the maximum number of matches you want


getwordfiltermessage() - returns string - returns the warn message after calling wordFilterText()
* getwordfiltermessage() - returns string - returns the warn message after calling wordFilterText()


getwordfilternewtext() - returns string - returns the new text generated by the word filter after calling wordFilterText()</pre>
* getwordfilternewtext() - returns string - returns the new text generated by the word filter after calling wordFilterText()


== Example ==
== Example ==
The following example shows how the word filter can be used to implement a swear filter.
The following snippet shows how the word filter can be used to implement a swear filter:
 
<pre>temp.filteresult = wordFilterText(player.chat, "chat");
 
if ((temp.filteresult & 1)!=0)
  savelog2("cursinglog.txt", player.account @ " used rude words: " @ getWordFilterMatches(3));
 
if ((temp.filteresult & (8 + 16 + 32))!=0)
  player.chat = getWordFilterMessage();
else if ((temp.filteresult & 4)!=0)
  player.chat = getWordFilterNewText()</pre>

Revision as of 18:32, 22 April 2009

Introduction

The NPC server has a built-in word filter. This feature comes in handy for servers who want to implement a swear filter.

Functions

* wordfiltertext(text, type) - returns integer - filters text with the rules defined in wordfilter/rules.txt, second parameter is the text type (chat, pm, toall or nick), result is a combination of 1 (log) + 2 (tell admins) + 4 (replace) + 8 (warn) + 16 (jail) + 32 (ban); use getWordFilterNewText(), getWordFilterMessage() and getWordFilterMatches() for more information about the filtered text
* getwordfiltermatches(int) - returns object - returns an array of words which matched the word filter after calling wordFilterText(), parameter is the maximum number of matches you want
* getwordfiltermessage() - returns string - returns the warn message after calling wordFilterText()
* getwordfilternewtext() - returns string - returns the new text generated by the word filter after calling wordFilterText()

Example

The following snippet shows how the word filter can be used to implement a swear filter:

temp.filteresult = wordFilterText(player.chat, "chat"); 

if ((temp.filteresult & 1)!=0) 
  savelog2("cursinglog.txt", player.account @ " used rude words: " @ getWordFilterMatches(3)); 

if ((temp.filteresult & (8 + 16 + 32))!=0) 
  player.chat = getWordFilterMessage(); 
else if ((temp.filteresult & 4)!=0) 
  player.chat = getWordFilterNewText()