Created
January 5, 2016 19:35
-
-
Save Geesu/1b1ae28a29532362935f to your computer and use it in GitHub Desktop.
Swear filter for AMX Mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* AMX Mod script. | |
* | |
* (c) 2003, [?]Mother | |
* | |
* Based on code by Djey, JustinHoMi, and RAV | |
* | |
* This file is provided as is (no warranties). | |
* | |
* This AMX plugin requires MySQL module. | |
* | |
* For this to work, you might create your MySQL wordlist table with this | |
SQL query : | |
CREATE TABLE amx_wordlist ( | |
swear varchar(20) NOT NULL default '', | |
admin_id varchar(40) NOT NULL default '', | |
admin_name varchar(30) NOT NULL default '', | |
time_created timestamp(14) NOT NULL, | |
PRIMARY KEY (swear) | |
) TYPE=MyISAM; | |
* Once created, prepopulate it with: | |
INSERT INTO amx_wordlist VALUES | |
('badword','WONID_of_adding_admin','Name_of_adding_admin',NOW()); | |
* IMPORTANT: | |
* o Check $moddir/addons/amx/mysql.cfg for MySQL access configuration | |
* o Disable any other language filters | |
* | |
* 0.70 - Misc coding cleanups | |
* 0.64 - Added multiple methods of punishment (frag & money) | |
* 0.61 - Fixed race condition when loading bad word list | |
* 0.60 - Initial Relase | |
* | |
*/ | |
#include <amxmod> | |
#include <mysql> | |
// max number of words in word list | |
#define MAX_WORDS 192 | |
// Set DEBUG to 1 to enable debugging | |
#define DEBUG 0 | |
new g_swears[MAX_WORDS][20] | |
new g_SwearsNum | |
new state = 0 | |
public plugin_init(){ | |
register_plugin("MySQL Swear filter","0.7","[?]Mother") | |
register_cvar("amx_mode","2.0") | |
register_cvar("amx_password_field","_pw") | |
register_cvar("amx_default_access","") | |
register_srvcmd("amx_sqladmins","swearSql") | |
register_cvar("amx_mysql_host","127.0.0.1") | |
register_cvar("amx_mysql_user","root") | |
register_cvar("amx_mysql_pass","") | |
register_cvar("amx_mysql_db","amx") | |
server_cmd("exec addons/amx/mysql.cfg;amx_sqladmins") | |
register_cvar("sw_admin","1.0") | |
register_cvar("sw_warn","0.0") | |
register_cvar("sw_cashloss", "100") | |
register_cvar("sw_punish_frag","1") | |
register_cvar("sw_punish_money","1") | |
register_clcmd("say","swearPunish") | |
register_clcmd("say_team","swearPunish") | |
return PLUGIN_CONTINUE | |
} | |
public swearSql(){ | |
new host[64],user[32],pass[32],db[32],error[128] | |
get_cvar_string("amx_mysql_host",host,63) | |
get_cvar_string("amx_mysql_user",user,31) | |
get_cvar_string("amx_mysql_pass",pass,31) | |
get_cvar_string("amx_mysql_db",db,31) | |
new mysql = mysql_connect(host,user,pass,db,error,127) | |
if(mysql < 1){ | |
server_print("[AMX] MySQL Swearfilter error: can't connect: | |
'%s'",error) | |
return PLUGIN_HANDLED | |
} | |
server_print("[AMX] Swearfilter Plugin successfully connected.") | |
if(mysql_query(mysql,"SELECT swear FROM amx_wordlist") < 1) { | |
mysql_error(mysql,error,127) | |
server_print("[AMX] MySQL Swearfilter error in loading list: | |
'%s'",error) | |
return PLUGIN_HANDLED | |
} | |
g_SwearsNum=0 | |
while( mysql_nextrow(mysql) > 0 ) | |
{ | |
mysql_getfield(mysql, 1, g_swears[ g_SwearsNum ],19) | |
if (DEBUG) server_print("[AMX] Swear loaded bad word: %s from | |
database (%i)", g_swears[ g_SwearsNum ],strlen(g_swears[ g_SwearsNum ])) | |
g_SwearsNum++ | |
} | |
server_print("[AMX] Swear filter loaded %d bad word%s from | |
database",g_SwearsNum, (g_SwearsNum == 1) ? "" : "s" ) | |
mysql_close(mysql) | |
state=1 | |
return PLUGIN_HANDLED | |
} | |
public client_connect(id){ | |
if (state == 0) | |
swearSql() | |
return PLUGIN_CONTINUE | |
} | |
public swearPunish(id) | |
{ | |
// If we're an admin, don't punish | |
if ((get_cvar_num("sw_admin") > 0) && (get_user_flags(id) > 0)) | |
return PLUGIN_CONTINUE | |
new szSaid[192] | |
read_args(szSaid,191) | |
new bool:found = false | |
new pos, i = 0 | |
while ( i < g_SwearsNum ) { | |
if ((pos = containi(szSaid,g_swears[i])) != -1 ){ | |
new len = strlen(g_swears[i]) | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter badword %s (%i) | |
found in %s",g_swears[i],len,szSaid) | |
while(len--) szSaid[pos++] = '*' | |
found = true | |
continue | |
} | |
++i | |
} | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter %s", szSaid) | |
if ( found ){ | |
new money = get_user_money(id) | |
new loss = get_cvar_num("sw_cashloss") | |
// Fine them the money | |
if ( get_cvar_num("sw_punish_money") ) { | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter fine start") | |
if ( money < loss ) | |
loss = money | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter fine $%i", loss) | |
set_user_money(id, money - loss,1) | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter fine end: Id:%i | |
Money:%i",id, money) | |
} | |
// Fine them the frag | |
if (get_cvar_num("sw_punish_frag") ) { | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter frag start") | |
new pfrags = get_user_frags(id) | |
set_user_frags(id,pfrags -1) | |
if (DEBUG) server_print("[AMX] MYSQL Swearfilter frag: Id:%i | |
Frags:%i ",id,pfrags) | |
} | |
// Print out warning depending on their punishment | |
if (get_cvar_num("sw_punish_money") && | |
get_cvar_num("sw_punish_frag") && (loss > 0)) { | |
set_hudmessage(220,80,0, 0.05, 0.50, 2, 0.1, 3.0, 0.02, 0.02, 10) | |
show_hudmessage(id,"WATCH YOUR LANGUAGE^nYou have been fined $%i | |
and^n1 frag for swearing!",loss) | |
} | |
else { | |
if (get_cvar_num("sw_punish_money") && (loss > 0)) { | |
set_hudmessage(220,80,0, 0.05, 0.50, 2, 0.1, 3.0, 0.02, 0.02, | |
10) | |
show_hudmessage(id,"WATCH YOUR LANGUAGE^nYou have been fined $%i | |
for swearing!",loss) | |
} | |
else { | |
if (get_cvar_num("sw_punish_frag")) { | |
set_hudmessage(220,80,0, 0.05, 0.50, 2, 0.1, 3.0, 0.02, 0.02, | |
10) | |
show_hudmessage(id,"WATCH YOUR LANGUAGE^n1 frag removed for | |
swearing!") | |
} | |
} | |
} | |
return PLUGIN_HANDLED | |
} | |
return PLUGIN_CONTINUE | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment