Addons CSO

Esse fórum tem como objetivo ajudar jogadores de Counter-Strike 1.6 a instalar mods do Counter-Strike: Online.


Você não está conectado. Conecte-se ou registre-se

Sistema de Registro

Ver o tópico anterior Ver o tópico seguinte Ir em baixo  Mensagem [Página 1 de 1]

1SMA Sistema de Registro em Seg 25 Abr 2016 - 17:38

MekaBR

avatar
Admin
Código:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <sqlx>

#define TASK_MESS 2133
#define TASK_KICK 3312
#define SALT "8c4f4370c53e0c1e1ae9acd577dddbed"

new g_on, g_save, g_mess, g_regtime, g_logtime, g_pass_length, g_attempts, g_reg_dt, g_chp_dt, g_name, g_pass_pr, g_host, g_user, g_pass, g_db;
new reg_file[256], conf_dir[64], file[192], params[2];
new name[32], check_name[32], check_pass[34], namepass[512], typedpass[32], old_pass[32], new_pass[32], passsalt[64], hash[34], pass_prefix[32];
new bool:is_logged[33], bool:is_registered[33], attempts[33], times[33];
new Handle:g_SQLTuple
new g_error[512]
new password[34][34];
new SayTxT;
new const prefix[]="^3|^4MKS^3|^1";

public plugin_init()
{
 register_plugin("Meka | Registro", "1.0", "Meka")

 g_on = register_cvar("rs_on", "1")
 g_save = register_cvar("rs_save_type", "0")
 g_mess = register_cvar("rs_messages", "3")
 g_regtime = register_cvar("rs_register_time", "0")
 g_logtime = register_cvar("rs_login_time", "60.0")
 g_pass_length = register_cvar("rs_password_length", "6")
 g_attempts = register_cvar("rs_attempts", "3")
 g_reg_dt = register_cvar("rs_register_datetime", "1")
 g_chp_dt = register_cvar("rs_chngpass_datetime", "1")
 g_name = register_cvar("rs_name_change", "1")
 g_pass_pr = register_cvar("rs_password_prefix", "_rspasss")
 g_host = register_cvar("rs_host", "127.0.0.1")
 g_user = register_cvar("rs_user", "root")
 g_pass = register_cvar("rs_pass", "")
 g_db = register_cvar("rs_db", "registersystem")

 register_message(get_user_msgid("ShowMenu"), "ShowMenu")
 register_message(get_user_msgid("VGUIMenu"), "VGUIMenu")
 register_menucmd(register_menuid("Main Menu"), 1023, "HandleMenu")
 register_menucmd(register_menuid("Password Menu"), 1023, "HandleConfirmPassword")
 register_clcmd("say /registro", "Menu")
 register_clcmd("say_team /registro", "Menu")
 register_clcmd("LOGIN_PASS", "Login");
 register_clcmd("REGISTER_PASS", "Register")

 register_forward(FM_ClientUserInfoChanged, "NameChange")

 register_dictionary("registro.txt")
 SayTxT = get_user_msgid("SayText")
}

public plugin_cfg()
{
 if(!get_pcvar_num(g_on))
 return PLUGIN_HANDLED

 get_configsdir(conf_dir, charsmax(conf_dir))
 formatex(file, charsmax(file), "%s/registros/config.cfg", conf_dir)
 
 if(!file_exists(file))
 {
 server_print("Arquivo %s nao encontrado!", file)
 }
 else
 {
 server_cmd("exec %s", file);
 server_print("Config: SitemaRegistro sendo executado..")
 }

 if(get_pcvar_num(g_save))
 {
 MYSQL()
 }
 else
 {
 File()
 }
 return PLUGIN_CONTINUE
}

public File()
{
 get_configsdir(conf_dir, charsmax(conf_dir))
 formatex(reg_file, charsmax(reg_file), "%s/registros/usuarios.ini", conf_dir)
 
 if(!file_exists(reg_file))
 {
 write_file(reg_file,";Register System file^n;Modifying may cause the clients to can not Login!^n^n")
 server_print("%L", LANG_SERVER, "FILE_ERROR", reg_file)
 }
}

