|
楼主 |
发表于 2005-2-19 23:55:57
|
显示全部楼层
来自 中国–广东–广州
Post by hai1989
yanexp 能不能 把你的改的AMX版的共享一下 。以前我用的也卡所以就不用了
好的,当然没问题,以下是我改好后的AMX版显IP地址插件
- #include <amxmod>
- #include <amxmisc>
- #include <mysql>
- #define DEBUG
- #define HUD_CHANNEL 9
- #define MSG_DELAY_TIME 5.0
- new g_country[32][128],g_prov[32][128],g_city[32][128],g_addr[32][255]
- new g_buffer[512]
- new bool:g_specMode[33]
- new bool:g_sql_statu
- new g_sql
- public plugin_init() {
- register_plugin("IP to address","0.2.1","nwb13")
- register_cvar("amx_mysql_host","127.0.0.1")
- register_cvar("amx_mysql_user","root")
- register_cvar("amx_mysql_pass","***")
- register_cvar("amx_mysql_db","amx")
- register_cvar("amx_mysql_table","ipdatau")
- register_cvar("amx_print_chat", "1")
- register_srvcmd("amx_load_ita","sql_init")
- register_event("TextMsg","setSpecMode","bd","2&ec_Mod")
- register_event("StatusValue","showipinfo","bd","1=2")
-
- new configsDir[128]
- get_basedir(configsDir, 127)
- server_cmd("exec %s/config/mysql.cfg", configsDir)
- server_cmd("amx_load_ita")
- }
- public sql_init() {
- new host[64],user[32],pass[32],db[32],table[32],error[128]
- get_cvar_string("amx_mysql_host",host,63)
- get_cvar_string("amx_mysql_user",user,31)
- get_cvar_string("amx_mysql_pass",pass,31)
- get_cvar_string("amx_mysql_db",db,31)
- get_cvar_string("amx_mysql_table",table,31)
- #if defined DEBUG
- server_print("[AMX]Sql setting:host[%s] user[%s] password[%s] database[%s] table[%s]",host,user,pass,db,table)
- #endif
- #if defined DEBUG
- server_print("[AMX]Start to connect sql server.")
- #endif
- new sql = mysql_connect(host,user,pass,db,error,127)
- if (sql <= 1){
- server_print("[AMX] Connect to sql server fail, please check your settings or sql server.")
- g_sql_statu = false
- }else{
- server_print("[AMX] Connect to sql server success.")
- g_sql_statu = true
- g_sql = sql
- }
- if (g_sql_statu == true){
- #if defined DEBUG
- server_print("[AMX]Creat table %s in sql server if it not exist.",table)
- #endif
- }
- }
- public setSpecMode(id) {
- new arg[12]
- read_data( 2 , arg , 11 )
- g_specMode[id] = ( arg[10] == '4' ) // 设置为第一人称视角
- return PLUGIN_HANDLED
- }
- // ip 计算
- ip_to_number(userips[16]){
- new ipb1[12],ipb2[12],ipb3[12],ipb4[12]
- new ip
- new nipb1,nipb2,nipb3,nipb4
- new uip[16]
- copy(uip, 16, userips)
- while(replace(uip, 16, ".", " ")){}
- parse(uip, ipb1, 12, ipb2, 12, ipb3, 12, ipb4, 12)
- nipb1 = str_to_num(ipb1)
- nipb2 = str_to_num(ipb2)
- nipb3 = str_to_num(ipb3)
- nipb4 = str_to_num(ipb4)
- ip=nipb1*16777216 + nipb2*65536 + nipb3*256 + nipb4
- return ip
- }
- public showipinfo(id){
- if ( g_specMode[id] && g_sql_statu ){
- new a = read_data(2)
- if ( is_user_connected(a) ){
- new name[32]
- get_user_name(a,name,31)
- format(g_buffer,511,"%s^n来自^n%s^n%s",name,g_country[a],g_addr[a])
- set_hudmessage(200, 100, 0, 0.85, 0.35, 0, 6.0, 8.0, 0.5, 0.15, 8) // 显示观察视角坐标 右上角
- show_hudmessage(id,g_buffer)
- }
- }
- return PLUGIN_HANDLED
- }
- public client_connect(id){
- if (!g_sql_statu)
- return PLUGIN_HANDLED
- new ipaddr,name[32],userip[16],query[1024],table[32],error[128]
- get_user_ip(id,userip,16,1)
- get_user_name(id,name,31)
- get_cvar_string("amx_mysql_table",table,31)
- ipaddr=ip_to_number(userip)
- if (ipaddr >=0)
- format(query, 1024, "SELECT * FROM %s WHERE StartIP <=%d ORDER BY StartIP DESC LIMIT 0 , 1", table, ipaddr)
- else
- format(query, 1024, "SELECT * FROM %s WHERE StartIP <=%d + 4294967296 ORDER BY StartIP DESC LIMIT 0 , 1", table, ipaddr)
- // 查找需要的数据
- #if defined DEBUG
- new ipaddrs[17]
- numtostr(ipaddr,ipaddrs,16)
- //server_print("[AMX] Search data from table %s IP:%s/%s",table,ipaddrs,userip)
- client_print(0,print_chat,"*[AMX] Search data from table %s IP:%s/%s",table,ipaddrs,userip)
- #endif
- new Res = mysql_query(g_sql,query)
- if (Res < 1) {
- mysql_error(g_sql,error,127)
- server_print("[AMX] Sql error '%s', can't load address.",error)
- //mysql_free_result(Res)
- //write_to_file(id,name,userip,Res,0)
- return PLUGIN_HANDLED
- }else if (Res ==0) {
- server_print("[AMX] Warning! Ip[%s] not find in sql server!",userip)
- return PLUGIN_HANDLED
- }
- // 读取数据
- while(mysql_nextrow(Res) > 0 ) {
- mysql_getfield(Res, 3, g_country[id], 127)
- mysql_getfield(Res, 6, g_addr[id], 254)
- }
- if (strlen(g_country[id]) == 0)
- if (strlen(g_addr[id]) == 0)
- #if defined DEBUG
- server_print("[AMX] Read address success! Player[%s] IP[%s] address[%s, %s, %s, %s]", name, userip, g_country[id], g_prov[id], g_city[id], g_addr[id])
- #endif
- return PLUGIN_HANDLED
- }
- public client_putinserver(id){
- if (!g_sql_statu)
- return PLUGIN_HANDLED
- new parm[2]
- parm[0] = id
- set_task(MSG_DELAY_TIME,"show_msg",6666666,parm,2)
- return PLUGIN_HANDLED
- }
- public client_disconnect(id){
- if (g_sql_statu == false)
- return PLUGIN_HANDLED
- g_country[id] = ""
- g_prov[id] = ""
- g_city[id] = ""
- g_addr[id] = ""
- new name[32]
- get_user_name(id,name,31)
- format(g_buffer,511,"%s 离开了服务器.^n期待你再次光临.",name)
- set_hudmessage(255, 0, 255, 0.10, 0.55, 0, 6.0, 10.0, 0.5, 0.15, HUD_CHANNEL)
- show_hudmessage(0, g_buffer)
- return PLUGIN_CONTINUE
- }
- public show_msg(parm[]){
- new name[32],id //server_name[64],id
- id = parm[0]
- get_user_name(id,name,31)
- format(g_buffer,511,"进入了服务器, 来自: %s, %s, 祝您玩得愉快!",g_country[id],g_addr[id])
- if (get_cvar_num("amx_print_chat"))
- client_print(0,print_chat,"* %s %s",name,g_buffer)
- while(replace(g_buffer, 511, " ", "")){}
- while(replace(g_buffer, 511, ",", "^n")){}
- while(replace(g_buffer, 511, ":", "^n")){}
- format(g_buffer,511,"%s %s",name,g_buffer)
- set_hudmessage(0, 255, 0, 0.10, 0.55, 0, 6.0, 10.0, 0.5, 0.15, HUD_CHANNEL)
- show_hudmessage(0, g_buffer)
- return PLUGIN_CONTINUE
- }
- public plugin_end() {
- if (!g_sql_statu)
- return PLUGIN_CONTINUE
- mysql_close(g_sql)
- server_print("[AMX] SQL Connection closed!")
- return PLUGIN_CONTINUE
- }
复制代码
数据我是使用
显示玩家IP及城市插件的2月10日IP库
http://www.dt-club.net/showthread.php?t=18240
欢迎大家继续讨论这个问题!!! |
|