yanexp 发表于 2005-1-24 12:32:13

我网吧用的显IP来源插件!~~

借用hnroc和结合nwb13的优化代码,
我也作了自己的想法
因为网吧的服务器多数有60%是内部玩家,既然是内网就不必要再去查询Mysql数据库以免浪费资源
毕竟内网玩家老喜欢reconnect

代码如下:

// last edit by YanOnline at 2005.1.24

#include <amxmod>
#include <amxmisc>
#include <mysql>

#define DEBUG

new g_country,g_city
new g_buffer
new sBuffer
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
   get_basedir( filename , 31 )
   server_cmd("exec %s/config/mysql.cfg" , filename)
   server_cmd("amx_load_lic")
}

public sql_init(){
        new host,user,pass,dbname,error
        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("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(" SQL Connection Failed! Try once")
                dbc = mysql_connect(host,user,pass,dbname,error,32)
                if (dbc < 1){
                        server_print(" 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(" SQL Connect OK!")
        #endif
        return PLUGIN_HANDLED
}

public client_connect(id){
   if (!g_sql_connected)
      return PLUGIN_CONTINUE

   new query,error
   new ipb1,ipb2,ipb3,ipb4
   new userip,uip
   new ipp,pos
   get_user_ip(id,userip,15,1)
   new ips
   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,31,"广州新力量网吧")
   copy(g_city,31," 内部玩家")
   }
   else
   {
   copy(uip,16,userip)
   while(replace(uip,16,"."," ")){}
   parse(uip,ipb1,12,ipb2,12,ipb3,12,ipb4,12)
   pos += format(ipp,31-pos,"%s",ipb1)
   if(str_to_num(ipb2)>=100)
      pos += format(ipp,31-pos,"%s",ipb2)
   else if(str_to_num(ipb2)>=10)
      pos += format(ipp,31-pos,"0%s",ipb2)
   else if(str_to_num(ipb2)>=1)
      pos += format(ipp,31-pos,"00%s",ipb2)
   if(str_to_num(ipb3)>=100)
      pos += format(ipp,31-pos,"%s",ipb3)
   else if(str_to_num(ipb3)>=10)
      pos += format(ipp,31-pos,"0%s",ipb3)
   else if(str_to_num(ipb3)>=1)
      pos += format(ipp,31-pos,"00%s",ipb3)
   if(str_to_num(ipb4)>=100)
      pos += format(ipp,31-pos,"%s",ipb4)
   else if(str_to_num(ipb4)>=10)
      pos += format(ipp,31-pos,"0%s",ipb4)
   else if(str_to_num(ipb4)>=1)
      pos += format(ipp,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(" MySQL error: can't load address: '%s'",error)
      return PLUGIN_HANDLED
   }
   while(mysql_nextrow(g_dbc) > 0 ){
      mysql_getfield(g_dbc, 3,g_country, 31)
      mysql_getfield(g_dbc, 4,g_city, 31)
   }
   if (strlen(g_country) == 0)
      copy(g_country,31,"未知地址")
   if (strlen(g_city) == 0)
      copy(g_city,31,"未知地址")
   }
   return PLUGIN_CONTINUE
}

public client_putinserver(id){
        if (!g_sql_connected)
                return PLUGIN_CONTINUE
        new ids
        ids=id
        set_task(8.0,"show_msg",0,ids,1)
        return PLUGIN_CONTINUE
}

public show_msg(ids[]){
   new name,ip,id,pos
   id=ids
   if (get_cvar_num("amx_hideop")){
      if (get_user_flags(id)&ADMIN_IMMUNITY) {
         get_user_name(id,name,31)
         pos += format(g_buffer,511-pos," %s ",name)
         pos += format(g_buffer,511-pos,"进入服务器,他来自:^n")
         pos += format(g_buffer,511-pos," 身份OP,地址隐藏")
   //    pos += format(g_buffer,511-pos," 祝您玩的愉快!")
      }
      else{
         get_user_name(id,name,31)
           get_user_ip(id,ip,15,1)
         pos += format(g_buffer,511-pos,"%s 终于来啦! ^n",name)
         pos += format(g_buffer,511-pos,"他的IP:%s ^n",ip)
         pos += format(g_buffer,511-pos,"来自:%s / %s",g_country,g_city)
      // pos += format(g_buffer,511-pos," 祝您玩的愉快,请不要作弊!")
      }
   }
   else{
      get_user_name(id,name,31)
        get_user_ip(id,ip,15,1)
        pos += format(g_buffer,511-pos,"%s 终于来啦! ^n",name)
        pos += format(g_buffer,511-pos,"他的IP:%s ^n",ip)
        pos += format(g_buffer,511-pos,"来自:%s / %s",g_country,g_city)
         //pos += format(g_buffer,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,inum,state
   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,511-iLen," 连接sql服务器失败, 请检查设置或者sql服务器")
   else{
      iLen += format( sBuffer,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,name
        if(get_cvar_num("amx_hideop")){
            if (get_user_flags(players)&ADMIN_IMMUNITY) {
               get_user_name(players,name,31)
               iLen += format(sBuffer,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,2047-iLen,"<tr class=%s><td>%1s<td>%s<td>%s%s</tr>",state,name,ip,g_country],g_city])
            }
         }
         else{
            get_user_name(players,name,31)
            get_user_ip(players,ip,31,1)
            iLen += format(sBuffer,2047-iLen,"<tr class=%s><td>%1s<td>%s<td>%s%s</tr>",state,name,ip,g_country],g_city])
         }
      }
   }
   show_motd(id, sBuffer, "查看玩家来源:" )
   return PLUGIN_HANDLED
}

public plugin_end(){
        if (!g_sql_connected)
                return PLUGIN_CONTINUE
        mysql_close(g_dbc)
        server_print(" SQL Connection closed!")
        return PLUGIN_CONTINUE
}

你们认为怎样呢?
改源就是进步!!

yanhaifu 发表于 2005-1-24 12:38:22

试下sdfsdfdsfsdf

黄泉 发表于 2005-1-24 12:46:36

我来瞧瞧哦~

wiskey00 发表于 2005-1-24 12:51:12

look look

dgh386 发表于 2005-1-24 13:06:44

晕,回复.....................

youaibieku 发表于 2005-1-24 13:06:55

好吗??//?

dgh386 发表于 2005-1-24 13:08:19

这个IP库可够厉害,连我这小地方的网吧都能显示,强!!!

wzf828 发表于 2005-1-24 13:16:30

Post by yanexp
【隐藏帖】

看看好东西

eddiefish1 发表于 2005-1-24 13:35:15

不回可以吗
?

BoeZombie 发表于 2005-1-24 13:38:18

我就是不回帖
页: [1] 2 3
查看完整版本: 我网吧用的显IP来源插件!~~