Jump to content
Sign in to follow this  
ev0x

Server Shield - Security plugin

Recommended Posts

Server Shield - Security Plugin

 

Am zis sa fac si eu o versiune de "plugin de securitate". Ce a iesit, vedeti mai jos.

Eventualele/viitoarele/posibilele update-uri vor fi postate aici.

#include <amxmodx>
#include <amxmisc>
#include <colorchat>

#define MAX_SECS 2
#define SIZE_KB 1000
#define MAX_WARNING 3

enum _:db_content
{
	name[32],
	password[15]
}

new const
	PLUGIN[] = "Server Shield",
	VERSION[] = "1.0-stable",
	TAG[] = "[Server Shield]"

new bool:is_logged[33], bool:is_in_process[33], bool:exists[33], bool:g_usechat[33], g_password[16], cfg_dir[64], text[200], newname[32], oldname[32], ip[32], g_baseDir[128], file, db_h[db_content], g_msg_saytext, language;
new Array:db_holder;
new Float:g_LastTime[32], g_Count[32];

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, ".evo")
	
	register_clcmd("say", "hook_chat");
	register_clcmd("say_team", "hook_chat");
	register_clcmd("say /reg", "set_register");
	register_clcmd("say /login", "set_login");
	register_clcmd("PAROLA", "logare");
	register_clcmd("INREGISTRARE", "register");
	
	register_srvcmd("shield_version", "info");
	
	language = register_cvar("shield_vault_language", "1");
	
	register_event("DeathMsg", "shield_death", "a");
	
	formatex(g_password, charsmax(g_password), "%c%c%c", random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'));
	g_msg_saytext = get_user_msgid("SayText");
	
	check_file()
	
	set_task(1.0, "check_file", _, _, _, "b");
	set_task(30.0, "server_execute", _, _, _, "b")
	set_task(900.0, "server_optimisation", _, _, _, "b")
}

public check_file()
{
	if(db_holder)
		ArrayDestroy(db_holder)
	db_holder = ArrayCreate(db_content)
	get_configsdir(cfg_dir, 63)
	format(cfg_dir, 63, "%s/shield_inregistrati.ini", cfg_dir)
	file = fopen(cfg_dir, "r")
	
	if(file)
	{
		static txt[512], pl_name[32], pl_password[15];
		while(!feof(file))
		{
			fgets(file, txt, charsmax(txt))
			replace(txt, charsmax(txt), "^n", "");
			trim(txt)
			if(txt[0]==';' || !txt[0]) 
				continue;
			
			pl_name[0] = 0
			pl_password[0] = 0
			
			if(parse(txt, pl_name, charsmax(pl_name), pl_password, charsmax(pl_password)) < 2)
				continue;

			db_h[name] = pl_name
			db_h[password] = pl_password
			ArrayPushArray(db_holder, db_h)
		}
		fclose(file)
	}
	else 
		log_amx("Eroare. Fisierul 'shield_inregistrati.ini' nu a fost gasit.")
}

public plugin_natives()
{
	register_native("get_logged", "check_logstatus", 1)
	register_native("is_registered", "check_status", 1);
	register_native("open_register", "set_register", 1)
	register_native("open_login", "set_login", 1)
	register_native("process", "get_process", 1);
}

public plugin_cfg()
{
	new configsdir[32];
	get_configsdir(configsdir, 31) 
	server_cmd("exec %s/server_shield.cfg", configsdir)
}

public client_putinserver(id)
{	
	g_usechat[id] = false;
	is_in_process[id] = false;
	is_logged[id] = false;
	exists[id] = false;
}

public server_execute()
{
	server_cmd("mapchangecfgfile server.cfg")
	set_task(1.0, "shield_exec")
}

public shield_exec()
{
	server_cmd("exec server.cfg")
}

public shield_death()
{
	new ids[1]
	ids[0] = read_data(2)
	set_task(1.0, "shield_fix", 0, ids, 1)
	return PLUGIN_CONTINUE
}

public get_process(id)
{
	if(!is_user_connected(id))
		return -1;
		
	return is_in_process[id];
}

public check_logstatus(id)
{
	if(!is_user_connected(id))
		return -1;
		
	return is_logged[id];
}

public check_status(id)
{
	if(!is_user_connected(id))
		return -1;
	
	if(check_exist(id))
		return true;
	else
		return false;
	return true;
}

