|
Senior Member
|

08-31-2009
, 07:31
Help with login/register system
|
#1
|
I use :
PHP Code:
public clcmd_login_name(id){ static arg[48] read_args(arg, sizeof arg) replace_all(arg, sizeof arg - 1, "login_name ", "") replace_all(arg, sizeof arg - 1, "^"", "") copy(g_login_name[id], sizeof g_login_name[] - 1, arg) show_menu_login(id) return PLUGIN_HANDLED; } public clcmd_login_password(id){ static arg[48] read_args(arg, sizeof arg) replace_all(arg, sizeof arg - 1, "login_pw ", "") replace_all(arg, sizeof arg - 1, "^"", "") copy(g_login_password[id], sizeof g_login_password[] - 1, arg) show_menu_login(id) return PLUGIN_HANDLED; } public clcmd_login(id){ if(g_login[id]){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_LOGIN_LOGINED") return PLUGIN_HANDLED; } if(contain( g_login_name[id], " ") != -1){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_LOGIN_UNABLE") return PLUGIN_HANDLED; } if(contain( g_login_password[id], " ") != -1){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_LOGIN_UNABLE") return PLUGIN_HANDLED; } static key[32], data[64] format(key, sizeof key - 1, "[Data_%s]", g_login_name[id]); new valid = nvault_get(g_Nvault, key, data, sizeof data - 1); if(!valid){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_LOGIN_NOEXIST") return PLUGIN_HANDLED; } static pw[32], startpos startpos = contain(data, "#") format(pw, startpos, "%s", data); if(!equal(g_login_password[id], pw)){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_LOGIN_PWERROR") return PLUGIN_HANDLED; } g_login[id] = 1 copy(g_username[id], sizeof g_username[] - 1, g_login_name[id]) copy(g_password[id], sizeof g_password[] - 1, g_login_password[id]) replace(data, sizeof data - 1, "pw#", "") client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_LOGIN_SUCCESS", g_login_name[id]) format(g_login_name[id], sizeof g_login_name[] - 1, " ") format(g_login_password[id], sizeof g_login_password[] - 1, " ") return PLUGIN_HANDLED; }
and
PHP Code:
register_clcmd("login_name", "clcmd_login_name") register_clcmd("login_pw", "clcmd_login_password") register_clcmd("login_user", "clcmd_login")
to login in
then
PHP Code:
public clcmd_register_name(id){ static arg[48] read_args(arg, sizeof arg) replace_all(arg, sizeof arg - 1, "reg_name ", "") replace_all(arg, sizeof arg - 1, "^"", "") copy(g_reg_name[id], sizeof g_reg_name[] - 1, arg) show_menu_register(id) return PLUGIN_HANDLED; } public clcmd_register_password(id){ static arg[48] read_args(arg, sizeof arg) replace_all(arg, sizeof arg - 1, "reg_pw ", "") replace_all(arg, sizeof arg - 1, "^"", "") copy(g_reg_password[id], sizeof g_reg_password[] - 1, arg) show_menu_register(id) return PLUGIN_HANDLED; } public clcmd_register(id){ if(contain( g_reg_name[id], " ") != -1){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_REG_UNABLE") return PLUGIN_HANDLED; } if(contain( g_reg_password[id], " ") != -1){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_REG_UNABLE") return PLUGIN_HANDLED; } static key[32], data[32] format(key, sizeof key - 1, "[Data_%s]", g_reg_name[id]) new valid = nvault_get(g_Nvault, key, data, sizeof data - 1); if(valid){ client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_REG_REGISTERED") return PLUGIN_HANDLED; } static len, vaultkey[32], vaultdata[128] format(vaultkey, sizeof vaultkey - 1, "[Data_%s]", g_reg_name[id]) len += formatex(vaultdata, sizeof vaultdata - len - 1, "%s", g_reg_password[id]) nvault_set(g_Nvault, vaultkey, vaultdata) client_print_colored(id, "^x04%L^x01%L", LANG_PLAYER, "MSG_TITLE", id, "MSG_REG_SUCCESS", g_reg_name[id]) format(g_reg_name[id], sizeof g_reg_name[] - 1, " ") format(g_reg_password[id], sizeof g_reg_password[] - 1, " ") return PLUGIN_HANDLED; }
and
PHP Code:
register_clcmd("reg_name", "clcmd_register_name") register_clcmd("reg_pw", "clcmd_register_password") register_clcmd("reg_user", "clcmd_register")
to register accounts
When I use a valid username and password to login in, the server may crashs
I think the register system works fine because I found nothing wrong in Vault file:
Quote:
|
TLVn 枦J 8 [Data_hzqst]nmqs7456m暃J8 [Data_]nmqs7456
|
Last edited by hzqst; 08-31-2009 at 07:34.
|
|