public MYSQL()
{
 new Host[64], User[32], Pass[32], DB[128];

 get_pcvar_string(g_host, Host, charsmax(Host))
 get_pcvar_string(g_user, User, charsmax(User))
 get_pcvar_string(g_pass, Pass, charsmax(Pass))
 get_pcvar_string(g_db, DB, charsmax(DB))

 g_SQLTuple = SQL_MakeDbTuple(Host, Pass, Pass, DB)

 new errorcode, Handle:SqlConnection = SQL_Connect(g_SQLTuple, errorcode, g_error, charsmax(g_error))

 if(SqlConnection == Empty_Handle)
 {
 server_print("MySQL connection failed")
 set_fail_state(g_error)
 }
 else
 {
 server_print("MySQL connection succesful")
 }

 new Handle:Query

 Query = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS registersystem (Name VARCHAR(32), Password VARCHAR(34), Registered VARCHAR(25), Pass_Change VARCHAR(25))")

 if(!SQL_Execute(Query))
 {
 SQL_QueryError(Query, g_error, charsmax(g_error))
 set_fail_state(g_error)
 }

 SQL_FreeHandle(Query)
 SQL_FreeHandle(SqlConnection)
}

public client_connect(id)
{
 is_logged[id] = false
 is_registered[id] = false
 attempts[id] = 0
 remove_task(id+TASK_MESS)
 remove_task(id+TASK_KICK)
 CheckUser(id)
}

public client_putinserver(id)
{
 ShowMess(id)
}

public client_disconnect(id)
{
 is_logged[id] = false
 is_registered[id] = false
 attempts[id] = 0
 remove_task(id+TASK_MESS)
 remove_task(id+TASK_KICK)
}

public ShowMenu(msgid, dest, id)
{
 new menu_text[64]

 get_msg_arg_string(4, menu_text, charsmax(menu_text))

 if(!equal(menu_text, "#Team_Select") || !equal(menu_text, "#Team_Select_Spect"))
 {
 return PLUGIN_CONTINUE
 }

 if(!is_registered[id] && get_pcvar_float(g_regtime) != 0)
 {
 return PLUGIN_HANDLED
 }
 else if(is_registered[id] && !is_logged[id])
 {
 return PLUGIN_HANDLED
 }

 return PLUGIN_CONTINUE
}

public VGUIMenu(msgid, dest, id)
{
 if(get_msg_arg_int(1) != 2)
 {
 return PLUGIN_CONTINUE
 }

 if(!is_registered[id] && get_pcvar_float(g_regtime) != 0)
 {
 return PLUGIN_HANDLED
 }
 else if(is_registered[id] && !is_logged[id])
 {
 return PLUGIN_HANDLED
 }

 return PLUGIN_CONTINUE
}

public CheckUser(id)
{
 if(!get_pcvar_num(g_on) || is_user_bot(id))
 return PLUGIN_HANDLED

 if(get_pcvar_num(g_save))
 {
 new query[512]
 get_user_name(id, name, charsmax(name))

 new data[1]
 data[0] = id

 formatex(query, charsmax(query), "SELECT `Password` FROM `registersystem` WHERE (`Name` = '%s');", name)

 SQL_ThreadQuery(g_SQLTuple, "QuerySelectData", query, data, 1)
 }
 else
 {
 new file = fopen(reg_file, "r")

 while(!feof(file))
 {
 get_user_name(id, name, charsmax(name))
 fgets(file, namepass, charsmax(namepass))
 parse(namepass, check_name, charsmax(check_name), check_pass, charsmax(check_pass))

 if(namepass[0] == ';')
 continue

 if(equal(check_name, name))
 {
 is_registered[id] = true
 password[id] = check_pass
 CheckAutoLogin(id)

 break
 }
 }
 fclose(file)
 }
 return PLUGIN_CONTINUE
}

public QuerySelectData(FailState, Handle:Query, error[], errorcode, data[], datasize, Float:fQueueTime)
{
 if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED)
 {
 log_amx("%s", error)
 return
 }
 else
 {
 new id = data[0];
 new Colpass = SQL_FieldNameToNum(Query, "Password")

 while(SQL_MoreResults(Query))
 {
 SQL_ReadResult(Query, Colpass, check_pass, charsmax(check_pass))
 is_registered[id] = true
 password[id] = check_pass
 CheckAutoLogin(id)
 SQL_NextRow(Query)
 }
 }
}

public CheckAutoLogin(id)
{
 new client_password[32];
 get_pcvar_string(g_pass_pr, pass_prefix, charsmax(pass_prefix))
 get_user_info(id, pass_prefix, client_password, charsmax(client_password))
 formatex(passsalt, charsmax(passsalt), "%s%s", client_password, SALT)
 md5(passsalt, hash)
 
 if(equal(hash, password[id]))
 {
 is_logged[id] = true
 }
}

