
   /* AMX Mod script.
   *
   * (c) 2003, OLO and revised by snafus
   * This file is provided as is (no warranties).
   *
   */
   #include <amxmod>
   #define MAX_ADMINS    128
   new g_aPassword[MAX_ADMINS][32]
   new g_aName[MAX_ADMINS][32]
   new g_aFlags[MAX_ADMINS]
   new g_aAccess[MAX_ADMINS]
   new g_aNames[MAX_ADMINS][160]
   new g_aClanTags[MAX_ADMINS][50]
   new g_aNum
   new logfilename[256]
   public plugin_init()
   {
       register_plugin("Admin Base++","0.9.4","default += Snafus")
       register_cvar("amx_mode","2.0")
       register_cvar("amx_password_field","_pw")
       register_cvar("amx_default_access","")
       remove_user_flags(0,read_flags("z"))  /*  remove  'user' flag from
   server rights */
       get_time("addons/amx/logs/admin%m%d.log",logfilename,255)
       server_cmd("exec addons/amx/amx.cfg")
       loadSettings(  "addons/amx/users.ini" ) /* load admins accounts */
       return PLUGIN_CONTINUE
   }
   loadSettings(szFilename[])
   {
       if (!file_exists(szFilename)) return 0

       new szText[256], szFlags[32], szAccess[32]
       new a, pos = 0

       while ( g_aNum < MAX_ADMINS &&
   read_file(szFilename,pos++,szText,255,a) )
       {
           if ( szText[0] == ';'    ) continue

           if  (  parse(szText,  g_aName[  g_aNum  ] ,31,    g_aPassword[
   g_aNum ], 31,
               szAccess,31,szFlags,31,  g_aNames[  g_aNum ], g_aClanTags[
   g_aNum ] )     <  6 ) continue
           g_aAccess[ g_aNum ] = read_flags( szAccess )
           g_aFlags[ g_aNum ] = read_flags( szFlags )
           ++g_aNum
       }

       return 1
   }
   getAccess(id,name[],authid[],ip[], password[]){
       new index = -1
       new result = 0
       for(new i = 0; i < g_aNum; ++i) {
           if (g_aFlags[i] & FLAG_AUTHID) {
               if (equal(authid,g_aName[i])) {
                   index = i
                   if(g_aFlags[i] & FLAG_NEEDNAME) {
                       if(containi(g_aNames[i],name)==-1)
                           index = -1
                   }
                   if(g_aFlags[i] & FLAG_NEEDCLAN) {
                       if(containi(name,g_aClanTags[i])==-1)
                           index = -1
                   }
                   break
               }
           }
           else if (g_aFlags[i] & FLAG_IP) {
               if (contain(ip,g_aName[i])!=-1){
                   index = i
                   if(g_aFlags[i] & FLAG_NEEDNAME) {
                       if(containi(g_aNames[i],name)==-1)
                           index = -1
                   }
                   if(g_aFlags[i] & FLAG_NEEDCLAN) {
                       if(containi(name,g_aClanTags[i])==-1)
                           index = -1
                   }
                   break
               }
           }
           else {
               if (g_aFlags[i] & FLAG_TAG)    {
                   if (contain(name,g_aName[i])!=-1){
                       index = i
                       break
                   }
               }
               else if (equal(name,g_aName[i])) {
                   index = i
                   break
               }
           }
       }
       if (index != -1) {
           if (g_aFlags[index] & FLAG_NOPASS){
               result |= 8
               new sflags[32]
               get_flags(g_aAccess[index],sflags,31)
               set_user_flags(id,g_aAccess[index])
               log_to_file(logfilename,"Login: ^"%s<%d><%s><>^" become an
   admin (account ^"%s^") (access ^"%s^") (address ^"%s^")",
                   name,get_user_userid(id),authid,g_aName[index]
   ,sflags,ip)
           }
           else if (equal(password,g_aPassword[index])) {
               result |= 12
               set_user_flags(id,g_aAccess[index])
               new sflags[32]
               get_flags(g_aAccess[index],sflags,31)
               log_to_file(logfilename,"Login: ^"%s<%d><%s><>^" become an
   admin (account ^"%s^") (access ^"%s^") (address ^"%s^")",
                   name,get_user_userid(id),authid,g_aName[index]
   ,sflags,ip)
           }
           else {
               result |= 1
               if (g_aFlags[index] & FLAG_KICK){
                   result |= 2
                   log_to_file(logfilename,"Login:       ^"%s<%d><%s><>^"
   kicked due to invalid password (account ^"%s^") (address ^"%s^")",
                       name,get_user_userid(id),authid,g_aName[index],ip)
               }
           }
       }
       else if (get_cvar_float("amx_mode")==2.0) {
           result |= 2
       }
       else {
           new defaccess[32]
           get_cvar_string("amx_default_access",defaccess,31)
           new idefaccess = read_flags(defaccess)
           if (idefaccess){
               result |= 8
               set_user_flags(id,idefaccess)
           }
     }

       return result
   }
   accessUser(id,username[32])
   {
       new userip[32],userauthid[32],password[32],passfield[32]
       get_user_ip(id,userip,31)
       get_user_authid(id,userauthid,31)
       get_cvar_string("amx_password_field",passfield,31)
       get_user_info(id,passfield,password,31)
       new result = getAccess(id,username,userauthid,userip,password)
       if (result & 1) client_cmd(id,"echo * Invalid Password!")
       if (result & 2) {
           client_cmd(id,"echo    *    You   have   no   entry   to   the
   server...;disconnect")
           return PLUGIN_HANDLED
       }
       if (result & 4) client_cmd(id,"echo * Password accepted")
       if (result & 8) client_cmd(id,"echo * Privileges set")
       return PLUGIN_CONTINUE
   }
   public client_infochanged(id)
   {
       new newname[32], oldname[32]

       get_user_name(id,oldname,31)
       get_user_info(id,"name",newname,31)

       if (is_user_connected(id)&&!equal(newname,oldname))
       {
           remove_user_flags(id)
           accessUser(id,newname)
       }

       return PLUGIN_CONTINUE
   }
   public client_connect(id)
   {
       if ( get_cvar_num("amx_mode") == 0 )
           return PLUGIN_CONTINUE

       remove_user_flags(id)
       new name[32]
       get_user_name(id,name,31)

       return accessUser(id,name)
   }
