
   /*********************************************************************
   ******
   *  amx_ejl_adminaccess.sma
   *   version 1.9a        Date: 1/3/2002
   *   Author: Eric Lidman     ejlmozart@hotmail.com
   *   Alias: Ludwig van       Upgrade:
   http://lidmanmusic.com/cs/plugins.html
   *
   *  Grant  admin access to anyone or take it away on the fly. There are
   2
   *   levels  the  plugin  reponds to ADMIN_RCON lets you modify anyones
   access.
   *   ADMIN_LEVEL_B   admins   can  modify  anyone  who  does  not  have
   ADMIN_LEVEL_B
   *   access, but only for certain flags as this is a restricted form of
   the
   *   command. Built in safegards prevent you from messing up your own
   *   access  level.  Also,  when  the  first  admin who changes another
   player's
   *   access  leaves,  the  player's access is returned automatically to
   default
   *   server  access. The changes only last until the player disconnects
   or
   *   the map changes.
   *
   *  Commands:
   *
   *   amx_makeadmin_help                   Get list of access flags
   *   amx_makeadmin <player> <flags>       give admin power temporary
   *                                         full   use   requires   RCON
   ACCESS
   *                                         limited     use     requires
   ADMIN_LEVEL_B
   *   amx_return_access <player>           Returns a player/admin to the
   *                                         access   he   had   when  he
   entered the
   *                                         server.             Requires
   ADMIN_LEVEL_B
   *   amx_killadmin <player>               strips admin of power
   *                                         RCON ACCESS REQUIRED
   *
   *
   *  Setup:
   *
   *   Requires  the  creation  of  the  folder  "admin_logs" in your mod
   directory
   *   if  you  do  not  have  one  already  --  its  for special logging
   purposes.
   *   WARNING: Failure to create the folder will result in errors.
   *
   **********************************************************************
   ******/
   #include <amxmod>
   #include <amxmisc>
   new AccessInfo[33][34]
   new OldFlags[33]
   public plugin_init() {
       register_plugin("Grant Remove Admin","0.9","EJL")
       // ADMIN_RCON LEVEL ADMINS can kill all access
       // from an admin (except for real rcon)
       register_concmd("amx_killadmin","kill_admin_access",ADMIN_RCON,"<p
   layer>  :  Strips an admin of his access in game.")
       register_concmd("amx_makeadmin","make_admin_access",ADMIN_LEVEL_B,
   "<player>    <flags>    :  Give    admin    power   to   player   till
   disconnect/change.")
       register_concmd("amx_makeadmin_help","make_admin_access",ADMIN_LEV
   EL_B,"Get list of access flags")
       register_concmd("amx_return_access","make_admin_access",ADMIN_LEVE
   L_B,"<player>  : Returns admin/player to access they had when entering
   game")
       return PLUGIN_CONTINUE
   }
   public client_connect(id){
       AccessInfo[id][0] = 0
       AccessInfo[id][1] = 0
       OldFlags[id] = 0
       return PLUGIN_CONTINUE
   }
   public client_putinserver(id){
       OldFlags[id] = get_user_flags(id)
       return PLUGIN_CONTINUE
   }
   public client_disconnect(id){
       new maxpl = get_maxplayers() +1
       for(new a=1; a < maxpl; a++) {
           if(AccessInfo[a][0] == 1){
               if(AccessInfo[a][1] == id){
                   remove_user_flags(a,-1)
                   set_user_flags(a,OldFlags[a])
                   new Aname[32], name[32], AUTHID[40], authid2[40]
                   get_user_name(id,Aname,31)
                   get_user_name(a,name,31)
                   get_user_authid(id,AUTHID,39)
                   get_user_authid(a,authid2,39)
                   client_print(a,print_chat,"[AMX]   %s   changed   your
   access, but left. Returing you to your original access",name)
                   log_to_file("admin_logs/ADMIN_ACCESS_CHANGE.log","DONE
   ADMIN:  %s  %s  left,  original access given to player whose access he
   modified: %s %s",Aname,AUTHID, name,authid2 )
               }
           }
       }
       AccessInfo[id][0] = 0
       AccessInfo[id][1] = 0
       OldFlags[id] = 0
       return PLUGIN_CONTINUE
   }
   public kill_admin_access(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new arg[32]
       read_argv(1,arg,31)
       new player = cmd_target(id,arg,0)
       if (!player) return PLUGIN_HANDLED
       new name[32]
       new Aname[32]
       new AUTHID[40]
       new authid2[40]
       get_user_name(id,Aname,31)
       get_user_name(player,name,31)
       get_user_authid(id,AUTHID,39)
       get_user_authid(player,authid2,39)
       if( id == player ){
           client_print(id,print_console,"[AMX]  You  cannot  take  admin
   away from yourself.")
           return PLUGIN_HANDLED
       }
       remove_user_flags(player,-1)
       new defa[32]
       get_cvar_string("amx_default_access",defa,31)
       set_user_flags(player,read_flags(defa))
       client_print(id,print_console,"[AMX] %s has been stripped of admin
   power for the remainder of his connect.",name)
       log_to_file("admin_logs/ADMIN_ACCESS_CHANGE.log","KILLADMIN:    %s
   %s  .........   stripped   power  of  .........  %s  %s",Aname,AUTHID,
   name,authid2 )

       return PLUGIN_HANDLED
   }
   public make_admin_access(id,level,cid){
       new defa[32]
       new defa1[32]
       new cmd[32]
       read_argv(0,cmd,31)
       if(equali(cmd[14],"h",1)){
           if (!cmd_access(id,level,cid,1))
               return PLUGIN_HANDLED
           client_cmd(id,"echo [AMX] Access Flag codes:")
           client_cmd(id,"echo [AMX] a  -- ADMIN_IMMUNITY")
           client_cmd(id,"echo [AMX] b  -- ADMIN_RESERVATION")
           client_cmd(id,"echo [AMX] c  -- ADMIN_KICK")
           client_cmd(id,"echo [AMX] d  -- ADMIN_BAN")
           client_cmd(id,"echo  [AMX]  e  --  ADMIN_SLAY  <and  slay type
   commands, timebomb, zap, lightsaber>")
           client_cmd(id,"echo  [AMX]  f  -- ADMIN_MAP <required for most
   other access too and includes yy commands>")
           client_cmd(id,"echo [AMX] g  -- ADMIN_CVAR")
           client_cmd(id,"echo [AMX] h  -- ADMIN_CFG")
           client_cmd(id,"echo [AMX] i  -- ADMIN_CHAT <and all admin type
   say commands>")
           client_cmd(id,"echo [AMX] j  -- ADMIN_VOTE <like amx_vote>")
           client_cmd(id,"echo [AMX] k  -- ADMIN_PASSWORD")
           client_cmd(id,"echo [AMX] l  -- ADMIN_RCON")
           client_cmd(id,"echo   [AMX]   m  --   ADMIN_LEVEL_A   <special
   commands like amx_heal and amx_nukem")
           client_cmd(id,"echo  [AMX]  n  -- ADMIN_LEVEL_B <extra special
   admins only, include limited access to makeadmin")
           client_cmd(id,"echo [AMX] o  -- ADMIN_LEVEL_C")
           client_cmd(id,"echo [AMX] p  -- ADMIN_LEVEL_D")
           client_cmd(id,"echo [AMX] q  -- ADMIN_LEVEL_E")
           client_cmd(id,"echo [AMX] r  -- ADMIN_LEVEL_F")
           client_cmd(id,"echo   [AMX]   s  --  ADMIN_LEVEL_G  <addtional
   punishemnts like amx_bury>")
           client_cmd(id,"echo  [AMX]  t  -- ADMIN_LEVEL_H <limited cvars
   like gravity and scotty contoller>")
           client_cmd(id,"echo [AMX] u  -- ADMIN_MENU")
           client_cmd(id,"echo  [AMX]  z  --  ADMIN_USER  <if you want to
   remove an admin's power use this alone>")
           return PLUGIN_HANDLED
       }
       new name[32]
       new Aname[32]
       new AUTHID[40]
       new authid2[40]
       get_user_name(id,Aname,31)
       get_user_authid(id,AUTHID,39)
       new arg[32]
       read_argv(1,arg,31)
       new player = cmd_target(id,arg,0)
       if (!player) return PLUGIN_HANDLED
       if(equali(cmd[4],"r",1)){
           if (!cmd_access(id,level,cid,2))
               return PLUGIN_HANDLED
           get_user_name(player,name,31)
           get_user_authid(player,authid2,39)
           set_user_flags(player,OldFlags[player])
           console_print(id,"[AMX]  %s  has been returned to his original
   access status",name)
           log_to_file("admin_logs/ADMIN_ACCESS_CHANGE.log","RETURNACCESS
   :   %s   %s  .........   returned   original   access   to:  .....  %s
   %s",Aname,AUTHID, name,authid2 )
           return PLUGIN_HANDLED
       }
       if (!cmd_access(id,level,cid,3))
           return PLUGIN_HANDLED
       new arg2[32]
       read_argv(2,arg2,31)
       get_user_name(player,name,31)
       get_user_authid(player,authid2,39)
       if (get_user_flags(id)&ADMIN_RCON){
           if( ( (containi(arg2,"n") ==-1) || (containi(arg2,"l") ==-1) )
   && (id == player) ){
               client_cmd(id,"echo  [AMX]  You  cannot  take  ADMIN_RCON,
   flags L and N away from yourself.")
               return PLUGIN_HANDLED
           }else{
               remove_user_flags(player,-1)
               get_cvar_string("amx_default_access",defa,31)
               new iflcount = strlen(defa)
               new tempa[2]
               if(iflcount){
                   for(new i = 0; i<=iflcount; i++) {
                       copy(tempa,1,defa[i])
                       if(containi(defa1,tempa)==-1){
                           if(containi(arg2,tempa) ==-1){
                               add(defa1,31,tempa)
                           }
                       }
                   }
                   add(arg2,31,defa1)
               }
               set_user_flags(player, read_flags(arg2))
               if(AccessInfo[player][0] == 0){
                   AccessInfo[player][0] = 1
                   AccessInfo[player][1] = id
               }
           }
       }
       else if(get_user_flags(id)&ADMIN_LEVEL_B){
           if( id == player ){
               client_cmd(id,"echo   [AMX]  Access  Flag  codes  you  may
   grant:")
               client_cmd(id,"echo  [AMX] e  -- ADMIN_SLAY <and slay type
   commands, timebomb, zap, lightsaber>")
               client_cmd(id,"echo  [AMX]  f  --  ADMIN_MAP <required for
   most other access too and includes yy commands>")
               client_cmd(id,"echo  [AMX] i  -- ADMIN_CHAT <and all admin
   type say commands>")
               client_cmd(id,"echo    [AMX]    j  --   ADMIN_VOTE   <like
   amx_vote>")
               client_cmd(id,"echo  [AMX]  m  --  ADMIN_LEVEL_A  <special
   commands like amx_heal and amx_nukem")
               client_cmd(id,"echo      [AMX]     r  --     ADMIN_LEVEL_F
   <unassigned>")
               client_cmd(id,"echo  [AMX]  s  -- ADMIN_LEVEL_G <addtional
   punishemnts like amx_bury>")
               client_cmd(id,"echo  [AMX]  t  --  ADMIN_LEVEL_H  <limited
   cvars live gravity and scotty contoller>")
               client_cmd(id,"echo [AMX] z  -- ADMIN_USER <if you want to
   remove an admin's power use this alone>")
               client_cmd(id,"echo  [AMX] You cannot take change your own
   admin power.")
               return PLUGIN_HANDLED
           }
           else if(get_user_flags(player)&ADMIN_LEVEL_B){
               client_print(id,print_console,"[AMX]   You  cannot  adjust
   this admin's power.")
               return PLUGIN_HANDLED
           }
           if( (containi(arg2,"a") !=-1) ||
               (containi(arg2,"b") !=-1) ||
               (containi(arg2,"c") !=-1) ||
               (containi(arg2,"d") !=-1) ||
               (containi(arg2,"g") !=-1) ||
               (containi(arg2,"h") !=-1) ||
               (containi(arg2,"k") !=-1) ||
               (containi(arg2,"l") !=-1) ||
               (containi(arg2,"n") !=-1) ||
               (containi(arg2,"o") !=-1) ||
               (containi(arg2,"p") !=-1) ||
               (containi(arg2,"q") !=-1) ||
               (containi(arg2,"u") !=-1) ){
               client_cmd(id,"echo   [AMX]  Access  Flag  codes  you  may
   grant:")
               client_cmd(id,"echo  [AMX] e  -- ADMIN_SLAY <and slay type
   commands, timebomb, zap, lightsaber>")
               client_cmd(id,"echo  [AMX]  f  --  ADMIN_MAP <required for
   most other access too and includes yy commands>")
               client_cmd(id,"echo  [AMX] i  -- ADMIN_CHAT <and all admin
   type say commands>")
               client_cmd(id,"echo    [AMX]    j  --   ADMIN_VOTE   <like
   amx_vote>")
               client_cmd(id,"echo  [AMX]  m  --  ADMIN_LEVEL_A  <special
   commands like amx_heal and amx_nukem")
               client_cmd(id,"echo      [AMX]     r  --     ADMIN_LEVEL_F
   <unassigned>")
               client_cmd(id,"echo  [AMX]  s  -- ADMIN_LEVEL_G <addtional
   punishemnts like amx_bury>")
               client_cmd(id,"echo  [AMX]  t  --  ADMIN_LEVEL_H  <limited
   cvars live gravity and scotty contoller>")
               client_cmd(id,"echo  [AMX] z  -- DEFAULT_PLAYER_ACCESS <if
   you want to remove an admin's power use this alone>")
               client_cmd(id,"echo  [AMX]  Sorry, you cannot grant any of
   the flags: abcdghklnopqu  to anyone")
               return PLUGIN_HANDLED
           }else{
               remove_user_flags(player,-1)
               get_cvar_string("amx_default_access",defa,31)
               new iflcount = strlen(defa)
               new tempa[2]
               if(iflcount){
                   for(new i = 0; i<=iflcount; i++) {
                       copy(tempa,1,defa[i])
                       if(containi(defa1,tempa)==-1){
                           if(containi(arg2,tempa) ==-1){
                               add(defa1,31,tempa)
                           }
                       }
                   }
                   add(arg2,31,defa1)
               }
               set_user_flags(player, read_flags(arg2))
               if(AccessInfo[player][0] == 0){
                   AccessInfo[player][0] = 1
                   AccessInfo[player][1] = id
               }
           }
       }else{
           console_print(id,"[AMX] Fail! You should never see this.")
           return PLUGIN_HANDLED
       }
       console_print(id,"[AMX]   If   necessary  for  execution  of  some
   commands like amx_map, you also need turn on amx_ah_guest")
       new orgflag1[32]
       new orgflag2 = read_flags(arg2)
       get_flags(orgflag2,orgflag1,31)
       if(strlen(defa1) == 0)
           console_print(id,"[AMX]       %s       now      has      admin
   temporarily  -->  flags: %s",name,orgflag1)
       else
           console_print(id,"[AMX]       %s       now      has      admin
   temporarily  -->  flags:   %s   <Auto   added   req.   default  flags:
   %s>",name,orgflag1,defa1)
       log_to_file("admin_logs/ADMIN_ACCESS_CHANGE.log","MAKEADMIN:    %s
   %s  .........    gave    admin    accss   flags:  %s  to:   .....   %s
   %s",Aname,AUTHID, arg2, name,authid2 )
       return PLUGIN_HANDLED
   }