public ShowMess(id)
{
 if(!get_pcvar_num(g_on))
 return PLUGIN_HANDLED

 set_task(5.0, "Messages", id+TASK_MESS)

 params[0] = id

 if(!is_registered[id])
 {
 if(get_pcvar_float(g_regtime) != 0)
 {
 params[1] = 1
 set_task(get_pcvar_float(g_regtime), "KickPlayer", id+TASK_KICK, params, sizeof params)
 return PLUGIN_HANDLED
 }
 }
 else
 {
 params[1] = 2
 set_task(get_pcvar_float(g_logtime), "KickPlayer", id+TASK_KICK, params, sizeof params)
 return PLUGIN_HANDLED
 }
 return PLUGIN_CONTINUE
}

public Messages(id)
{
 id -= TASK_MESS
 
 if(get_pcvar_num(g_mess) == 1 || get_pcvar_num(g_mess) == 3)
 {
 if(!is_registered[id])
 {
 if(get_pcvar_num(g_regtime) != 0)
 {
 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 0.5, 5.0, 2.0, 2.0, -1)
 show_hudmessage(id, "%L", LANG_SERVER, "REGISTER_HUD", get_pcvar_num(g_regtime))
 }
 else
 {
 set_hudmessage(0, 255, 0, -1.0, -1.0, 0, 0.5, 5.0, 2.0, 2.0, -1)
 show_hudmessage(id, "%L", LANG_SERVER, "YOUCANREG_HUD", get_pcvar_num(g_regtime))
 }
 }
 else if(!is_logged[id])
 {
 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 0.5, 5.0, 2.0, 2.0, -1)
 show_hudmessage(id, "%L", LANG_SERVER, "LOGIN_HUD", get_pcvar_num(g_logtime))
 }
 }

 if(get_pcvar_num(g_mess) == 2 || get_pcvar_num(g_mess) == 3)
 {
 if(!is_registered[id])
 {
 if(get_pcvar_num(g_regtime) != 0)
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "REGISTER_CHAT", prefix, get_pcvar_num(g_regtime))
 }
 else
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "YOUCANREG_CHAT", prefix, get_pcvar_num(g_regtime))
 }
 }
 else if(!is_logged[id])
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "LOGIN_CHAT", prefix, get_pcvar_num(g_logtime))
 }
 }
 Menu(id)
}

public Menu(id)
{
 if(!get_pcvar_num(g_on) || !is_user_connected(id))
 return PLUGIN_HANDLED

 static menu[512];
 new keys, lenght;
 lenght = 0

 if(is_registered[id])
 {
 if(is_logged[id])
 {
 lenght += formatex(menu[lenght], charsmax(menu) - 1, "%L%L", LANG_SERVER, "MENU_LOG", LANG_SERVER, "MENU_EXIT")
 keys = MENU_KEY_0
 }
 else
 {
 lenght += formatex(menu[lenght], charsmax(menu) - 1, "%L", LANG_SERVER, "MENU_REG")
 keys = MENU_KEY_1
 }
 }
 else
 {
 lenght += formatex(menu[lenght], charsmax(menu) - 1, "%L", LANG_SERVER, "MENU_NOT_REG", get_pcvar_num(g_regtime) != 0 ? "" : "\w")
 keys = MENU_KEY_2
 
 if(get_pcvar_num(g_regtime) == 0)
 {
 lenght += formatex(menu[lenght], charsmax(menu) - 1, "%L", LANG_SERVER, "MENU_EXIT")
 keys |= (MENU_KEY_0)
 }
 }
 show_menu(id, keys, menu, -1, "Main Menu")
 
 return PLUGIN_CONTINUE
}

public HandleMenu(id, key)
{
 switch(key)
 {
 case 0:
 {
 client_cmd(id, "messagemode LOGIN_PASS")
 Menu(id)
 }
 case 1:
 {
 client_cmd(id, "messagemode REGISTER_PASS")
 Menu(id)
 }
 case 2:
 {
 client_cmd(id, "messagemode CHANGE_PASS")
 Menu(id)
 }
 case 3:
 {
 Menu(id)
 }
 case 9:
 {
 return PLUGIN_HANDLED
 }
 }
 return PLUGIN_HANDLED
}

