// plugin_swearblock.sma,v 1.00 09/21/2001
 
/*
    This plugin will scan chat messages for swearing embedded within
    clever typing the user may enter. Essentially, the plugin strips
    the chat line of any characters that may be used to separate
    alphanumeric characters (e.g. spaces). the resultant string is then
    fed into the standard swear checker. Unlike plugin_retribution, the
    foul chat is simply eaten and the user is told as such.
 
    NOTE: For this plugin to work effectively, make sure it is placed
    before plugin_retribution in your plugin.ini file.
*/
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_SWEARBLOCK 8192
 
new SwearBlocking = 1;
new STRING_VERSION[MAX_DATA_LENGTH] = "1.00";
 
public admin_swearblock(HLCommand,HLData,HLUserName,UserIndex) 
{
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	new tmpData = 0;
	tmpData = strtonum(Data);
 
	if (tmpData == 0)
	{
		snprintf(Text, MAX_TEXT_LENGTH, "Swear Blocking: %i", SwearBlocking);
	}
	else
	{
		if ((tmpData == 1) || (tmpData == 2))
		{
			SwearBlocking = tmpData;
		}
		snprintf(Text, MAX_TEXT_LENGTH, "Swear Blocking: %i", SwearBlocking);
	}
	selfmessage(Text);
 
	say_command(User, Command, Data);
	return PLUGIN_HANDLED;
}
 
public HandleSay(HLCommand,HLData,HLUserName,UserIndex) 
{
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	/* Ignore messages that come from the console */
	if (UserIndex == 0) {
		return PLUGIN_CONTINUE;
	}
 
	/* Check to see if this is a say_team message, and whether or not
	we should be trapping those. If not, leave.*/
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	// new stuff to check for clever swearing
	if (SwearBlocking == 1)
	{
		new i;
		new length;
		new counter;
		new strippedData[MAX_DATA_LENGTH];
 
		length = strlen(Data);
		counter = 0;
		for (i = 0; i < length; i++)
		{
			if ((Data[i] != ' ')  && (Data[i] != '.') && (Data[i] != ','))
			{
				strippedData[counter] = Data[i];
				counter++;
			}
		}
 
		if (check_words(strippedData) == 0) 
		{
			/* Compliments of PetitMorte */
			if (check_immunity(User)==0) 
			{
				messageex(User, "Your foul chat was suppressed", print_center);
				snprintf(Text, MAX_TEXT_LENGTH, "%s warned about swearing. Chat was blocked", User);
				log(Text);
 
				return PLUGIN_HANDLED;
			}
		}	
	}
 
	return PLUGIN_CONTINUE;
}
 
public plugin_init() {
	plugin_registerinfo("Swearing Blocker Plugin", "Blocks clever attempts to get around swear checker.",STRING_VERSION);
 
	plugin_registercmd("admin_swearblock", "admin_swearblock", ACCESS_SWEARBLOCK, "admin_swearblock 1 | 2 : toggles swear blocking.");
	plugin_registercmd("say", "HandleSay", ACCESS_ALL);
	plugin_registercmd("say_team", "HandleSay", ACCESS_ALL);
 
	return PLUGIN_CONTINUE;	
}