View Single Post
Author Message
ghostz0r
Senior Member
Join Date: Dec 2012
Old 12-25-2016 , 06:11   [help] bad player list
Reply With Quote #1

hello guys, i tried to make blacklist with bad players with sql database, i don't know how to make sql request to check players, help pls to

this code have black_list.ini file in configs dir, all players writed inside this file like a
;nickname
STEAMID

Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#define PLUGIN "Black List SQLx"
#define VERSION "0.000"
#define AUTHOR "zerz0r"

new const user_file[] = "black_list.ini"
new Array:BlackList

new Handle:SQL_Tuple
new Handle:SQL_Connection 

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
    SQL_Tuple = SQL_MakeDbTuple("host","user","password","database")
    new err, error[256]
    SQL_Connection = SQL_Connect(SQL_Tuple, err, error, charsmax(error))
     
    if(SQL_Connection != Empty_Handle)
	{
        log_amx("[SQLx connect ok]") 
        }else{
        log_amx("[SQLX sql error] %s ",error)
        pause("a")
    }
     
}

public plugin_precache()
{
	BlackList = ArrayCreate(32, 1)
	read_user_from_file()
}

public read_user_from_file()
{
	static user_file_url[64], config_dir[32]
	
	get_configsdir(config_dir, sizeof(config_dir))
	format(user_file_url, sizeof(user_file_url), "%s/%s", config_dir, user_file)
	
	if(!file_exists(user_file_url))
		return
	
	static file_handle, line_data[64], line_count
	file_handle = fopen(user_file_url, "rt")
	
	while(!feof(file_handle))
	{
		fgets(file_handle, line_data, sizeof(line_data))
		
		replace(line_data, charsmax(line_data), "^n", "")
		
		if(!line_data[0] || line_data[0] == ';') 
			continue
			
		ArrayPushString(BlackList, line_data)
		line_count++
	}
	
	fclose(file_handle)
}

public client_connect(id)
{
	check_and_handle(id)
}

public client_infochanged(id)
{
	check_and_handle(id)
}

public check_and_handle(id)
{
	static name[64], steamid[32], Data[32]
	
	get_user_name(id, name, sizeof(name))
	get_user_steamid(id, steamid, sizeof(steamid))
	
	for(new i = 0; i < ArraySize(BlackList); i++)
	{
		ArrayGetString(BlackList, i, Data, sizeof(Data))
		
		if(equal(name, Data) || equal(steamid, Data))
		{
		server_cmd("amx_kick %s kappa^n", name)
		client_printcolor(0, "!g[BL]!y !t%s!y bad PLAYER. Kick !t%s!y !!!", name, name)
		}
	}
}
stock client_printcolor(const id, const input[], any:...)
{
	new iCount = 1, iPlayers[32]
	static szMsg[191]
	
	vformat(szMsg, charsmax(szMsg), input, 3)
	replace_all(szMsg, 190, "!g", "^4")
	replace_all(szMsg, 190, "!y", "^1")
	replace_all(szMsg, 190, "!t", "^3")
	
	if(id) iPlayers[0] = id
	else get_players(iPlayers, iCount, "ch")
	
	for (new i = 0; i < iCount; i++)
	{
		if(is_user_connected(iPlayers[i]))
		{
			message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, iPlayers[i])
			write_byte(iPlayers[i])
			write_string(szMsg)
			message_end()
		}
	}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1066\\ f0\\ fs16 \n\\ par }
*/

Last edited by ghostz0r; 12-25-2016 at 06:13.
ghostz0r is offline