slyh
|
分享:
▲
▼
回上文: 开启源码,寻找 复制程式
set_task(1.0,"not_login",id) 修改为 复制程式
set_task(1.0,"not_login",id+987654) 再将 复制程式
修改为 复制程式
public not_login(taskid)
{
new id = taskid-987654 再在 复制程式
show_hudmessage(id,"你的昵称已被使用,请登入或转换另一个名字,否则你将会于 %i 秒后被踢除",user_rest[id]) 下面加入 复制程式
另外,我发现了一个问题,如果玩家载入速度过慢,可能会导致玩家于完全进入伺服器前被踢除, 在第15行后开一新行,加上 复制程式
new bool:user_putinserver[33] 寻找 复制程式
public client_putinserver(id)
{ 修改为 复制程式
public client_putinserver(id)
{
user_putinserver[id] = true
if(!user_connect[id])
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
}
寻找 复制程式
public client_connect(id)
{ 修改为 复制程式
public client_connect(id)
{
user_putinserver[id] = false 将 复制程式
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id) 修改为 复制程式
if(user_putinserver[id])
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
}
[ 此文章被slyh在2011-03-02 14:58重新编辑 ]
|
|
x0
[32 楼]
From:香港和记电讯 | Posted:2011-03-01 21:33 |
|
|
slyh
|
分享:
▲
▼
直接根据前文修改,能通过编译,不过不保证没有改错的地方 有错便回贴吧 直接贴出来比较方便 这是普通版本: 复制程式
#include <amxmodx>
#include <fakemeta>
#include <sqlx>
#include <cstrike>
#include <amxmisc>
#include <fun>
#define VERSION "1.0"
// 密码最短长度
#define PASSWORD_MIN_LEN 6
#define MAX_LOGIN_ATTEMPTS 3
#define BAN_TIME 3
// user_activity 1 - 注册中 2 - 登入中 3 - 输入旧密码 4 - 输入新密码
new user_status[33],user_activity[33],user_len[33],user_password[33][33],user_wrong[33],mysqlx_host,mysqlx_user,mysqlx_db,mysqlx_pass,gmsgScreenFade,user_rest[33]
new bool:user_putinserver[33]
new Handle:g_hTuple
new bool:user_connect[33]
new const szTables[][] =
{
"CREATE TABLE IF NOT EXISTS `register_system` ( `user_id` varchar(64) NOT NULL,`user_password` varchar(128) default NULL,`user_ip` varchar(32) default NULL,PRIMARY KEY (`user_id`) ) TYPE=MyISAM;"
}
public plugin_init()
{
gmsgScreenFade = get_user_msgid("ScreenFade")
register_plugin("注册/登入系统", VERSION, "slyh")
register_clcmd("say", "user_say", ADMIN_ALL)
register_clcmd("say /login", "user_login", ADMIN_ALL)
register_event("ScreenFade","Event_ScreenFade","b")
register_forward(FM_ClientUserInfoChanged, "Fwd_ClientInfoChanged")
mysqlx_host = register_cvar ("regsys_host", "localhost")
mysqlx_user = register_cvar ("regsys_user", "")
mysqlx_pass = register_cvar ("regsys_pass", "")
mysqlx_db = register_cvar ("regsys_dbname", "register_system")
MySQLx_Init()
}
public user_say(id,level,cid)
{
if( ( !cmd_access(id, level, cid, 2) ) || user_activity[id] == 0)
return PLUGIN_CONTINUE
new name[32],message[128]
get_user_name(id,name,31)
switch(user_activity[id])
{
case 1:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
new len = strlen(arg_pass);
if(len < PASSWORD_MIN_LEN || len > 20)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01密码长度最少需有 %d 位, 最多不可超过 20 位, 请输入一个新的密码.",PASSWORD_MIN_LEN)
client_color(id,id,message)
client_cmd(id,"messagemode")
return PLUGIN_HANDLED
}
format(message,127,"^x04[hk-fun.com提醒你] ^x01你已成功注册, 请谨记你的密码: %s .",arg_pass)
access_user(id)
client_color(id,id,message)
user_password[id] = arg_pass
user_status[id] = 3
user_activity[id] = 0
set_task(2.5,"Reset_Screen",id)
set_task(3.0,"chooseteam",id)
set_task(1.1,"hud_finish",id)
client_cmd(id,"setinfo ^"_reg^" ^"%s^"",arg_pass)
new name[32],ip[32]
get_user_name(id,name,31)
get_user_ip(id,ip,31,1)
static szQuery[128];
formatex( szQuery, 127, "REPLACE INTO `register_system` (`user_id`, `user_password`, `user_ip`) VALUES ('%s', '%s', '%s');",name,arg_pass,ip)
SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
return PLUGIN_HANDLED
}
case 2:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
user_password[id] = arg_pass
LoadData(id)
return PLUGIN_HANDLED
}
case 3:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
user_password[id] = arg_pass
LoadData(id)
return PLUGIN_HANDLED
}
case 4:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
new len = strlen(arg_pass);
if(len < PASSWORD_MIN_LEN || len > 20)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01密码长度最少需有 %d 位, 最多不可超过 20 位, 请输入一个新的密码.",PASSWORD_MIN_LEN)
client_color(id,id,message)
client_cmd(id,"messagemode")
return PLUGIN_HANDLED
}
format(message,127,"^x04[hk-fun.com提醒你] ^x01你已成功更换密码, 请谨记你的密码: %s .",arg_pass)
client_color(id,id,message)
user_password[id] = arg_pass
user_status[id] = 3
user_activity[id] = 0
set_task(2.5,"Reset_Screen",id)
set_task(3.0,"chooseteam",id)
set_task(1.1,"hud_finish",id)
new name[32],ip[32]
get_user_name(id,name,31)
get_user_ip(id,ip,31,1)
static szQuery[128];
formatex( szQuery, 127, "REPLACE INTO `register_system` (`user_id`, `user_password`, `user_ip`) VALUES ('%s', '%s', '%s');",name,arg_pass,ip)
SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public QuerySelectData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
{
if( iFailState == TQUERY_CONNECT_FAILED
|| iFailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", szError );
return;
}
else
{
new id = iData[ 0 ];
new password = SQL_FieldNameToNum(hQuery, "user_password")
new pw[44]
while (SQL_MoreResults(hQuery))
{
new name[32],message[128]
get_user_name(id,name,31)
SQL_ReadResult(hQuery, password, pw, sizeof(pw)-1)
if(user_connect[id])
{
new password[32]
user_len[id] = strlen(pw)
user_connect[id] = false
get_user_info(id, "_reg", password, 31)
if(equali(pw, password))
{
user_status[id] = 3
access_user(id)
}
else
{
if(user_putinserver[id])
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
}
user_rest[id] = 20
}
}
else
{
if(!equali(pw, user_password[id]))
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01密码错误, 你只有 %d 次机会.",MAX_LOGIN_ATTEMPTS)
client_color(id,id,message)
user_wrong[id] += 1
client_cmd(id,"messagemode")
if(user_wrong[id] >= MAX_LOGIN_ATTEMPTS)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01由于 ^x03%s^x01 输入了 %d 次错误的密码, 所以已被封禁 %d 分钟.",name,MAX_LOGIN_ATTEMPTS,BAN_TIME)
client_color(0,id,message)
server_cmd("banid ^"%d^" ^"#%i^"",BAN_TIME,get_user_userid(id))
server_cmd("kick #%i ^"由于你输入了 %d 次错误的密码, 所以已被封禁 %d 分钟!^"",get_user_userid(id),MAX_LOGIN_ATTEMPTS,BAN_TIME);
}
}
else
{
if(user_activity[id] == 3)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01已认证身份, 请输入新密码.")
client_color(id,id,message)
user_activity[id] = 4
client_cmd(id,"messagemode")
}
else
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01你已成功登入.")
client_color(id,id,message)
user_status[id] = 3
user_activity[id] = 0
set_task(2.5,"Reset_Screen",id)
set_task(3.0,"chooseteam",id)
set_task(1.1,"hud_finish",id)
access_user(id)
}
}
}
SQL_NextRow(hQuery)
}
}
}
public user_login(id)
{
if(user_status[id] == 3)
{
new menu = menu_create("\y欢迎使用登记系统, 你现已登入:", "login_menu_handler")
menu_additem(menu, "\d注册", "1", 0)
menu_additem(menu, "\d登录", "2", 0)
menu_additem(menu, "\w更改密码", "3", 0)
//menu_additem(menu, "\d设定(暂未开放)", "4", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
if(user_len[id] >= PASSWORD_MIN_LEN)
{
new menu = menu_create("\y欢迎使用登记系统, 请完成登入程序:", "login_menu_handler")
menu_additem(menu, "\d注册", "1", 0)
menu_additem(menu, "\w登录", "2", 0)
menu_additem(menu, "\d更改密码", "3", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
else
{
new menu = menu_create("\y欢迎使用登记系统, 请完成注册程序:", "login_menu_handler")
menu_additem(menu, "\w注册", "1", 0)
menu_additem(menu, "\d登录", "2", 0)
menu_additem(menu, "\d更改密码", "3", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public login_menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new data[6], iName[64]
new access, callback
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
new key = str_to_num(data)
switch(key)
{
case 1:
{
if(user_status[id] != 3 && user_len[id] < PASSWORD_MIN_LEN)
{
user_activity[id] = 1
if(is_user_alive(id))
{
user_kill(id)
cs_set_user_deaths(id, cs_get_user_deaths(id) - 1)
set_user_frags(id, get_user_frags(id) + 1 )
}
cs_set_user_team(id,CS_TEAM_SPECTATOR)
Fade_To_Black(id)
client_cmd(id,"messagemode")
hud(id)
}
}
case 2:
{
if(user_status[id] != 3 && user_len[id] >= PASSWORD_MIN_LEN)
{
user_activity[id] = 2
if(is_user_alive(id))
{
user_kill(id)
cs_set_user_deaths(id, cs_get_user_deaths(id) - 1)
set_user_frags(id, get_user_frags(id) + 1 )
}
cs_set_user_team(id,CS_TEAM_SPECTATOR)
Fade_To_Black(id)
client_cmd(id,"messagemode")
hud(id)
}
}
case 3:
{
if(user_status[id] == 3)
{
user_activity[id] = 3
if(is_user_alive(id))
{
user_kill(id)
cs_set_user_deaths(id, cs_get_user_deaths(id) - 1)
set_user_frags(id, get_user_frags(id) + 1 )
}
cs_set_user_team(id,CS_TEAM_SPECTATOR)
Fade_To_Black(id)
client_cmd(id,"messagemode")
hud(id)
}
}
case 4:
{
//setting_menu(id)
}
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
public setting_menu(id)
{
new menu = menu_create("\y系统设定:", "setting_menu_handler")
menu_additem(menu, "\w返回主目录", "2", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
menu_display(id, menu, 0)
}
public setting_menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new data[6], iName[64]
new access, callback
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
new key = str_to_num(data)
switch(key)
{
case 2:
{
user_login(id)
}
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
public hud(id)
{
switch(user_activity[id])
{
case 1:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "你只要输入密码, 再按Enter, 即完成整个注册过程!^n注意事项:^n1.密码长度不得短于 %d 位^n2.密码长度不得长于 20 位",PASSWORD_MIN_LEN)
set_task(1.0,"hud",id)
}
case 2:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "你只要输入密码, 再按Enter, 即完成整个登入过程!^n注意事项:^n你只有 %d 次错误输入密码的机会,^n机会用尽后, 你将会被封禁 %d 分钟!",MAX_LOGIN_ATTEMPTS,BAN_TIME)
set_task(1.0,"hud",id)
}
case 3:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "请你输入旧密码以确认身份!")
set_task(1.0,"hud",id)
}
case 4:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "你只要新输入密码, 再按Enter, 即完成整个密码更换过程!^n注意事项:^n1.新密码长度不得短于 %d 位^n2.新密码长度不得长于 20 位",PASSWORD_MIN_LEN)
set_task(1.0,"hud",id)
}
}
}
public Event_ScreenFade(id)
{
if(user_activity[id] > 0)
{
Fade_To_Black(id)
}
}
public Fade_To_Black(id)
{
message_begin ( MSG_ONE_UNRELIABLE , gmsgScreenFade , _ , id ) ;
write_short ( ( 1<<3 ) | ( 1<<8 ) | ( 1<<10 ) ) ;
write_short ( ( 1<<3 ) | ( 1<<8 ) | ( 1<<10 ) ) ;
write_short ( ( 1<<0 ) | ( 1<<2 ) ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 255 ) ;
message_end ( ) ;
}
public Reset_Screen(id)
{
message_begin ( MSG_ONE_UNRELIABLE , gmsgScreenFade , _ , id ) ;
write_short ( 1<<2 ) ;
write_short ( 0 ) ;
write_short ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
message_end ( ) ;
}
public MySQLx_Init()
{
new szHost[64], szUser[32], szPass[32], szDB[128];
get_pcvar_string( mysqlx_host, szHost, charsmax( szHost ) );
get_pcvar_string( mysqlx_user, szUser, charsmax( szUser ) );
get_pcvar_string( mysqlx_pass, szPass, charsmax( szPass ) );
get_pcvar_string( mysqlx_db, szDB, charsmax( szDB ) );
g_hTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
for ( new i = 0; i < sizeof szTables; i++ )
{
SQL_ThreadQuery( g_hTuple, "QueryCreateTable", szTables[i])
}
}
public QueryCreateTable( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
{
if( iFailState == TQUERY_CONNECT_FAILED
|| iFailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", szError );
return;
}
}
public LoadData(id)
{
new name[32]
get_user_name(id,name,31)
static szQuery[ 128 ], iData[ 1 ];
formatex( szQuery, 127, "SELECT `user_password` FROM `register_system` WHERE ( `user_id` = '%s' );",name);
iData[ 0 ] = id;
SQL_ThreadQuery( g_hTuple, "QuerySelectData", szQuery, iData, 1 );
}
public QuerySetData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
{
if( iFailState == TQUERY_CONNECT_FAILED
|| iFailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", szError );
return;
}
}
public plugin_natives()
{
register_native("get_user_status", "native_get_user_status", 1)
register_native("get_user_pwlen", "native_get_user_pwlen", 1)
}
public hud_finish(id)
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 0, 0.0, 2.0, 0.0, 0.0, -1)
show_hudmessage(id, "你已完成登入/注册/更换密码过程!")
}
public client_connect(id)
{
user_putinserver[id] = false
user_activity[id] = 0
user_wrong[id] = 0
user_status[id] = 0
user_len[id] = 0
user_connect[id] = true
remove_task(id)
LoadData(id)
}
public client_putinserver(id)
{
user_putinserver[id] = true
if(!user_connect[id])
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
}
if( ( get_user_flags(id) & ADMIN_KICK ) && ( user_status[id] !=3 ) )
{
remove_user_flags(id)
}
set_task(1.0,"not_login",id+987654)
}
public messengmode(id)
{
client_cmd(id,"messagemode")
}
public client_disconnect(id)
{
user_activity[id] = 0
user_wrong[id] = 0
user_status[id] = 0
user_len[id] = 0
remove_task(id)
user_connect[id] = 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, "游戏中不允许更换名字.");
return FMRES_SUPERCEDE;
}
public native_get_user_status(id)
{
return user_status[id]
}
public native_get_user_pwlen(id)
{
return user_len[id]
}
public chooseteam(id)
{
client_cmd(id,"chooseteam")
}
public client_color(playerid, colorid, msg[]){
message_begin(playerid?MSG_ONE:MSG_ALL,get_user_msgid("SayText"),{0,0,0},playerid)
write_byte(colorid)
write_string(msg)
message_end()
}
public not_login(taskid)
{
new id = taskid-987654
if(user_status[id] != 3)
{
set_hudmessage(255, 0, 0, -1.0, 0.7, 0, 0.0, 0.1, 0.0, 0.0)
show_hudmessage(id,"请说/login注册/登录, 否则你将受以下限制^n失去管理员权力")
set_task(0.1,"not_login",id)
}
}
access_user(id)
{
remove_user_flags(id)
new userip[32], userauthid[32], password[32], username[32]
get_user_ip(id, userip, 31, 1)
get_user_authid(id, userauthid, 31)
get_user_name(id, username, 31)
get_user_info(id, "_pw", password, 31)
getAccess(id, username, userauthid, userip, password)
return PLUGIN_CONTINUE
}
getAccess(id, name[], authid[], ip[], password[])
{
new index = -1
new result = 0
static Count;
static Flags;
static Access;
static AuthData[44];
static Password[32];
Count=admins_num();
for (new i = 0; i < Count; ++i)
{
Flags=admins_lookup(i,AdminProp_Flags);
admins_lookup(i,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
if (Flags & FLAG_AUTHID)
{
if (equal(authid, AuthData))
{
index = i
break
}
}
else if (Flags & FLAG_IP)
{
new c = strlen(AuthData)
if (AuthData[c - 1] == '.') /* check if this is not a xxx.xxx. format */
{
if (equal(AuthData, ip, c))
{
index = i
break
}
} /* in other case an IP must just match */
else if (equal(ip, AuthData))
{
index = i
break
}
}
else
{
if (Flags & FLAG_CASE_SENSITIVE)
{
if (Flags & FLAG_TAG)
{
if (contain(name, AuthData) != -1)
{
index = i
break
}
}
else if (equal(name, AuthData))
{
index = i
break
}
}
else
{
if (Flags & FLAG_TAG)
{
if (containi(name, AuthData) != -1)
{
index = i
break
}
}
else if (equali(name, AuthData))
{
index = i
break
}
}
}
}
if (index != -1)
{
Access=admins_lookup(index,AdminProp_Access);
if (Flags & FLAG_NOPASS)
{
result |= 8
new sflags[32]
get_flags(Access, sflags, 31)
set_user_flags(id, Access)
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
}
else
{
admins_lookup(index,AdminProp_Password,Password,sizeof(Password)-1);
if (equal(password, Password))
{
result |= 12
set_user_flags(id, Access)
new sflags[32]
get_flags(Access, sflags, 31)
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
}
else
{
result |= 1
if (Flags & FLAG_KICK)
{
result |= 2
log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, ip)
}
}
}
}
}
public force_login(id)
{
if(user_status[id] != 3)
{
user_rest[id] -= 1
set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 0.0, 1.0, 0.0, 0.0)
show_hudmessage(id,"你的昵称已被使用,请登入或转换另一个名字,否则你将会于 %i 秒后被踢除",user_rest[id]) //这行可以更改
remove_task(id+987654)
}
}
public check_user(id)
{
if(user_status[id] != 3)
{
server_cmd("kick #%i ^"你因尚未登入而被踢除^"",get_user_userid(id)) // 这行也是可以更改
}
} 这是第二方案: 复制程式
#include <amxmodx>
#include <fakemeta>
#include <sqlx>
#include <cstrike>
#include <amxmisc>
#include <fun>
#include <admin>
#define VERSION "1.0"
// 密码最短长度
#define PASSWORD_MIN_LEN 6
#define MAX_LOGIN_ATTEMPTS 3
#define BAN_TIME 3
// user_activity 1 - 注册中 2 - 登入中 3 - 输入旧密码 4 - 输入新密码
new user_status[33],user_activity[33],user_len[33],user_password[33][33],user_wrong[33],mysqlx_host,mysqlx_user,mysqlx_db,mysqlx_pass,gmsgScreenFade,user_rest[33]
new bool:user_putinserver[33]
new Handle:g_hTuple
new bool:user_connect[33]
new const szTables[][] =
{
"CREATE TABLE IF NOT EXISTS `register_system` ( `user_id` varchar(64) NOT NULL,`user_password` varchar(128) default NULL,`user_ip` varchar(32) default NULL,PRIMARY KEY (`user_id`) ) TYPE=MyISAM;"
}
public plugin_init()
{
gmsgScreenFade = get_user_msgid("ScreenFade")
register_plugin("注册/登入系统", VERSION, "slyh")
register_clcmd("say", "user_say", ADMIN_ALL)
register_clcmd("say /login", "user_login", ADMIN_ALL)
register_event("ScreenFade","Event_ScreenFade","b")
register_forward(FM_ClientUserInfoChanged, "Fwd_ClientInfoChanged")
mysqlx_host = register_cvar ("regsys_host", "localhost")
mysqlx_user = register_cvar ("regsys_user", "")
mysqlx_pass = register_cvar ("regsys_pass", "")
mysqlx_db = register_cvar ("regsys_dbname", "register_system")
MySQLx_Init()
}
public user_say(id,level,cid)
{
if( ( !cmd_access(id, level, cid, 2) ) || user_activity[id] == 0)
return PLUGIN_CONTINUE
new name[32],message[128]
get_user_name(id,name,31)
switch(user_activity[id])
{
case 1:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
new len = strlen(arg_pass);
if(len < PASSWORD_MIN_LEN || len > 20)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01密码长度最少需有 %d 位, 最多不可超过 20 位, 请输入一个新的密码.",PASSWORD_MIN_LEN)
client_color(id,id,message)
client_cmd(id,"messagemode")
return PLUGIN_HANDLED
}
format(message,127,"^x04[hk-fun.com提醒你] ^x01你已成功注册, 请谨记你的密码: %s .",arg_pass)
access_user(id)
client_color(id,id,message)
user_password[id] = arg_pass
user_status[id] = 3
user_activity[id] = 0
set_task(2.5,"Reset_Screen",id)
set_task(3.0,"chooseteam",id)
set_task(1.1,"hud_finish",id)
client_cmd(id,"setinfo ^"_reg^" ^"%s^"",arg_pass)
new name[32],ip[32]
get_user_name(id,name,31)
get_user_ip(id,ip,31,1)
static szQuery[128];
formatex( szQuery, 127, "REPLACE INTO `register_system` (`user_id`, `user_password`, `user_ip`) VALUES ('%s', '%s', '%s');",name,arg_pass,ip)
SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
return PLUGIN_HANDLED
}
case 2:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
user_password[id] = arg_pass
LoadData(id)
return PLUGIN_HANDLED
}
case 3:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
user_password[id] = arg_pass
LoadData(id)
return PLUGIN_HANDLED
}
case 4:
{
new arg_pass[32]
read_argv(1, arg_pass, 31)
new len = strlen(arg_pass);
if(len < PASSWORD_MIN_LEN || len > 20)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01密码长度最少需有 %d 位, 最多不可超过 20 位, 请输入一个新的密码.",PASSWORD_MIN_LEN)
client_color(id,id,message)
client_cmd(id,"messagemode")
return PLUGIN_HANDLED
}
format(message,127,"^x04[hk-fun.com提醒你] ^x01你已成功更换密码, 请谨记你的密码: %s .",arg_pass)
client_color(id,id,message)
user_password[id] = arg_pass
user_status[id] = 3
user_activity[id] = 0
set_task(2.5,"Reset_Screen",id)
set_task(3.0,"chooseteam",id)
set_task(1.1,"hud_finish",id)
new name[32],ip[32]
get_user_name(id,name,31)
get_user_ip(id,ip,31,1)
static szQuery[128];
formatex( szQuery, 127, "REPLACE INTO `register_system` (`user_id`, `user_password`, `user_ip`) VALUES ('%s', '%s', '%s');",name,arg_pass,ip)
SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public QuerySelectData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
{
if( iFailState == TQUERY_CONNECT_FAILED
|| iFailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", szError );
return;
}
else
{
new id = iData[ 0 ];
new password = SQL_FieldNameToNum(hQuery, "user_password")
new pw[44]
while (SQL_MoreResults(hQuery))
{
new name[32],message[128]
get_user_name(id,name,31)
SQL_ReadResult(hQuery, password, pw, sizeof(pw)-1)
if(user_connect[id])
{
new password[32]
user_len[id] = strlen(pw)
user_connect[id] = false
get_user_info(id, "_reg", password, 31)
if(equali(pw, password))
{
user_status[id] = 3
access_user(id)
}
else
{
if(user_putinserver[id])
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
}
user_rest[id] = 20
}
}
else
{
if(!equali(pw, user_password[id]))
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01密码错误, 你只有 %d 次机会.",MAX_LOGIN_ATTEMPTS)
client_color(id,id,message)
user_wrong[id] += 1
client_cmd(id,"messagemode")
if(user_wrong[id] >= MAX_LOGIN_ATTEMPTS)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01由于 ^x03%s^x01 输入了 %d 次错误的密码, 所以已被封禁 %d 分钟.",name,MAX_LOGIN_ATTEMPTS,BAN_TIME)
client_color(0,id,message)
server_cmd("banid ^"%d^" ^"#%i^"",BAN_TIME,get_user_userid(id))
server_cmd("kick #%i ^"由于你输入了 %d 次错误的密码, 所以已被封禁 %d 分钟!^"",get_user_userid(id),MAX_LOGIN_ATTEMPTS,BAN_TIME);
}
}
else
{
if(user_activity[id] == 3)
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01已认证身份, 请输入新密码.")
client_color(id,id,message)
user_activity[id] = 4
client_cmd(id,"messagemode")
}
else
{
format(message,127,"^x04[hk-fun.com提醒你] ^x01你已成功登入.")
client_color(id,id,message)
user_status[id] = 3
user_activity[id] = 0
set_task(2.5,"Reset_Screen",id)
set_task(3.0,"chooseteam",id)
set_task(1.1,"hud_finish",id)
access_user(id)
}
}
}
SQL_NextRow(hQuery)
}
}
}
public user_login(id)
{
if(user_status[id] == 3)
{
new menu = menu_create("\y欢迎使用登记系统, 你现已登入:", "login_menu_handler")
menu_additem(menu, "\d注册", "1", 0)
menu_additem(menu, "\d登录", "2", 0)
menu_additem(menu, "\w更改密码", "3", 0)
//menu_additem(menu, "\d设定(暂未开放)", "4", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
if(user_len[id] >= PASSWORD_MIN_LEN)
{
new menu = menu_create("\y欢迎使用登记系统, 请完成登入程序:", "login_menu_handler")
menu_additem(menu, "\d注册", "1", 0)
menu_additem(menu, "\w登录", "2", 0)
menu_additem(menu, "\d更改密码", "3", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
else
{
new menu = menu_create("\y欢迎使用登记系统, 请完成注册程序:", "login_menu_handler")
menu_additem(menu, "\w注册", "1", 0)
menu_additem(menu, "\d登录", "2", 0)
menu_additem(menu, "\d更改密码", "3", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public login_menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new data[6], iName[64]
new access, callback
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
new key = str_to_num(data)
switch(key)
{
case 1:
{
if(user_status[id] != 3 && user_len[id] < PASSWORD_MIN_LEN)
{
user_activity[id] = 1
if(is_user_alive(id))
{
user_kill(id)
cs_set_user_deaths(id, cs_get_user_deaths(id) - 1)
set_user_frags(id, get_user_frags(id) + 1 )
}
cs_set_user_team(id,CS_TEAM_SPECTATOR)
Fade_To_Black(id)
client_cmd(id,"messagemode")
hud(id)
}
}
case 2:
{
if(user_status[id] != 3 && user_len[id] >= PASSWORD_MIN_LEN)
{
user_activity[id] = 2
if(is_user_alive(id))
{
user_kill(id)
cs_set_user_deaths(id, cs_get_user_deaths(id) - 1)
set_user_frags(id, get_user_frags(id) + 1 )
}
cs_set_user_team(id,CS_TEAM_SPECTATOR)
Fade_To_Black(id)
client_cmd(id,"messagemode")
hud(id)
}
}
case 3:
{
if(user_status[id] == 3)
{
user_activity[id] = 3
if(is_user_alive(id))
{
user_kill(id)
cs_set_user_deaths(id, cs_get_user_deaths(id) - 1)
set_user_frags(id, get_user_frags(id) + 1 )
}
cs_set_user_team(id,CS_TEAM_SPECTATOR)
Fade_To_Black(id)
client_cmd(id,"messagemode")
hud(id)
}
}
case 4:
{
//setting_menu(id)
}
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
public setting_menu(id)
{
new menu = menu_create("\y系统设定:", "setting_menu_handler")
menu_additem(menu, "\w返回主目录", "2", 0)
menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
menu_display(id, menu, 0)
}
public setting_menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new data[6], iName[64]
new access, callback
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
new key = str_to_num(data)
switch(key)
{
case 2:
{
user_login(id)
}
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
public hud(id)
{
switch(user_activity[id])
{
case 1:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "你只要输入密码, 再按Enter, 即完成整个注册过程!^n注意事项:^n1.密码长度不得短于 %d 位^n2.密码长度不得长于 20 位",PASSWORD_MIN_LEN)
set_task(1.0,"hud",id)
}
case 2:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "你只要输入密码, 再按Enter, 即完成整个登入过程!^n注意事项:^n你只有 %d 次错误输入密码的机会,^n机会用尽后, 你将会被封禁 %d 分钟!",MAX_LOGIN_ATTEMPTS,BAN_TIME)
set_task(1.0,"hud",id)
}
case 3:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "请你输入旧密码以确认身份!")
set_task(1.0,"hud",id)
}
case 4:
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 2, 1.0, 1.0, 0.0, 0.0, -1)
show_hudmessage(id, "你只要新输入密码, 再按Enter, 即完成整个密码更换过程!^n注意事项:^n1.新密码长度不得短于 %d 位^n2.新密码长度不得长于 20 位",PASSWORD_MIN_LEN)
set_task(1.0,"hud",id)
}
}
}
public Event_ScreenFade(id)
{
if(user_activity[id] > 0)
{
Fade_To_Black(id)
}
}
public Fade_To_Black(id)
{
message_begin ( MSG_ONE_UNRELIABLE , gmsgScreenFade , _ , id ) ;
write_short ( ( 1<<3 ) | ( 1<<8 ) | ( 1<<10 ) ) ;
write_short ( ( 1<<3 ) | ( 1<<8 ) | ( 1<<10 ) ) ;
write_short ( ( 1<<0 ) | ( 1<<2 ) ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 255 ) ;
message_end ( ) ;
}
public Reset_Screen(id)
{
message_begin ( MSG_ONE_UNRELIABLE , gmsgScreenFade , _ , id ) ;
write_short ( 1<<2 ) ;
write_short ( 0 ) ;
write_short ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
write_byte ( 0 ) ;
message_end ( ) ;
}
public MySQLx_Init()
{
new szHost[64], szUser[32], szPass[32], szDB[128];
get_pcvar_string( mysqlx_host, szHost, charsmax( szHost ) );
get_pcvar_string( mysqlx_user, szUser, charsmax( szUser ) );
get_pcvar_string( mysqlx_pass, szPass, charsmax( szPass ) );
get_pcvar_string( mysqlx_db, szDB, charsmax( szDB ) );
g_hTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
for ( new i = 0; i < sizeof szTables; i++ )
{
SQL_ThreadQuery( g_hTuple, "QueryCreateTable", szTables[i])
}
}
public QueryCreateTable( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
{
if( iFailState == TQUERY_CONNECT_FAILED
|| iFailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", szError );
return;
}
}
public LoadData(id)
{
new name[32]
get_user_name(id,name,31)
static szQuery[ 128 ], iData[ 1 ];
formatex( szQuery, 127, "SELECT `user_password` FROM `register_system` WHERE ( `user_id` = '%s' );",name);
iData[ 0 ] = id;
SQL_ThreadQuery( g_hTuple, "QuerySelectData", szQuery, iData, 1 );
}
public QuerySetData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
{
if( iFailState == TQUERY_CONNECT_FAILED
|| iFailState == TQUERY_QUERY_FAILED )
{
log_amx( "%s", szError );
return;
}
}
public plugin_natives()
{
register_native("get_user_status", "native_get_user_status", 1)
register_native("get_user_pwlen", "native_get_user_pwlen", 1)
}
public hud_finish(id)
{
set_hudmessage(0, 0, 0, -1.0, -1.0, 0, 0.0, 2.0, 0.0, 0.0, -1)
show_hudmessage(id, "你已完成登入/注册/更换密码过程!")
}
public client_connect(id)
{
user_putinserver[id] = false
user_activity[id] = 0
user_wrong[id] = 0
user_status[id] = 0
user_len[id] = 0
user_connect[id] = true
remove_task(id)
LoadData(id)
}
public client_putinserver(id)
{
user_putinserver[id] = true
if(!user_connect[id])
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
}
if( ( get_user_flags(id) & ADMIN_KICK ) && ( user_status[id] !=3 ) )
{
remove_user_flags(id)
}
set_task(1.0,"not_login",id+987654)
}
public messengmode(id)
{
client_cmd(id,"messagemode")
}
public client_disconnect(id)
{
user_activity[id] = 0
user_wrong[id] = 0
user_status[id] = 0
user_len[id] = 0
remove_task(id)
user_connect[id] = 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, "游戏中不允许更换名字.");
return FMRES_SUPERCEDE;
}
public native_get_user_status(id)
{
return user_status[id]
}
public native_get_user_pwlen(id)
{
return user_len[id]
}
public chooseteam(id)
{
client_cmd(id,"chooseteam")
}
public client_color(playerid, colorid, msg[]){
message_begin(playerid?MSG_ONE:MSG_ALL,get_user_msgid("SayText"),{0,0,0},playerid)
write_byte(colorid)
write_string(msg)
message_end()
}
public not_login(taskid)
{
new id = taskid-987654
if(user_status[id] != 3)
{
set_hudmessage(255, 0, 0, -1.0, 0.7, 0, 0.0, 0.1, 0.0, 0.0)
show_hudmessage(id,"请说/login注册/登录, 否则你将受以下限制^n失去管理员权力")
set_task(0.1,"not_login",id)
}
}
public force_login(id)
{
if(user_status[id] != 3)
{
user_rest[id] -= 1
set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 0.0, 1.0, 0.0, 0.0)
show_hudmessage(id,"你的昵称已被使用,请登入或转换另一个名字,否则你将会于 %i 秒后被踢除",user_rest[id]) //这行可以更改
remove_task(id+987654)
}
}
public check_user(id)
{
if(user_status[id] != 3)
{
server_cmd("kick #%i ^"你因尚未登入而被踢除^"",get_user_userid(id)) // 这行也是可以更改
}
}
|
|
x0
[36 楼]
From:香港和记电讯 | Posted:2011-03-07 21:38 |
|
|
|