public Login(id)
{
 if(!get_pcvar_num(g_on))
 return PLUGIN_HANDLED

 if(!is_registered[id])
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "LOG_NOTREG", prefix)
 return PLUGIN_HANDLED
 }

 if(is_logged[id])
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "LOG_LOGGED", prefix);
 return PLUGIN_HANDLED
 }
 
 read_argv(1, typedpass, charsmax(typedpass))

 if(equal(typedpass, ""))
 return PLUGIN_HANDLED

 formatex(passsalt, charsmax(passsalt), "%s%s", typedpass, SALT)
 md5(passsalt, hash)

 if(!equal(hash, password[id]))
 {
 attempts[id]++
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "LOG_PASS_INVALID", prefix, attempts[id], get_pcvar_num(g_attempts))

 if(attempts[id] >= get_pcvar_num(g_attempts))
 {
 params[0] = id
 params[1] = 3
 set_task(2.0, "KickPlayer", id+TASK_KICK, params, sizeof params)
 return PLUGIN_HANDLED
 }
 else
 {
 client_cmd(id, "messagemode LOGIN_PASS")
 }
 return PLUGIN_HANDLED
 }
 else
 {
 is_logged[id] = true
 attempts[id] = 0
 remove_task(id+TASK_KICK)
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "LOG_LOGING", prefix)
 get_pcvar_string(g_pass_pr, pass_prefix, charsmax(pass_prefix))
 client_cmd(id, "setinfo %s %s",pass_prefix, typedpass)
 Menu(id)
 }
 return PLUGIN_CONTINUE
}

public Register(id)
{
 if(!get_pcvar_num(g_on))
 return PLUGIN_HANDLED

 read_argv(1, typedpass, charsmax(typedpass))
 new passlength = strlen(typedpass)

 if(equal(typedpass, ""))
 return PLUGIN_HANDLED
 
 if(is_registered[id])
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "REG_EXISTS", prefix)
 return PLUGIN_HANDLED
 }

 if(passlength < get_pcvar_num(g_pass_length))
 {
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "REG_LEN", prefix, get_pcvar_num(g_pass_length))
 client_cmd(id, "messagemode REGISTER_PASS")
 return PLUGIN_HANDLED
 }

 password[id] = typedpass
 ConfirmPassword(id)
 return PLUGIN_CONTINUE
}

public ConfirmPassword(id)
{
 if(!get_pcvar_num(g_on) || !is_user_connected(id))
 return PLUGIN_HANDLED

 static passmenu[256];
 new keys;

 formatex(passmenu, charsmax(passmenu), "%L", LANG_SERVER, "MENU_PASS", password[id])
 keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_0
 
 show_menu(id, keys, passmenu, -1, "Password Menu")
 return PLUGIN_CONTINUE
}

public HandleConfirmPassword(id, key)
{
 switch(key)
 {
 case 0:
 {
 new datetime[26];
 get_user_name(id, name, charsmax(name))
 get_time("on %d/%m/%Y at %H:%M:%S", datetime, 25)
 formatex(passsalt, charsmax(passsalt), "%s%s", password[id],  SALT)
 md5(passsalt, hash)

 if(is_registered[id])
 {
 if(get_pcvar_num(g_save))
 {
 if(get_pcvar_num(g_chp_dt))
 {
 formatex(namepass, charsmax(namepass), "UPDATE registersystem SET Password = '%s', Pass_Change = '%s' WHERE Name = '%s';", hash, datetime, name)
 }
 else
 {
 formatex(namepass, charsmax(namepass), "UPDATE registersystem SET Password = '%s' WHERE Namå = '%s';", hash, name)
 }
 SQL_ThreadQuery(g_SQLTuple, "QuerySetData", namepass)
 }
 else
 {
 new file = fopen(reg_file, "r");
 new line;

 while(!feof(file))
 {
 fgets(file, namepass, 255)
 line++
 parse(namepass, namepass, charsmax(namepass))

 if(equal(namepass, name))
 {
 if(get_pcvar_num(g_chp_dt))
 {
 formatex(namepass, charsmax(namepass), "^"%s^" ^"%s^" //Password changed %s", name, hash, datetime)
 }
 else
 {
 formatex(namepass, charsmax(namepass), "^"%s^" ^"%s^"", name, hash)
 }
 write_file(reg_file, namepass, line - 1)

 break
 }
 }
 fclose(file)
 }
 get_pcvar_string(g_pass_pr, pass_prefix, charsmax(pass_prefix))
 client_cmd(id, "setinfo %s %s",pass_prefix, password[id])
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "CHANGE_NEW", new_pass)
 password[id] = hash
 times[id]++
 }
 else
 {
 if(get_pcvar_num(g_save))
 {
 if(get_pcvar_num(g_chp_dt))
 {
 formatex(namepass, charsmax(namepass), "INSERT INTO `registersystem` (`Name`, `Password`, `Registered`) VALUES ('%s', '%s', '%s');", name, hash, datetime)
 }
 else
 {
 formatex(namepass, charsmax(namepass), "INSERT INTO `registersystem` (`Name`, `Password`) VALUES ('%s', '%s');", name, hash)
 }
 SQL_ThreadQuery(g_SQLTuple, "QuerySetData", namepass)
 }
 else
 {
 new file = fopen(reg_file, "a")
 if(get_pcvar_num(g_reg_dt))
 {
 format(namepass, charsmax(namepass), "^n^"%s^" ^"%s^"^n;Account Created %s^n", name, hash, datetime)
 }
 else
 {
 format(namepass, charsmax(namepass), "^n^"%s^" ^"%s^"", name, hash)
 }
 fprintf(file, namepass)
 fclose(file)
 }
 remove_task(id+TASK_KICK)
 params[1] = 2
 set_task(get_pcvar_float(g_logtime), "KickPlayer", id+TASK_KICK, params, sizeof params)
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "REG_REGIS", password[id], get_pcvar_num(g_logtime))
 is_registered[id] = true
 password[id] = hash
 }
 Menu(id)
 }
 case 1:
 {
 password[id] = old_pass
 if(is_registered[id])
 {
 client_cmd(id, "messagemode CHANGE_PASS")
 }
 else
 {
 client_cmd(id, "messagemode REGISTER_PASS")
 }
 }
 case 9:
 {
 Menu(id)
 password[id] = old_pass
 return PLUGIN_HANDLED
 }
 }
 return PLUGIN_HANDLED
}