public hook_chat(id)
{
	if(!g_usechat[id])
	{
		new chat[192];
		read_argv(1, chat, charsmax(chat));
		if(equal(g_password, chat))
		{
			ColorChat(id, RED, "%s^x01 Chat-ul tau a fost activat.", TAG);
			g_usechat[id] = true;
			return 1;
		}
		else
		{
			ColorChat(id, RED, "%s^x01 Chatul tau este momentan blocat.", TAG);
			ColorChat(id, RED, "%s^x01 Pentru a il debloca, tasteaza codul:^x03 %s^x01.", TAG, g_password);
			return 1;
		}
	}
	return 0;
}

public set_login(id)
{
	if(!is_user_connected(id) || is_logged[id] || !exists[id])
		return PLUGIN_HANDLED;
	
	client_cmd(id, "messagemode PAROLA");
	ColorChat(id, RED, "%s^x01 Te rugam sa introduci parola pentru numele:^x03 %s^x01.", TAG, get_name(id));
	ColorChat(id, RED, "%s^x01 Altfel nu vei avea acces la facilitatile contului.", TAG);
	is_in_process[id] = true
	return PLUGIN_HANDLED;
}

public logare(id)
{
	if(!is_user_connected(id) || is_logged[id] || !exists[id])
		return PLUGIN_HANDLED;
		
	static texted_password[16];
	read_args(texted_password, charsmax(texted_password))
	remove_quotes(texted_password)
	is_in_process[id] = false
	check_pass(id, texted_password)
	return PLUGIN_CONTINUE;
}

public set_register(id)
{
	if(!is_user_connected(id) || is_logged[id] || exists[id])
		return PLUGIN_HANDLED;
		
	client_cmd(id, "messagemode INREGISTRARE");
	ColorChat(id, RED, "%s^x01 Trebuie sa scrii o parola cuprinsa intre^x03 5-16^x01 caractere.", TAG)
	ColorChat(id, RED, "%s^x01 Parola ta trebuie sa fie doar din^x03 LITERE^x01 !", TAG)
	is_in_process[id] = true
	return PLUGIN_CONTINUE;
}

public register(id)
{
	if(!is_user_connected(id) || is_logged[id] || exists[id])
		return PLUGIN_HANDLED;
	
	static texted_password[16];
	read_args(texted_password, charsmax(texted_password))
	remove_quotes(texted_password)
	is_in_process[id] = false
	if(strlen(texted_password) < 5)
	{
		ColorChat(id, RED, "%s^x01 Parola introdusa de tine contine mai putin de^x03 5^x01 caractere.", TAG);
		set_register(id)
		return PLUGIN_HANDLED;
	}
	if(strlen(texted_password) > 15)
	{
		ColorChat(id, RED, "%s^x01 Parola introdusa de tine contine mai mult de^x03 15^x01 caractere.", TAG)
		set_register(id)
		return PLUGIN_HANDLED;
	}
	writefile("shield_inregistrati.ini", get_name(id), texted_password)
	exists[id] = true
	set_login(id)
	return PLUGIN_CONTINUE;
}

public writefile(const filename[], const line1[], const line2[]) 
{ 
	new file[64]; 
	get_configsdir(file, sizeof (file)); 
	format(file, sizeof (file), "%s/%s", file, filename); 

	if(!file_exists(file)) 
		return;

	new fmt[128]; 
	formatex(fmt, sizeof (fmt), "^r^n^"%s^" ^"%s^"", line1, line2); 
	write_file(file, fmt); 
}  

public check_exist(id)
{
	new size = ArraySize(db_holder)
	static numeloi[32];
	get_user_name(id, numeloi, charsmax(numeloi));
	for(new index = 0; index < size; index++) 
	{
		ArrayGetArray(db_holder, index, db_h)
		if(equal(numeloi, db_h[name]))
		{
			exists[id] = true
			break;
		}
		else
			exists[id] = false
	}
	return exists[id];
}

