搜索
查看: 2267|回复: 5

帮分离一下这代码

[复制链接]
发表于 2008-11-9 19:24:24 | 显示全部楼层 |阅读模式 来自 中国–广东–中山
[PHP]// last edit by YanOnline at 2005.1.24
#include <amxmod>
#include <amxmisc>
#include <mysql>
#define DEBUG
new g_country[32][32],g_city[32][32]
new g_buffer[512]
new sBuffer[2048]
new bool:g_sql_connected
new g_dbc
public plugin_init() {
register_plugin("Look Ip and City","1.0","hnroc")
register_clcmd("say /city", "cmdcity", 0, "- display city (MOTD)")
register_clcmd("say city", "cmdcity", 0, "- display city (MOTD)")
register_cvar("amx_mysql_host","127.0.0.1")
register_cvar("amx_mysql_user","root")
register_cvar("amx_mysql_pass","yan")
register_cvar("amx_mysql_db","amx")
register_cvar("amx_hideop","1")
register_srvcmd("amx_load_lic","sql_init")
new filename[32]
get_basedir( filename , 31 )
server_cmd("exec %s/config/mysql.cfg" , filename)
server_cmd("amx_load_lic")
}
public sql_init(){
new host[64],user[32],pass[32],dbname[32],error[32]
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",dbname,31)
#if defined DEBUG
server_print("[AMX]Sql setting:host[%s] user[%s] password[%s] database[%s]",host,user,pass,dbname)
#endif
new dbc = mysql_connect(host,user,pass,dbname,error,32)
if (dbc < 1 ){
  server_print("[AMX] SQL Connection Failed! Try once")
  dbc = mysql_connect(host,user,pass,dbname,error,32)
  if (dbc < 1){
   server_print("[AMX] SQL Connection Failed! Check your sql server and its settings")
   g_sql_connected = false
   return PLUGIN_HANDLED
   }else{
   g_sql_connected = true
   g_dbc = dbc
  }
  }else{
  g_sql_connected = true
  g_dbc = dbc
}
#if defined DEBUG
server_print("[AMX] SQL Connect OK!")
#endif
return PLUGIN_HANDLED
}
public client_connect(id){
if (!g_sql_connected)
  return PLUGIN_CONTINUE

new query[512],error[128]
new ipb1[12],ipb2[12],ipb3[12],ipb4[12]
new userip[16],uip[16]
new ipp[32],pos
get_user_ip(id,userip,15,1)
new ips[7]
copy(ips,7,userip)
if (equali(ips,"192.168")){
  set_user_flags(id,read_flags("b"))
  client_print(0,print_chat,"*内网优先玩家: %s",userip)
  copy(g_country[id],31,"广州新力量网吧")
  copy(g_city[id],31," 内部玩家")
}
else
{
  copy(uip,16,userip)
  while(replace(uip,16,"."," ")){}
  parse(uip,ipb1,12,ipb2,12,ipb3,12,ipb4,12)
  pos += format(ipp[pos],31-pos,"%s",ipb1)
  if(str_to_num(ipb2)>=100)
   pos += format(ipp[pos],31-pos,"%s",ipb2)
  else if(str_to_num(ipb2)>=10)
   pos += format(ipp[pos],31-pos,"0%s",ipb2)
  else if(str_to_num(ipb2)>=1)
   pos += format(ipp[pos],31-pos,"00%s",ipb2)
  if(str_to_num(ipb3)>=100)
   pos += format(ipp[pos],31-pos,"%s",ipb3)
  else if(str_to_num(ipb3)>=10)
   pos += format(ipp[pos],31-pos,"0%s",ipb3)
  else if(str_to_num(ipb3)>=1)
   pos += format(ipp[pos],31-pos,"00%s",ipb3)
  if(str_to_num(ipb4)>=100)
   pos += format(ipp[pos],31-pos,"%s",ipb4)
  else if(str_to_num(ipb4)>=10)
   pos += format(ipp[pos],31-pos,"0%s",ipb4)
  else if(str_to_num(ipb4)>=1)
   pos += format(ipp[pos],31-pos,"00%s",ipb4)
  client_print(0,print_chat,"*IP引索: %s ",ipp)
  format(query,511,"SELECT * FROM mytable WHERE startip<=%s AND endip>=%s",ipp,ipp)
  
  if (mysql_query(g_dbc,query) < 1){
   mysql_error(g_dbc,error,127)
   server_print("[AMX] MySQL error: can't load address: '%s'",error)
   return PLUGIN_HANDLED
  }
  while(mysql_nextrow(g_dbc) > 0 ){
   mysql_getfield(g_dbc, 3,  g_country[id], 31)
   mysql_getfield(g_dbc, 4,  g_city[id], 31)
  }
  if (strlen(g_country[id]) == 0)
   copy(g_country[id],31,"未知地址")
  if (strlen(g_city[id]) == 0)
   copy(g_city[id],31,"未知地址")
}
return PLUGIN_CONTINUE
}
public client_putinserver(id){
if (!g_sql_connected)
  return PLUGIN_CONTINUE
new ids[1]
ids[0]=id
set_task(8.0,"show_msg",0,ids,1)
return PLUGIN_CONTINUE
}
public show_msg(ids[]){
new name[32],ip[15],id,pos
id=ids[0]
if (get_cvar_num("amx_hideop")){
  if (get_user_flags(id)&ADMIN_IMMUNITY) {
   get_user_name(id,name,31)
   pos += format(g_buffer[pos],511-pos," %s ",name)
   pos += format(g_buffer[pos],511-pos,"进入服务器,他来自:^n")
   pos += format(g_buffer[pos],511-pos," 身份OP,地址隐藏")
   //    pos += format(g_buffer[pos],511-pos," 祝您玩的愉快!")
  }
  else{
   get_user_name(id,name,31)
   get_user_ip(id,ip,15,1)
   pos += format(g_buffer[pos],511-pos,"%s 终于来啦! ^n",name)
   pos += format(g_buffer[pos],511-pos,"他的IP:%s ^n",ip)
   pos += format(g_buffer[pos],511-pos,"来自:%s / %s",g_country[id],g_city[id])
   // pos += format(g_buffer[pos],511-pos," 祝您玩的愉快,请不要作弊!")
  }
}
else{
  get_user_name(id,name,31)
  get_user_ip(id,ip,15,1)
  pos += format(g_buffer[pos],511-pos,"%s 终于来啦! ^n",name)
  pos += format(g_buffer[pos],511-pos,"他的IP:%s ^n",ip)
  pos += format(g_buffer[pos],511-pos,"来自:%s / %s",g_country[id],g_city[id])
  //pos += format(g_buffer[pos],511-pos," 祝您玩的愉快,请不要作弊!")
}
set_hudmessage(0, 255, 0, 0.05, 0.50, 2, 0.01, 8.0, 0.01, 3.0, 4)
show_hudmessage(0, g_buffer)
return PLUGIN_CONTINUE
}
public cmdcity(id){
new players[32],inum,state[4]
new iLen = 0
get_players(players,inum)

iLen = format( sBuffer,2047, "<meta http-equiv=Content-Type content=charset=utf-8><style>body{color:#FFCC99;background-color:black;margin-top:0}.header{background-color:#9C0000;}.one{background-color:#310000;}.two{background-color:#630000;}td{font-size:13px}</style><table><tr class=header>")
if (!g_sql_connected)
  iLen += format(g_buffer[iLen],511-iLen," 连接sql服务器失败, 请检查设置或者sql服务器")
else{
  iLen += format( sBuffer[iLen],2047-iLen,"%2s %15s %22s^n","<td>玩家ID","<td> 玩家IP","<td>所在城市</tr>")
  for( new i = 0; i < inum; i++ ) {
   if (equal(state,"one")) copy(state,3,"two")
   else copy(state,3,"one")
   new ip[32],name[32]
   if(get_cvar_num("amx_hideop")){
    if (get_user_flags(players)&ADMIN_IMMUNITY) {
     get_user_name(players,name,31)
     iLen += format(sBuffer[iLen],2047-iLen,"<tr class=%s><td>%s<td>%13s<td>%21s%s^n</tr>",state,name,"*****","*****","*****")
    }
    else{
     get_user_name(players,name,31)
     get_user_ip(players,ip,31,1)
     iLen += format(sBuffer[iLen],2047-iLen,"<tr class=%s><td>%1s<td>%s<td>%s%s</tr>",state,name,ip,g_country[players],g_city[players])
    }
   }
   else{
    get_user_name(players,name,31)
    get_user_ip(players,ip,31,1)
    iLen += format(sBuffer[iLen],2047-iLen,"<tr class=%s><td>%1s<td>%s<td>%s%s</tr>",state,name,ip,g_country[players],g_city[players])
   }
  }
}
show_motd(id, sBuffer, "查看玩家来源:" )
return PLUGIN_HANDLED
}
public plugin_end(){
if (!g_sql_connected)
  return PLUGIN_CONTINUE
mysql_close(g_dbc)
server_print("[AMX] SQL Connection closed!")
return PLUGIN_CONTINUE
}[/PHP]


