|
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define PLUGIN "UserRegister System"
#define VERSION "1.0"
#define AUTHOR "Alka"
#define TASK_CHECK_LOG 2223
#define TASK_CHECK_REG 2132
#define PASSWORD_MIN_LEN 6
#define MAX_LOGIN_ATTEMPTS 3
#define STORE_REGISTER_DATE
new bool:user_is_registerd[33];
new user_saved_password[33][32];
new bool:user_has_loged[33];
new bool:user_has_registerd[33];
new bool:user_has_changed_pass[33];
new attempts[33];
new users_db_file[256];
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_dictionary("userregister_system.txt");
register_concmd("amx_register", "register_user", ADMIN_ALL, "<mod:1[Name],2[Ip],3[SteamID]> <password>");
register_concmd("amx_login", "login_user", ADMIN_ALL, "<password>");
register_concmd("amx_changepassword", "change_password", ADMIN_ALL, "<old password> <new password>");
register_forward(FM_ClientUserInfoChanged, "Fwd_ClientInfoChanged");
check_db();
}
public check_db()
{
new datadir[64];
get_datadir(datadir, 63);
format(users_db_file, sizeof users_db_file - 1, "%s/users_db.ini", datadir);
new file_pointer = fopen(users_db_file, "r");
if(!file_pointer)
{
server_print("%L", LANG_SERVER, "ERROR_DB", users_db_file);
write_file(users_db_file, "");
}
fclose(file_pointer);
}
public client_putinserver(id)
{
new Steamid[32], Ip[32], Name[32];
get_user_authid(id, Steamid, 31);
get_user_ip(id, Ip, 31, 1);
get_user_name(id, Name, 31);
new parm[1];
parm[0] = id;
check_user(id, Steamid, Ip, Name);
set_task(3.0, "warn_user", id);
if(user_is_registerd[id])
set_task(13.0, "check_user_login", TASK_CHECK_LOG, parm, 1);
else
set_task(18.0, "check_user_reg", TASK_CHECK_REG, parm, 1);
}
public client_disconnect(id)
{
if(user_has_loged[id])
user_has_loged[id] = false;
if(user_has_registerd[id])
user_has_registerd[id] = false;
if(user_has_changed_pass[id])
user_has_changed_pass[id] = false;
attempts[id] = 0;
}
public warn_user(id)
{
if(user_is_registerd[id])
{
set_hudmessage(255, 0, 0, -1.0, -1.0, 1, 6.0, 5.0, 0.1, 0.1, -1);
show_hudmessage(id, "%L", LANG_PLAYER, "LOGIN_ADV_HUD");
client_print(id, print_chat, "%L", LANG_PLAYER, "LOGIN_ADV_CHAT");
}
else
{
set_hudmessage(255, 0, 0, -1.0, -1.0, 1, 6.0, 5.0, 0.1, 0.1, -1);
show_hudmessage(id, "%L", LANG_PLAYER, "REGISTER_ADV_HUD");
client_print(id, print_chat, "%L", LANG_PLAYER, "REGISTER_ADV_CHAT");
}
}
public register_user(id, level, cid)
{
if(!cmd_access(id, level, cid, 2))
return 1;
new name[32], ip[32], steamid[32];
new arg_mod[4], arg_pass[32];
new Buffer[256], Buffer2[128];
read_argv(1, arg_mod, 3);
read_argv(2, arg_pass, 31);
new adate[128];
get_time("%x", adate, sizeof adate - 1);
new mod = str_to_num(arg_mod);
new len = strlen(arg_pass);
switch(mod)
{
case 1:
{
get_user_name(id, name, 31);
format(Buffer, sizeof Buffer - 1, "^"%s^" ^"%s^"^n", name, arg_pass);
#if defined STORE_REGISTER_DATE
format(Buffer2, sizeof Buffer2 - 1, ";Register date: %s^n^n", adate);
#endif
}
case 2:
{
get_user_ip(id, ip, 31, 1);
format(Buffer, sizeof Buffer - 1, "^"%s^" ^"%s^"^n", ip, arg_pass);
#if defined STORE_REGISTER_DATE
format(Buffer2, sizeof Buffer2 - 1, ";Register date: %s^n^n", adate);
#endif
}
case 3:
{
get_user_authid(id, steamid, 31);
format(Buffer, sizeof Buffer - 1, "^"%s^" ^"%s^"^n", steamid, arg_pass);
#if defined STORE_REGISTER_DATE
format(Buffer2, sizeof Buffer2 - 1, ";Register date: %s^n^n", adate);
#endif
}
}
if(cont_exists(users_db_file, name, ip, steamid))
{
client_print(id, print_console, "%L", LANG_PLAYER, "ACCOUNT_EXISTS");
return 1;
}
if(len < PASSWORD_MIN_LEN)
{
client_print(id, print_console, "%L", LANG_PLAYER, "PASSWORD_LEN", PASSWORD_MIN_LEN);
return 1;
}
client_print(id, print_console, "%L", LANG_PLAYER, "REGISTER_OK", arg_pass);
user_has_registerd[id] = true;
new file = fopen(users_db_file, "at+");
fprintf(file, Buffer);
fprintf(file, Buffer2);
fclose(file);
return 1;
}
public login_user(id, level, cid)
{
if(!cmd_access(id, level, cid, 1))
return 1;
if(user_has_loged[id])
{
client_print(id, print_console, "%L", LANG_PLAYER, "ALREADY_LOGEDIN");
return 1;
}
new arg_pass[32];
read_argv(1, arg_pass, 31);
if(!equali(arg_pass, user_saved_password[id]))
{
attempts[id] += 1;
if(attempts[id] >= MAX_LOGIN_ATTEMPTS)
{
server_cmd("kick #%i ^"Sorry you enterd a invalid password %d times in a row!^"", get_user_userid(id), MAX_LOGIN_ATTEMPTS);
return 1;
}
client_print(id, print_console, "%L", LANG_PLAYER, "PASSWORD_INVALID", attempts[id], MAX_LOGIN_ATTEMPTS);
return 1;
}
else
{
client_print(id, print_console, "%L", LANG_PLAYER, "LOGIN_OK");
user_has_loged[id] = true;
}
return 1;
}
public change_password(id, level, cid)
{
if(!cmd_access(id, level, cid, 2))
return 1;
if(user_has_changed_pass[id])
{
client_print(id, print_console, "%L", LANG_PLAYER, "PASSWORD_WAIT_TIME");
return 1;
}
new arg_old_pass[32], arg_new_pass[32];
read_argv(1, arg_old_pass, 31);
read_argv(2, arg_new_pass, 31);
new name[32], ip[32], steamid[32];
get_user_name(id, name, 31);
get_user_ip(id, ip, 31, 1);
get_user_authid(id, steamid, 31);
new len = strlen(arg_new_pass);
if(!equali(arg_old_pass, user_saved_password[id]))
{
client_print(id, print_console, "%L", LANG_PLAYER, "PASSWORD_NOMATCH");
return 1;
}
if(len < PASSWORD_MIN_LEN)
{
client_print(id, print_console, "%L", LANG_PLAYER, "PASSWORD_LEN#2", PASSWORD_MIN_LEN);
return 1;
}
new file = fopen(users_db_file, "rt");
if(file)
{
new Buffer[128];
new counter;
while(!feof(file))
{
fgets(file, Buffer, 128);
parse(Buffer, Buffer, sizeof Buffer -1);
if(equal(Buffer, steamid) || equal(Buffer, ip) || equal(Buffer, name))
{
format(Buffer, sizeof Buffer - 1, "^"%s^" ^"%s^"", Buffer, arg_new_pass);
write_file(users_db_file, Buffer, counter);
}
counter++;
}
fclose(file);
client_print(id, print_console, "%L", LANG_PLAYER, "PASSWORD_NEW", arg_new_pass);
user_has_changed_pass[id] = true;
}
return 1;
}
public check_user_reg(parm[])
{
new id = parm[0];
if(!user_has_registerd[id])
{
server_cmd("kick #%i ^"You must to register to play in this server!^"", get_user_userid(id));
}
else
return 1;
return 0;
}
public check_user_login(parm[])
{
new id = parm[0];
if(!user_has_loged[id])
{
server_cmd("kick #%i ^"You must to login! Please retry...^"", get_user_userid(id));
}
else
return 1;
return 0;
}
stock check_user(id, steamid[], ip[], name[])
{
new szFile = fopen(users_db_file, "rt");
new Buffer[256], file_id[32], file_password[32];
while(!feof(szFile))
{
fgets(szFile, Buffer, 255);
if((strlen(Buffer) < 2) || Buffer[0] == ';')
continue;
parse(Buffer, file_id, 31, file_password, 31);
if(equal(file_id, steamid) || equal(file_id, ip) || equal(file_id, name))
{
user_is_registerd[id] = true;
user_saved_password[id] = file_password;
break;
}
}
fclose(szFile);
return 0;
}
stock bool:cont_exists(file[],name[], ip[], steamid[])
{
new file_pointer = fopen(file, "rt");
new Buffer[256];
while (!feof(file_pointer))
{
fgets(file_pointer, Buffer, 31);
if(containi(Buffer, name) != -1 || containi(Buffer, ip) != -1 || containi(Buffer, steamid) != -1)
{
fclose(file_pointer);
return true;
}
}
return false;
}
public Fwd_ClientInfoChanged(id, buffer)
{
if (!is_user_connected(id))
return FMRES_IGNORED;
static name[32], val[32];
get_user_name(id, name, sizeof name - 1)
engfunc(EngFunc_InfoKeyValue, buffer, "name", val, sizeof val - 1);
if(equal(val, name))
return FMRES_IGNORED;
engfunc(EngFunc_SetClientKeyValue, id, buffer, "name", name);
client_cmd(id, "name ^"%s^"; setinfo name ^"%s^"", name, name);
client_print(id, print_console, "%L", LANG_PLAYER, "NO_NAME_CHANGE");
return FMRES_SUPERCEDE;
}
该插件经调试,可以使用!若有汉化或优化的版本,不妨分享一下! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注个册吧
×
|