PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <cstrike>
#include <colorchat>
#define PLUGIN "Tutorial"
#define VERSION "1.0"
#define AUTHOR "Grim"
new Host[] = "127.0.0.1"
new User[] = "root"
new Pass[] = "lalala"
new Db[] = "amx"
new Handle:g_SqlTuple
new g_Error[512]
new Float:iMute[33];
new Float:iBan[33];
new iMuteReason[33][255];
new iMuteAdmin[33][32];
new iBanReason[33][255];
new iBanAdmin[33][32];
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
set_task(1.0, "MySql_Init")
register_clcmd("say ", "CmdSay")
register_clcmd("say_team ", "CmdSayTeam")
register_clcmd("say !banhelp", "CmdBanHelp")
register_clcmd("say !kickhelp", "CmdKickHelp")
register_clcmd("say !mutehelp", "CmdMuteHelp")
}
public CmdKickHelp(id)
{
if(!(get_user_flags(id) & ADMIN_BAN))
return PLUGIN_HANDLED;
client_print_color(id, DontChange, "^4[ INFO ]^1 Kick help printed to your ^3console")
client_print(id, print_console, "---------------------------")
client_print(id, print_console, "-------- Kick help --------")
client_print(id, print_console, "*** !kick player_name kick_reason")
client_print(id, print_console, "*** player_name - part of player name, example: player")
client_print(id, print_console, "*** kick_reason - reason of kick, example: away from keyboard")
client_print(id, print_console, "-------- Kick help --------")
client_print(id, print_console, "---------------------------")
return PLUGIN_HANDLED_MAIN;
}
public CmdMuteHelp(id)
{
if(!(get_user_flags(id) & ADMIN_BAN))
return PLUGIN_HANDLED;
client_print_color(id, DontChange, "^4[ INFO ]^1 Mute help printed to your ^3console")
client_print(id, print_console, "--------------------------")
client_print(id, print_console, "-------- Mute help -------")
client_print(id, print_console, "*** !mute player_name mute_time mute_reason")
client_print(id, print_console, "*** player_name - part of player name, example: player")
client_print(id, print_console, "*** mute_time - time of mute (m | h), example: 5m (Max time is 6 hours)")
client_print(id, print_console, "*** mute_reason - reason of mute, example: use of abusive language")
client_print(id, print_console, "-------- Mute help -------")
client_print(id, print_console, "--------------------------")
return PLUGIN_HANDLED_MAIN;
}
public CmdBanHelp(id)
{
if(!(get_user_flags(id) & ADMIN_BAN))
return PLUGIN_HANDLED;
client_print_color(id, DontChange, "^4[ INFO ]^1 Ban help printed to your ^3console")
client_print(id, print_console, "--------------------------")
client_print(id, print_console, "-------- Ban help --------")
client_print(id, print_console, "*** !ban player_name ban_time ban_reason")
client_print(id, print_console, "*** player_name - part of player name, example: player")
client_print(id, print_console, "*** ban_time - time of ban (m | h | d), example: 5m (Max time is 7 days)")
client_print(id, print_console, "*** ban_reason - reason of ban, example: advertising")
client_print(id, print_console, "-------- Ban help --------")
client_print(id, print_console, "--------------------------")
return PLUGIN_HANDLED_MAIN;
}
public CmdSay(id) {
if(Float:iMute[id] > get_systime() )
{
//static szDate[32]
//format_time(szDate, charsmax(szDate), "%a, %b %d at %H:%M:%S", iMute[id])
//client_print_color(id, DontChange, "^4[ INFO ]^1 You are ^3mutted^1, mute expires: %s", szDate)
return PLUGIN_HANDLED;
}
if(~get_user_flags(id) & ADMIN_BAN)
return PLUGIN_CONTINUE;
new szArg[192]
read_args(szArg, charsmax(szArg))
remove_quotes(szArg)
new szCmd[12], szTarget[12], szTime[4], szReason[50]
strbreak(szArg, szCmd, charsmax(szCmd), szArg, charsmax(szArg))
if(equali(szCmd, "!mute"))
{
strbreak(szArg, szTarget, charsmax(szTarget), szArg, charsmax(szArg))
strbreak(szArg, szTime, charsmax(szTime), szReason, charsmax(szReason))
if(!szTarget[0] || !szTime[0] || !szReason[0])
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Usage: ^3!mute player_name mute_time mute_reason")
return PLUGIN_HANDLED_MAIN;
}
new szAdminName[33];
get_user_name(id, szAdminName, 32)
new player = cmd_target(id, szTarget);
if(!player)
return PLUGIN_HANDLED;
new Float:iMuteTime;
if(containi(szTime, "m") != -1)
{
replace(szTime, charsmax(szTime), "m", "")
iMuteTime = str_to_num(szTime) * 60.0
}
else if(containi(szTime, "h") != -1)
{
replace(szTime, charsmax(szTime), "h", "")
iMuteTime = str_to_num(szTime) * 60.0 * 60.0
}
else if(containi(szTime, "d") != -1)
{
replace(szTime, charsmax(szTime), "d", "")
iMuteTime = str_to_num(szTime) * 60.0 * 60.0 * 24.0
}
if( iMuteTime > 21600 )
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Mute time can not exceed 6 hours")
return PLUGIN_HANDLED
}
else if( iMuteTime <= 0 )
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Mute time is not valid")
return PLUGIN_HANDLED
}
iMute[player] = get_systime() + Float:iMuteTime;
new szTargetName[33];
get_user_name(player, szTargetName, 32)
switch(cs_get_user_team(player))
{
case CS_TEAM_CT: client_print_color(0, BLUE, "^4[ INFO ]^1 Player ^3%s^1 mutted ( %s )", szTargetName, szReason)
case CS_TEAM_T: client_print_color(0, RED, "^4[ INFO ]^1 Player ^3%s^1 mutted ( %s )", szTargetName, szReason)
case CS_TEAM_SPECTATOR: client_print_color(0, GREY, "^4[ INFO ]^1 Player ^3%s^1 mutted ( %s )", szTargetName, szReason)
}
client_print_color(0, BLUE, "^4[ INFO ]^1 You were mutted by: ^3%s^1 ( %s )", szAdminName, szReason)
new szIp[33];
get_user_ip(player, szIp, 32, 1)
new szTemp[512]
format(szTemp,charsmax(szTemp),"INSERT INTO `bans` ( `ip` , `mute_time`, `mute_reason`, `mute_admin`)VALUES ('%s','%f', '%s', '%s');", szIp, Float:iMute[player], szReason, szAdminName)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szT emp)
return PLUGIN_HANDLED_MAIN;
}
if(equali(szCmd, "!ban"))
{
strbreak(szArg, szTarget, charsmax(szTarget), szArg, charsmax(szArg))
strbreak(szArg, szTime, charsmax(szTime), szReason, charsmax(szReason))
if(!szTarget[0] || !szTime[0] || !szReason[0])
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Usage: ^3!ban player_name ban_time ban_reason")
return PLUGIN_HANDLED_MAIN;
}
new szAdminName[33];
get_user_name(id, szAdminName, 32)
new player = cmd_target(id, szTarget);
if(!player)
return PLUGIN_HANDLED;
new Float:iBanTime;
if(containi(szTime, "m") != -1)
{
replace(szTime, charsmax(szTime), "m", "")
iBanTime = str_to_num(szTime) * 60.0
}
else if(containi(szTime, "h") != -1)
{
replace(szTime, charsmax(szTime), "h", "")
iBanTime = str_to_num(szTime) * 60.0 * 60.0
}
else if(containi(szTime, "d") != -1)
{
replace(szTime, charsmax(szTime), "d", "")
iBanTime = str_to_num(szTime) * 60.0 * 60.0 * 24.0
}
if( Float:iBanTime > 604800.0 )
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Ban time can not exceed 7 days")
return PLUGIN_HANDLED
}
else if( Float:iBanTime <= 0.0 )
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Ban time is not valid")
return PLUGIN_HANDLED
}
iBan[player] = get_systime() + Float:iBanTime;
new szTargetName[33];
get_user_name(player, szTargetName, 32)
switch(cs_get_user_team(player))
{
case CS_TEAM_CT: client_print_color(0, BLUE, "^4[ INFO ]^1 Player ^3%s^1 banned ( %s )", szTargetName, szReason)
case CS_TEAM_T: client_print_color(0, RED, "^4[ INFO ]^1 Player ^3%s^1 banned ( %s )", szTargetName, szReason)
case CS_TEAM_SPECTATOR: client_print_color(0, GREY, "^4[ INFO ]^1 Player ^3%s^1 banned ( %s )", szTargetName, szReason)
}
new szIp[33];
get_user_ip(player, szIp, 32, 1)
client_print(player, print_console, "--------------------------------")
client_print(player, print_console, "-------- You are banned --------")
client_print(player, print_console, "*** by: %s", szAdminName)
client_print(player, print_console, "*** reason: %s", szReason)
client_print(player, print_console, "*** for: %s", szTime)
client_print(player, print_console, "-------- You are banned --------")
client_print(player, print_console, "--------------------------------")
client_cmd(player, "disconnect")
new szTemp[512]
format(szTemp,charsmax(szTemp),"INSERT INTO `bans` ( `ip` , `ban_time`, `ban_reason`, `ban_admin`)VALUES ('%s','%f', '%s', '%s');", szIp, Float:iBan[player], szReason, szAdminName)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szT emp)
return PLUGIN_HANDLED_MAIN;
}
if(equali(szCmd, "!kick"))
{
strbreak(szArg, szTarget, charsmax(szTarget), szReason, charsmax(szReason))
if(!szTarget[0] || !szReason[0])
{
client_print_color(id, DontChange, "^4[ INFO ]^1 Usage: ^3!kick player_name kick_reason")
return PLUGIN_HANDLED_MAIN;
}
new szAdminName[33];
get_user_name(id, szAdminName, 32)
new player = cmd_target(id, szTarget);
if(!player)
return PLUGIN_HANDLED;
new szTargetName[33];
get_user_name(player, szTargetName, 32)
switch(cs_get_user_team(player))
{
case CS_TEAM_CT: client_print_color(0, BLUE, "^4[ INFO ]^1 Player ^3%s^1 kicked ( %s )", szTargetName, szReason)
case CS_TEAM_T: client_print_color(0, RED, "^4[ INFO ]^1 Player ^3%s^1 kicked ( %s )", szTargetName, szReason)
case CS_TEAM_SPECTATOR: client_print_color(0, GREY, "^4[ INFO ]^1 Player ^3%s^1 kicked ( %s )", szTargetName, szReason)
}
client_print(player, print_console, "--------------------------------")
client_print(player, print_console, "-------- You are kicked --------")
client_print(player, print_console, "*** by: %s", szAdminName)
client_print(player, print_console, "*** reason: %s", szReason)
client_print(player, print_console, "-------- You are kicked --------")
client_print(player, print_console, "--------------------------------")
client_cmd(player, "disconnect")
return PLUGIN_HANDLED_MAIN;
}
return PLUGIN_CONTINUE;
}
public CmdSayTeam(id)
{
if(Float:iMute[id] > get_systime() )
{
//static szDate[32]
//format_time(szDate, charsmax(szDate), "%a, %b %d at %H:%M:%S", iMute[id])
//client_print_color(id, DontChange, "^4[ INFO ]^1 You are ^3mutted^1, mute expires: %s", szDate)
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public MySql_Init()
{
g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,char smax(g_Error))
if(SqlConnection == Empty_Handle)
set_fail_state(g_Error)
new Handle:Queries
Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS bans (ip varchar(32),mute_time INT(20), mute_reason varchar(50), mute_admin varchar(32), ban_time INT(20), ban_reason varchar(50), ban_admin varchar(32) )")
if(!SQL_Execute(Queries))
{
SQL_QueryError(Queries,g_Error,charsmax(g_Err or))
set_fail_state(g_Error)
}
SQL_FreeHandle(Queries)
SQL_FreeHandle(SqlConnection)
}
public plugin_end()
{
SQL_FreeHandle(g_SqlTuple)
}
public Load_MySql(id)
{
new szIp[33], szTemp[512]
get_user_ip(id, szIp, 32, 1)
new Data[1]
Data[0] = id
format(szTemp,charsmax(szTemp),"SELECT * FROM `bans` WHERE (`bans`.`ip` = '%s')", szIp)
SQL_ThreadQuery(g_SqlTuple,"register_client", szTemp,Data,1)
}
public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
{
log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
new id
id = Data[0]
if(SQL_NumResults(Query) >= 1)
{
//iMute[id] = SQL_ReadResult(Query, 1)
SQL_ReadResult( Query, 1, iMute[id]);
SQL_ReadResult( Query, 2, iMuteReason[id], charsmax( iMuteReason[ ] ) )
SQL_ReadResult( Query, 3, iMuteAdmin[id], charsmax( iMuteAdmin[ ] ) )
//iBan[id] = SQL_ReadResult(Query, 4)
SQL_ReadResult( Query, 4, iBan[id]);
SQL_ReadResult( Query, 5, iBanReason[id], charsmax( iBanReason[ ] ) )
SQL_ReadResult( Query, 6, iBanAdmin[id], charsmax( iBanAdmin[ ] ) )
}
//static szDate[32]
//format_time(szDate, charsmax(szDate), "%a, %b %d at %H:%M:%S", iBan[id])
if( iBan[id] > get_systime() )
{
client_print(id, print_console, "*------* *------------* *------*")
client_print(id, print_console, "*------* You are banned *------*")
client_print(id, print_console, "*** by: %s", iBanAdmin[id])
client_print(id, print_console, "*** for: %s", iBanReason[id])
//client_print(id, print_console, "*** expires: %s", szDate)
client_print(id, print_console, "*------* You are banned *------*")
client_print(id, print_console, "*------* *------------* *------*")
client_cmd(id, "disconnect")
}
return PLUGIN_HANDLED
}
public client_disconnect(id)
{
Save_MySql(id);
iMute[id] = 0.0;
iMuteReason[id][0] = '^0'
iMuteAdmin[id][0] = '^0'
iBan[id] = 0.0;
iBanReason[id][0] = '^0'
iBanAdmin[id][0] = '^0'
}
public Save_MySql(id)
{
if( iBan[id] < get_systime() && iMute[id] < get_systime() )
{
new szIp[33];
get_user_ip(id, szIp, 32, 1)
new szTemp[512]
format(szTemp,charsmax(szTemp),"DELETE * FROM `bans` WHERE (`bans`.`ip` = '%s')", szIp)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szT emp)
}
}
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
SQL_FreeHandle(Query)
return PLUGIN_HANDLED
}
public client_putinserver(id)
{
Load_MySql(id)
}
Why the mute is not working ? I set user mute but he is still able to chat, same with ban.