public check_pass(id, const text[])
{
	new size = ArraySize(db_holder)
	for(new index = 0; index < size; index++) 
	{
		ArrayGetArray(db_holder, index, db_h)
		if(equali(text, db_h[password]))
		{
			
			ColorChat(id, RED, "%s^x01 Te-ai logat cu succes pe cont.", TAG)
			ColorChat(id, RED, "%s^x01 Ai primit acces total asupra nickname-ului dar si asupra contului.", TAG)
			is_logged[id] = true
			return true;
		} 
	}
	ColorChat(id, RED, "%s^x01 Parola introdusa de tine este gresita.", TAG)
	ColorChat(id, RED, "%s^x01 Incearca din nou.", TAG)
	ColorChat(id, RED, "%s^x01 Daca ai probleme cu parola, te rugam sa contactezi support-ul.", TAG)
	exists[id] = true
	set_login(id);
	return false;
}

public client_infochanged(id) 
{
	get_user_info(id, "name", newname, 31) 
	get_user_name(id, oldname, 31) 
	get_user_ip(id, ip, 31, 1)
	
	if (strcmp(oldname,newname)!=0) 
		{ 
		if(!g_LastTime[id]) 
			{ 
			g_LastTime[id] = get_gametime() 
			return PLUGIN_CONTINUE 
		} 
		
		new Float:curtime = get_gametime() - g_LastTime[id] 
		
		if(curtime<float(MAX_SECS)) 
			{ 
			g_Count[id]+=1 
			if(g_Count[id]<=MAX_WARNING) 
				{ 
				ColorChat(id, RED, "%s^x01 Nu mai flooda serverul. Avertismente:^x04 %i^x01 din^x04 %i^x01.", g_Count[id], MAX_WARNING);
			} 
			else 
			{
				
				server_print("%s Jucatorul '%s' a incercat sa afecteze serverul prin 'nick-bug' si a primit kick.", TAG, name);
				server_cmd("kick #%d ^"Tentativa de 'nick-bug'. Ai primit kick.^"", get_user_userid(id));
				return PLUGIN_HANDLED 
			} 
		} 
		g_LastTime[id] = get_gametime() 
	} 
	return PLUGIN_CONTINUE 
}

public info(id)
{
	new rcon[64], dproto[64], amxx[12];

	get_cvar_string("rcon_password", rcon, 63)
	get_cvar_string("dp_version", dproto, 63 )
	get_amxx_verstring(amxx, 11);
	
	server_print("------------------------------------------------------");
	server_print("Nume plugin: %s.", PLUGIN);
	server_print("Versiune actuala: %s.", VERSION);
	server_print("Autor: .evo");
	server_print("Versiune dproto: %s.", dproto);
	server_print("Parola rcon: %s.", rcon);
	server_print("Versiune stabila AMXX: %s.", amxx);
	server_print("------------------------------------------------------");
}

public plugin_end()
{
	format(g_baseDir,127, "%s/data/vault.ini", g_baseDir)
	if (file_size(g_baseDir, 0)>=1024)
		{
		if (file_exists(g_baseDir))
			{
			delete_file(g_baseDir)
		}
		// Limba engleza
		if(get_pcvar_num(language) == 1)
			{
			format(text, 199, "server_language en", g_baseDir)
			server_print("%s Fisierul 'vault.ini' a fost rescris in limba engleza conform setarilor, deoarece avea o marime mai mare de 1 KB.", TAG)
			write_file(g_baseDir, text, -1) 
		}
		// Limba romana
		else 
		if(get_pcvar_num(language) == 2)
			{
			format(text, 199, "server_language ro", g_baseDir)
			server_print("%s Fisierul 'vault.ini' a fost rescris in limba romana conform setarilor, deoarece avea o marime mai mare de 1 KB.", TAG)
			write_file(g_baseDir, text , -1) 
		}
	}
	if (file_size("custom.hpk")/SIZE_KB > 1000.0)
		{
		server_print("%s Fisierul 'custom.hpk' a fost sters conform setarilor pentru ca avea marimea de %d KB.", TAG, file_size("custom.hpk")/SIZE_KB)
		delete_file("custom.hpk")
	}
}

public shield_fix(ids[])
{
	client_cmd(ids[0], "+duck; -duck; spec_menu 0")
}

public client_disconnect(id)
{
	g_usechat[id] = false;
	is_in_process[id] = false;
	is_logged[id] = false;
	exists[id] = false;
}

stock get_name(id)
{
	static nume[32];
	get_user_name(id, nume, charsmax(nume));
	return nume;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×