我只想要按Y输入CITY就可以显视玩家所在地,多余的就不要了!有时间、有空、有心情的人帮改一下吧!我把点通能问的人都得罪了,所人发贴求助!
发表于 2008-11-9 19:31:59 | 显示全部楼层 来自 中国–浙江–衢州–开化县

回复: 帮分离一下这代码

你得罪的人太多了。没人会帮你了。
回复

使用道具 举报

 楼主| 发表于 2008-11-9 19:43:48 | 显示全部楼层 来自 中国–广东–中山

回复: 帮分离一下这代码

:) 谢谢你的回贴!
回复

使用道具 举报

发表于 2008-11-9 21:16:49 | 显示全部楼层 来自 中国–广东–广州–天河区

回复: 帮分离一下这代码

2005年这么老需要数据库显示地址的插件还要用呀,
现在显地址直接用QQwry.dat了
这样改下就行,自己替换

  1. iLen += format(sBuffer[iLen],2047-iLen,"<tr class=%s><td>%s<td>%13s</tr>",state,name,"*****")
  2.     }
  3.     else{
  4.      get_user_name(players[i],name,31)
  5.      get_user_ip(players[i],ip,31,1)
  6.      iLen += format(sBuffer[iLen],2047-iLen,"<tr class=%s><td>%1s<td>%s</tr>",state,name,g_country[players[i]])
  7.     }
  8.    }
  9.    else{
  10.     get_user_name(players[i],name,31)
  11.     get_user_ip(players[i],ip,31,1)
  12.     iLen += format(sBuffer[iLen],2047-iLen,"<tr class=%s><td>%1s<td>%s</tr>",state,name,g_country[players[i]])
  13.    }
复制代码
回复

使用道具 举报

 楼主| 发表于 2008-11-9 21:58:46 | 显示全部楼层 来自 中国–广东–中山

回复: 帮分离一下这代码

4楼的,好久不见你发贴呀!以为你退隐了呢!呵呵!想不到还能看到前辈!谢谢你!
回复

使用道具 举报

 楼主| 发表于 2008-11-10 11:12:20 | 显示全部楼层 来自 中国–广东–中山

回复: 帮分离一下这代码

白天人气旺,再顶一下!
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表