slyh
|
分享:
▲
▼
下面是引用 hihihi321321 於 2011-02-26 01:12 發表的 :
情況是這樣的: 當新玩家(名字為A) 進入伺服器 伺服器提示 可"選擇性" 進行註冊...
假如玩家(名字為A) 想註冊的話 側打開選單進行註冊...密碼為999999
萬一玩家(名字為A)註冊後, 相反其他玩家名稱也為A 這時伺服器檢查到這位玩家密碼不正確 <===( 加入20秒時間倒數, 提示玩家輸入密碼, 不正確或沒有輸入密碼並把其踢出) 在源碼第15行最後加上 複製程式
再把 複製程式
if(equali(pw, password))
{
user_status[id] = 3
access_user(id)
}
替換成 複製程式
if(equali(pw, password))
{
user_status[id] = 3
access_user(id)
}
else
{
set_task(1.0, "force_login", id, _, _, "a", 20)
set_task(20.0,"check_user",id)
user_rest[id] = 20
}
再於源碼底部加上 複製程式
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]) //這行可以更改
set_task(1.0,"force_login",id)
}
}
public check_user(id)
{
if(user_status[id] != 3)
{
server_cmd("kick #%i ^"對被踢者的提示^"",get_user_userid(id)) // 這行也是可以更改
}
}
[ 此文章被slyh在2011-02-26 13:39重新編輯 ]
|
|
x0
[23 樓]
From:香港和記電訊 | Posted:2011-02-26 09:14 |
|
|
hihihi321321
|
分享:
▲
下面是引用 slyh 於 2011-02-27 11:56 發表的 : 但經本人測試,上述代碼能正常運作 先多謝你測試喔... 但你是不是只測試了你所修改的語法... 我把你所提供的語法加入後...便變成語法設定與遊戲內不相同喔... 複製程式
#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 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", "")
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
{
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_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)
{
if( ( get_user_flags(id) & ADMIN_KICK ) && ( user_status[id] !=3 ) )
{
remove_user_flags(id)
}
set_task(1.0,"not_login",id)
}
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(id)
{
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]) //這行可以更改
set_task(1.0,"force_login",id)
}
}
public check_user(id)
{ if(user_status[id] != 3)
{
server_cmd("kick #%i ^"對被踢者的提示^"",get_user_userid(id)) // 這行也是可以更改
}
}
|
|
x0
[29 樓]
From:沒有資料 | Posted:2011-02-28 01:15 |
|
|
|