public QuerySetData(FailState, Handle:Query, error[],errcode, data[], datasize)
{
 if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED)
 {
 log_amx("%s", error)
 return
 }
}

public NameChange(id)
{
 if(!get_pcvar_num(g_on) || !is_user_connected(id))
 return FMRES_IGNORED

 new oldname[32], newname[32]
 pev(id, pev_netname, oldname, charsmax(oldname))
 if(oldname[0])
 {
 get_user_info(id, "name", newname, charsmax(newname))
 if(!equal(oldname, newname))
 {
 if(get_pcvar_num(g_name))
 {
 set_user_info(id, "name", oldname)
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "NAME_CHANGE", prefix)
 return FMRES_HANDLED
 }
 else
 {
 if(is_logged[id])
 {
 set_user_info(id, name, oldname)
 client_printcolor(id, "%s %L",prefix, LANG_SERVER, "NAME_CHANGE", prefix)
 return FMRES_HANDLED
 }
 else
 {
 if(is_registered[id])
 {
 is_registered[id] = false
 remove_task(id+TASK_KICK)
 }
 CheckUser(id)
 ShowMess(id)
 }
 }
 }
 }
 return FMRES_IGNORED
}

public KickPlayer(parameter[])
{
 new id = parameter[0]
 new reason = parameter[1]

 if(is_user_connected(id))
 {
 new userid = get_user_userid(id)
 
 if(reason == 1)
 {
 if(is_registered[id])
 return PLUGIN_HANDLED

 server_cmd("kick #%i ^"%L^"", userid, LANG_PLAYER, "KICK_REG")
 return PLUGIN_CONTINUE
 }
 else if(reason == 2)
 {
 if(is_logged[id])
 return PLUGIN_HANDLED

 server_cmd("kick #%i ^"%L^"", userid, LANG_PLAYER, "KICK_LOG")
 return PLUGIN_CONTINUE
 }
 else if(reason == 3)
 {
 server_cmd("kick #%i ^"%L^"", userid, LANG_PLAYER, "KICK_ATMP", get_pcvar_num(g_attempts))
 }
 }
 return PLUGIN_CONTINUE
}

stock client_printcolor(const id, const input[], any:...)
{
 new count = 1, players[32];
 static msg[191];
 vformat(msg, 190, input, 3)
 replace_all(msg,190,"!g","^4")
 replace_all(msg,190,"!n","^1")
 replace_all(msg,190,"!t","^3")
 replace_all(msg,190,"!w","^0")
 if(id) players[0] = id
 else get_players(players , count , "ch")
 {
 for(new i = 0; i < count; i++)
 {
 if(is_user_connected(players[i]))
 {
 message_begin(MSG_ONE_UNRELIABLE, SayTxT,_, players[i])
 write_byte(players[i])
 write_string(msg)
 message_end()
 }
 }
 }
}

Ver perfil do usuário http://addonscso.forumeiros.com

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo  Mensagem [Página 1 de 1]

Permissão deste fórum:
Você não pode responder aos tópicos neste fórum