
   /*********************************************************************
   **
   * amx_ejl_whoplayer.sma      version 1.9.1           November 3/2002
   *  By:  Eric Lidman    Alias: Ludwig van       ejlmozart@hotmail.com
   *  Upgrade: http://lidmanmusic.com/cs/plugins.html
   *
   * This plugin serves 2 functions:
   *
   * 1. Find out if known players are playing on the server even if they
   *    are using a different name. Good for tracking regular players,
   *    trouble-maker players, and suspected cheaters.
   * 2. Logs all players AUTHIDS to file with their names beside them.
   *    Using the log file makes evil player/cheater management easier.
   *    This was requested by the pixscotty server and they report to me
   *    its been extreemly useful. I myself have found it valuable. I
   *    hope it helps whoever gets it. *** Revised -- now includes IP
   *    adresses as well.
   *
   *
   * Commands:
   *
   *  amx_whoplayer   -- shows whos playing, listing their known name
   *                       and matching it up with thier current name.
   *  amx_who_reload  -- If you make changes the the regplayers.txt and
   *                       you want to see them right away, issue this
   *                       command.  Otherwise  you will have to wait for
   the
   *                       map to change for the file to reload showing
   *                       the changes. Admin ACCESS_RCON is required.
   *  amx_who_add <player> <name in quotes>
   *                  -- To add players to the known list regplayers.txt
   *                     in-game you can now use this command. You may
   *                     specify a name by which to recognize them later
   *
   * CVAR:
   *
   *  amx_whoplayer_hideadmins 0   -- if set to 1, admins will not be
   *                                  identified at all when command
   *                                  amx_whoplayer is used by players
   *                                  other admins will still see you
   *                                  identified though
   *
   * Setup:  You will need to create a text file called: regplayers.txt
   *   It goes in your ..addons/amx directory.
   *   The format of it is: <wonid> <name>
   *
   *     example:       1234576 Ludwigvan
   *                    34343   vodka
   *
   *   The name cannot contain spaces. This name is how you will identify
   *   a  regular  player.  If there is no match for a players wonid, the
   name
   *   will be *****, indicating an unknown player. Under its current
   *   setup, you can only have 200 entries in the file.
   *   There were thoughts of making the collection of regular players
   *   automatic. Feel free to if you like of course. My thought was that
   *   any system I came up with to do that would make the server laggy
   *   using alot of CPU and memory and would thrash the hard-drive on
   *   client connects. So I opted to make the adding of regular players
   *   manual instead to avoid all that. It shouldnt be too hard to do if
   *   you use the info in the id log files this plugin produces.
   *
   *  Important: For the logging to work, you need to set up some folders
   *   on your server. You need: ../%moddir%/admin_logs/id_logs
   *
   *     example:      ../cstrike/admin_logs/id_logs
   *
   **********************************************************************
   /
   #include <amxmod>
   #include <amxmisc>
   new RegPlaInfo[500][32]
   new RegPlaName[500][32]
   new TotalRegPla
   public plugin_init(){
       register_plugin("WhoPlayerIDTracking", "1.9.1", "EJL")
       register_concmd("amx_whoplayer",   "admin_whoplayer",  ADMIN_USER,
   ":  Find  out  what  players are currently playing if have a different
   name.")
       register_concmd("amx_who_reload",  "admin_who_reload", ADMIN_RCON,
   ": Reloads regplayers.txt in the middle of a round.")
       register_concmd("amx_who_add",     "admin_who_add",    ADMIN_RCON,
   "<player> <name in quotes> : adds a player to regplayers.txt")
       if(file_exists("addons/amx/regplayers.txt") == 1){
           new line = 0
           new data[128]
           new stextsize = 0
           while((line=read_file("addons/amx/regplayers.txt",line,data,12
   8,stextsize))!=0){
               if((!data) || (equal(data," ",1)) ){
                   continue
               }else{
                   TotalRegPla += 1
                   if(TotalRegPla < 500){
                       parse(data,      RegPlaInfo[TotalRegPla],      31,
   RegPlaName[TotalRegPla], 31)
                   }
               }
           }
       }
       register_cvar("amx_whoplayer_hideadmins","0")
       set_cvar_num("amx_whoplayer_hideadmins",0)
       new ThisMap[32]
       get_mapname(ThisMap,31)
       new idlog[192]
       new filename[100]
       get_time("admin_logs/id_logs/%Y-%m-%d--id.log",filename,99)
       format(idlog,191,"START MAP:  %s",ThisMap)
       log_to_file(filename,idlog)
       return PLUGIN_CONTINUE
   }
   public admin_whoplayer(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       new rst = get_cvar_num("amx_whoplayer_hideadmins")
       new i
       new j
       new maxpl = get_maxplayers()+1
       new Name[32]
       new Authid[32]
       new RegPlaCurName[32]
       new doneit
       console_print(id,"^nCurrent  Name     /    Known  Name  +  Cheater
   Status?")
       for (j = 1; j <= maxpl; j++) {
           doneit = 0
           get_user_authid(j,Authid,31)
           get_user_name(j,Name,31)
           if(            (!(get_user_flags(id)&ADMIN_MAP))            &&
   (get_user_flags(j)&ADMIN_MAP) && (rst) ){
               if(is_user_connected(j) == 1){
                   console_print(id, "%s            *****", Name)
                   doneit = 1
               }
           }else{
               for (i = 1; i <= TotalRegPla; i++) {
                   if(is_user_connected(j) == 1){
                       if(equal(Authid, RegPlaInfo[i])){
                           copy(RegPlaCurName, 31, Name)
                           console_print(id,"%s            %s",
   RegPlaCurName,RegPlaName[i])
                           doneit = 1
                       }
                   }
               }
           }
           if(is_user_connected(j) == 1){
               if(doneit == 0){
                   console_print(id, "%s            *****", Name)
               }
           }
       }
       client_cmd(id,"echo  ")
       return PLUGIN_HANDLED
   }
   public admin_who_reload(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       TotalRegPla = 0
       if(file_exists("addons/amx/regplayers.txt") == 1){
           new line = 0
           new data[128]
           new stextsize = 0
           while((line=read_file("addons/amx/regplayers.txt",line,data,12
   7,stextsize))!=0){
               if( (equal(data,"")) || (equal(data," ",1)) ){
                   continue
               }else{
                   TotalRegPla += 1
                   if(TotalRegPla < 500){
                       parse(data,      RegPlaInfo[TotalRegPla],      31,
   RegPlaName[TotalRegPla], 31)
                   }
               }
           }
           if(TotalRegPla >= 500)
               client_cmd(id,"echo  Error:  regplayers.txt  is full at %d
   lines. Modify plugin to allow for more.",TotalRegPla)
           else
               client_cmd(id,"echo     Reloaded:    regplayers.txt.   Any
   changes made are now in effect.")
       }
       return PLUGIN_HANDLED
   }
   public admin_who_add(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new fail = 0
       new arg[32]
       new Authid[32]
       new commonname[32]
       read_argv(1,arg,31)
       new player = cmd_target(id,arg,1)
       if (!player) return PLUGIN_HANDLED
       read_argv(2,commonname,31)
       if(strlen(commonname) > 31){
           client_print(id,print_console,"[AMX]  Common  identifier  name
   must be 31 characters or less")
           return PLUGIN_HANDLED
       }
       if(!strlen(commonname))
           get_user_name(player,commonname,31)
       for (new i = 1; i <= TotalRegPla; i++) {
           if(equal(Authid, RegPlaInfo[i])){
               fail = 1
           }
       }
       if(!fail){
           new newentry[128]
           format(commonname,31,"^"%s^"",commonname)
           format(newentry,127,"%s  %s",Authid,commonname)
           write_file("addons/amx/regplayers.txt",newentry,-1)
           client_cmd(id,"echo  [AMX] New entry added to file. Attempting
   to reload file.")
           client_cmd(id,"amx_who_reload")
       }else{
           client_cmd(id,"echo  [AMX]  FAIL:  Target player is already in
   the regplayers.txt")
       }
       return PLUGIN_HANDLED
   }
   public client_connect(id){
       new User[32]
       new AUTHID[32]
       new IPAddy[32]
       new idlog[192]
       new filename[100]
       get_time("admin_logs/id_logs/%Y-%m-%d--id.log",filename,99)
       get_user_authid(id,AUTHID,31)
       get_user_name(id,User,31)
       get_user_ip(id,IPAddy,31,1)
       format(idlog, 191, "%s   %s    %s", AUTHID,IPAddy, User)
       log_to_file(filename,idlog)
       return PLUGIN_CONTINUE
   }
   public client_infochanged(id){
       new cmd[32]
       read_argv(0,cmd,31)
       if( (equal(cmd,"name")) || (equal(cmd,"setinfo")) ){
           new newname[32]
           get_user_info(id,"name",newname,31)
           new arg[32]
           read_argv(2,arg,31)
           new idlog[192]
           new filename[100]
           new name[32]
           new AUTHID[32]
           new IPAddy[32]
           get_time("admin_logs/id_logs/%Y-%m-%d--id.log",filename,99)
           get_user_authid(id,AUTHID,31)
           get_user_ip(id,IPAddy,31,1)
           get_user_name(id,name,31)
           if(equal(newname,name))
               format(idlog,    191,    "%s   %s    %s",   AUTHID,IPAddy,
   arg)
           else
               format(idlog,    191,    "%s   %s    %s",   AUTHID,IPAddy,
   newname)
           log_to_file(filename,idlog)
       }
       return PLUGIN_CONTINUE
   }
