
   /* AMX Mod script.
   *
   * (c) Copyright 2002, OLO
   * This file is provided as is (no warranties).
   *
   * Commands added amx_t < name or wonid >
   *                  amx_ct < name or wonid >
   *
   */
   #include <amxmod>
   #include <amxmisc>
   new logfilename[256]
   public admin_kick(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,1)
       if (!player) return PLUGIN_HANDLED
       new authid[16],authid2[16],name2[32],name[32],userid2, arg2[32]
       get_user_authid(id,authid,15)
       get_user_authid(player,authid2,15)
       get_user_name(player,name2,31)
       get_user_name(id,name,31)
       userid2 = get_user_userid(player)
       read_argv(2,arg2,31)
       log_to_file(logfilename,"Kick:        ^"%s<%d><%s><>^"        kick
   ^"%s<%d><%s><>^" (reason ^"%s^")",
           name,get_user_userid(id),authid, name2,userid2,authid2,arg2 )

       switch(get_cvar_num("amx_show_activity"))    {
       case      2:    client_print(0,print_chat,"ADMIN      %s:     kick
   %s",name,name2)
       case 1:    client_print(0,print_chat,"ADMIN: kick %s",name2)
       }

       server_cmd("kick #%d",userid2)
       console_print(id,"Client ^"%s^" kicked",name2)
       return PLUGIN_HANDLED
   }
   public admin_unban(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new arg[32],authid[16],name[32]
       get_user_name(id,name,31)
       read_argv(1,arg,31)
       if (contain(arg,".")!=-1)    {
           server_cmd("removeip ^"%s^";writeip",arg)
           console_print(id,"Ip ^"%s^" removed from ban list", arg  )
       }
       else {
           server_cmd("removeid ^"%s^";writeid",arg)
           console_print(id,"Authid ^"%s^" removed from ban list", arg  )
       }
       switch(get_cvar_num("amx_show_activity"))    {
           case    2:    client_print(0,print_chat,"ADMIN    %s:    unban
   %s",name,arg)
           case 1:    client_print(0,print_chat,"ADMIN: unban %s",arg)
       }
       get_user_authid(id,authid,15)
       log_to_file(logfilename,"Cmd: ^"%s<%d><%s><>^" unban ^"%s^"",
           name,get_user_userid(id),authid, arg )
       return PLUGIN_HANDLED
   }
   public admin_ban(id,level,cid){
       if (!cmd_access(id,level,cid,3))
           return PLUGIN_HANDLED
       new arg[32]
       read_argv(2,arg,31)
       new player = cmd_target(id,arg,9)
       if (!player) return PLUGIN_HANDLED
       new         minutes[32],authid[16],name2[32],authid2[16],name[32],
   arg3[32]
       new userid2 = get_user_userid(player)
       read_argv(1,minutes,31)
       get_user_authid(player,authid2,15)
       get_user_authid(id,authid,15)
       get_user_name(player,name2,31)
       get_user_name(id,name,31)
       read_argv(3,arg3,31)
       log_to_file(logfilename,"Ban:   ^"%s<%d><%s><>^"   ban   and  kick
   ^"%s<%d><%s><>^" (minutes ^"%s^") (reason ^"%s^")",
           name,get_user_userid(id),authid,
   name2,userid2,authid2,minutes,arg3 )

       if (equal("4294967295",authid2)){ /* lan */
           new ipa[32]
           get_user_ip(player,ipa,31,1)
           server_cmd("addip %s %s;writeip",minutes,ipa)
       }
       else
           server_cmd("banid %s #%d kick;writeid",minutes,userid2)

       new activity = get_cvar_num("amx_show_activity")
       if (activity)    {
           new temp[64], temp2[64]
           if (activity == 1)
               copy(temp,63,"ADMIN:")
           else
               format(temp,63,"ADMIN %s:",name)
           if (strtonum(minutes))
               format(temp2,63,"for %s min.",minutes)
           else
               copy(temp2,63,"permanently")
           client_print(0,print_chat,"%s ban %s %s",temp,name2,temp2)
       }

       console_print(id,"Client ^"%s^" banned",name2)
       return PLUGIN_HANDLED
   }
   public admin_slay(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,5)
       if (!player) return PLUGIN_HANDLED
       user_kill(player)
       new authid[16],name2[32],authid2[16],name[32]
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       get_user_authid(player,authid2,15)
       get_user_name(player,name2,31)
       log_to_file(logfilename,"Cmd:         ^"%s<%d><%s><>^"        slay
   ^"%s<%d><%s><>^"",
           name,get_user_userid(id),authid,
   name2,get_user_userid(player),authid2 )

       switch(get_cvar_num("amx_show_activity"))    {
       case      2:    client_print(0,print_chat,"ADMIN      %s:     slay
   %s",name,name2)
       case 1:    client_print(0,print_chat,"ADMIN: slay %s",name2)
       }

       console_print(id,"Client ^"%s^" slayed",name2)
       return PLUGIN_HANDLED
   }
   public admin_slap(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,5)
       if (!player) return PLUGIN_HANDLED
       new power[32],authid[16],name2[32],authid2[16],name[32]
       read_argv(2,power,31)
       new damage = strtonum(power)
       user_slap(player,damage)
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       get_user_authid(player,authid2,15)
       get_user_name(player,name2,31)
       log_to_file(logfilename,"Cmd: ^"%s<%d><%s><>^" slap with %d damage
   ^"%s<%d><%s><>^"",
           name,get_user_userid(id),authid,
   damage,name2,get_user_userid(player),authid2 )

       switch(get_cvar_num("amx_show_activity"))    {
       case  2:    client_print(0,print_chat,"ADMIN  %s:  slap %s with %d
   damage",name,name2,damage)
       case   1:    client_print(0,print_chat,"ADMIN:  slap  %s  with  %d
   damage",name2,damage)
       }

       console_print(id,"Client      ^"%s^"      slaped      with      %d
   damage",name2,damage)
       return PLUGIN_HANDLED
   }
   public delayed_map(mapname[])
       server_cmd("changelevel %s",mapname)
   public admin_map(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new arg[32]
       new len = read_argv(1,arg,31)
       if (is_map_valid(arg)==0){
           console_print(id,"Map  with  that  name  not  found  or map is
   invalid")
           return PLUGIN_HANDLED
       }
       console_print(id,"Changing map")
       if (read_argc() > 2){
           message_begin(MSG_ALL, SVC_INTERMISSION)
           message_end()
           new arg2[32]
           read_argv(2,arg2,31)
           new Float:ftime = floatstr(arg2)
           if (ftime < 0.0) ftime = 0.0
           set_task( ftime + 0.5 ,"delayed_map",0,arg,len + 1)
       }
       else {
           set_task(0.5,"delayed_map",0,arg,len + 1)
       }
       new authid[16],name[32]
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)

       switch(get_cvar_num("amx_show_activity"))    {
           case  2:    client_print(0,print_chat,"ADMIN  %s:  changelevel
   %s",name,arg)
           case    1:    client_print(0,print_chat,"ADMIN:    changelevel
   %s",arg)
       }

       log_to_file(logfilename,"Cmd:     ^"%s<%d><%s><>^"     changelevel
   ^"%s^"",
           name,get_user_userid(id),authid, arg)
       return PLUGIN_HANDLED
   }
   #define CVARRCONSET 8
   new cvar_rcon[CVARRCONSET][] = {
   "rcon_password",
   "amx_show_activity",
   "amx_mode",
   "amx_password_field",
   "amx_default_access",
   "amx_reserved_slots",
   "amx_reservation",
   "amx_conmotd_file"
   }
   bool:cvars_only_with_rcon(arg[]) {
       for(new a=0; a<CVARRCONSET;++a)
           if ( equal(arg,cvar_rcon[a]) )
               return true
       return false
   }
   public admin_cvar(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new arg[32], arg2[64]
       read_argv(1,arg,31)
       read_argv(2,arg2,63)
       if (!cvar_exists(arg)){
           console_print(id,"Unknown cvar")
           return PLUGIN_HANDLED
       }
       if   (   cvars_only_with_rcon(arg)   &&   !(get_user_flags(id)   &
   ADMIN_RCON)){
           console_print(id,"You have no access to that cvar")
           return PLUGIN_HANDLED
       }
       else   if   (equal(arg,"sv_password")  &&  !(get_user_flags(id)  &
   ADMIN_PASSWORD)){
           console_print(id,"You have no access to that cvar")
           return PLUGIN_HANDLED
       }
       if (read_argc() < 3){
           get_cvar_string(arg,arg2,63)
           console_print(id,"Cvar ^"%s^" is ^"%s^"",arg,arg2)
           return PLUGIN_HANDLED
       }
       new authid[16],name[32]
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       log_to_file(logfilename,"Cmd:   ^"%s<%d><%s><>^"  set  cvar  (name
   ^"%s^") (value ^"%s^")",
           name,get_user_userid(id),authid, arg,arg2)
       set_cvar_string(arg,arg2)

       new activity = get_cvar_num("amx_show_activity")
       if (activity)    {
           new temp[64]
           if (activity == 1)
               copy(temp,63,"ADMIN:")
           else
               format(temp,63,"ADMIN %s:",name)
           client_print(0,print_chat,"%s      set      cvar     %s     to
   ^"%s^"",temp,arg,equal(arg,"rcon_password")  ?  "***  PROTECTED ***" :
   arg2)
       }

       console_print(id,"Cvar ^"%s^" changed to ^"%s^"",arg,arg2)
       return PLUGIN_HANDLED
   }
   public admin_cfg(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new arg[128]
       read_argv(1,arg,127)
       if (!file_exists(arg)){
           console_print(id,"File ^"%s^" not found",arg)
           return PLUGIN_HANDLED
       }
       new authid[16],name[32]
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       log_to_file(logfilename,"Cmd:  ^"%s<%d><%s><>^"  execute cfg (file
   ^"%s^")",
           name,get_user_userid(id),authid, arg)
       console_print(id,"Executing file ^"%s^"",arg)
       server_cmd("exec %s",arg)

       switch(get_cvar_num("amx_show_activity"))    {
               case  2:    client_print(0,print_chat,"ADMIN  %s:  execute
   config %s",name,arg)
               case    1:    client_print(0,print_chat,"ADMIN:    execute
   config %s",arg)
       }

       return PLUGIN_HANDLED
   }
   new pausecon
   new Float:fpausable
   new bool:bpaused
   public pause_success(){
       set_cvar_float("pausable",fpausable)
       console_print(pausecon,"Server   %s",   bpaused   ?  "unpaused"  :
   "paused")
       bpaused = !bpaused
       return PLUGIN_HANDLED
   }
   public admin_pause(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       new authid[16],name[32],slayer = id
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       fpausable = get_cvar_float("pausable")
       if (!slayer) slayer = find_player("h")
       if (!slayer){
           console_print(id,"Server  was  unable  to pause the game. Real
   players on server are needed")
           return PLUGIN_HANDLED
       }
       set_cvar_float("pausable",1.0)
       client_cmd(slayer,"pause;pause_loopback")
       log_to_file(logfilename,"Cmd: ^"%s<%d><%s><>^" %s server",
           name,get_user_userid(id),authid, bpaused ? "unpause" : "pause"
   )
       console_print(id,"Server  proceed  %s",  bpaused  ?  "unpausing" :
   "pausing")

       switch(get_cvar_num("amx_show_activity"))    {
           case     2:    client_print(0,print_chat,"ADMIN     %s:     %s
   server",name,bpaused ? "unpause" : "pause")
           case         1:    client_print(0,print_chat,"ADMIN:        %s
   server",bpaused ? "unpause" : "pause")
       }

       pausecon = id
       return PLUGIN_HANDLED
   }
   public admin_rcon(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new arg[128],authid[16],name[32]
       read_args(arg,127)
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       log_to_file(logfilename,"Cmd:   ^"%s<%d><%s><>^"   server  console
   (cmdline ^"%s^")",
           name,get_user_userid(id),authid, arg)
       console_print(id,"Commmand    line    ^"%s^"    sent   to   server
   console",arg)
       server_cmd(arg)
       return PLUGIN_HANDLED
   }
   public admin_who(id,level,cid){
       new players[32], inum, authid[16],name[32], flags, sflags[32]
       get_players(players,inum)
       console_print(id,"^nClients  on  server:^n  #  %-32.31s %-12s %-8s
   %-4.3s %-4.3s %s",
           "nick","authid","userid","imm","res","access")
       for(new a = 0; a < inum; ++a)    {
               get_user_authid(players[a],authid,15)
               get_user_name(players[a],name,31)
               flags = get_user_flags(players[a])
               get_flags(flags,sflags,31)
               console_print(id,"%2d  %-32.31s  %-12s  %-8d %-4.3s %-4.3s
   %s",    players[a],name,authid,
               get_user_userid(players[a]),(flags&ADMIN_IMMUNITY)?"yes":"
   no",
               (flags&ADMIN_RESERVATION)?"yes":"no",sflags)
       }
       console_print(id,"Total %d",inum)
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       log_to_file(logfilename,"Cmd:  ^"%s<%d><%s><>^"  ask  for  players
   list",name,get_user_userid(id),authid)
       return PLUGIN_HANDLED
   }
   has_tag(name[],ltags[4][32],ltagsnum){
       for(new a=0;a<ltagsnum;++a)
           if (contain(name,ltags[a])!=-1)
               return a
       return -1
   }
   public admin_leave(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new argnum = read_argc()
       new ltags[4][32]
       new ltagsnum = 0
       for(new a=1;a<5;++a){
           if (a<argnum)
               read_argv(a,ltags[ltagsnum++],31)
           else
               ltags[ltagsnum++][0] = 0
       }
       new nick[32], ires, pnum = get_maxplayers() + 1, count = 0
       for(new b=1;b<pnum;++b){
           if (!is_user_connected(b)&&!is_user_connecting(b)) continue
           get_user_name(b,nick,31)
           ires = has_tag(nick,ltags,ltagsnum)
           if (ires!=-1){
               console_print(id,"Skipping  ^"%s^"  because  client  match
   with ^"%s^"",nick,ltags[ires])
               continue
           }
           if (get_user_flags(b)&ADMIN_IMMUNITY){
               console_print(id,"Skipping   ^"%s^"   because  client  has
   immunity",nick)
               continue
           }
           console_print(id,"Kicking ^"%s^"",nick)
           if (is_user_bot(b))
               server_cmd("kick #%d",get_user_userid(b))
           else
               client_cmd(b,"echo  *  You have been dropped because admin
   has left only specified group of clients;disconnect")
           count++
       }
       console_print(id,"Kicked %d clients",count)
       new authid[16],name[32]
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       log_to_file(logfilename,"Kick:  ^"%s<%d><%s><>^"  leave some group
   (tag1 ^"%s^") (tag2 ^"%s^") (tag3 ^"%s^") (tag4 ^"%s^")",
           name,get_user_userid(id),authid,ltags[0],ltags[1],ltags[2],lta
   gs[3] )

       switch(get_cvar_num("amx_show_activity"))    {
           case 2:    client_print(0,print_chat,"ADMIN %s: leave %s %s %s
   %s",name,ltags[0],ltags[1],ltags[2],ltags[3])
           case  1:    client_print(0,print_chat,"ADMIN:  leave  %s %s %s
   %s",ltags[0],ltags[1],ltags[2],ltags[3])
       }

       return PLUGIN_HANDLED
   }
   public admin_t(id, level, cid) {
      if (!cmd_access(id, level, cid, 2))
         return PLUGIN_HANDLED
      new cmd[32], arg[32], name[32], pname[32]
      read_argv(0,cmd,31)
      read_argv(1,arg,31)
      get_user_name(id,name,31)
      new player = cmd_target(id,arg,1)
      get_user_name(player,pname,32)
      if (!player) return PLUGIN_HANDLED
      engclient_cmd(player,"chooseteam")
      engclient_cmd(player, "menuselect","1")
      client_cmd(player, "slot2")
      switch(get_cvar_num("amx_show_activity"))    {
      case  2:  client_print(0,print_chat,"ADMIN  %s:  swapped  %s to the
   TERRORIST team",name,pname)
      case   1:   client_print(0,print_chat,"ADMIN:  swapped  %s  to  the
   TERRORIST team",pname)
       }
      return PLUGIN_HANDLED
   }
   public admin_ct(id, level, cid) {
      if (!cmd_access(id, level, cid, 2))
         return PLUGIN_HANDLED
      new cmd[32], arg[32], name[32], pname[32]
      read_argv(0,cmd,31)
      read_argv(1,arg,31)
      get_user_name(id,name,31)
      new player = cmd_target(id,arg,1)
      get_user_name(player,pname,32)
      if (!player) return PLUGIN_HANDLED
      engclient_cmd(player,"chooseteam")
      engclient_cmd(player, "menuselect","2")
      client_cmd(player, "slot3")
      switch(get_cvar_num("amx_show_activity"))    {
      case  2:  client_print(0,print_chat,"ADMIN  %s:  swapped  %s to the
   COUNTER TERRORIST team",name,pname)
      case 1: client_print(0,print_chat,"ADMIN: swapped %s to the COUNTER
   TERRORIST team",pname)
       }
      return PLUGIN_HANDLED
   }
   public plugin_init(){
       register_plugin("Admin Commands","0.9.4","default")
       register_concmd("amx_kick","admin_kick",ADMIN_KICK,"<authid,  nick
   or #userid> [reason]")
       register_concmd("amx_ban","admin_ban",ADMIN_BAN,"<minutes>
   <authid, nick or #userid> [reason]")
       register_concmd("amx_t",  "admin_t", ADMIN_LEVEL_A, "<authid, nick
   or #userid>")
       register_concmd("amx_ct",   "admin_ct",  ADMIN_LEVEL_A,  "<authid,
   nick or #userid>")
       register_concmd("amx_unban","admin_unban",ADMIN_BAN,"<authid    or
   ip>")
       register_concmd("amx_slay","admin_slay",ADMIN_SLAY,"<authid,  nick
   or #userid>")
       register_concmd("amx_slap","admin_slap",ADMIN_SLAY,"<authid,  nick
   or #userid> [power]")
       register_concmd("amx_leave","admin_leave",ADMIN_KICK,"<tag>  [tag]
   [tag] [tag]")
       register_clcmd("amx_map","admin_map",ADMIN_MAP,"<mapname>   [delay
   in sec.]")
       register_clcmd("amx_cvar","admin_cvar",ADMIN_CVAR,"<cvar>
   <value>")
       register_concmd("amx_pause","admin_pause",ADMIN_CVAR,"-  pause  or
   unpause the game")
       register_clcmd("pause_loopback","pause_success")
       register_clcmd("amx_cfg","admin_cfg",ADMIN_CFG,"<fliename>")
       register_clcmd("amx_rcon","admin_rcon",ADMIN_RCON,"<command
   line>")
       register_concmd("amx_who","admin_who",0,"-   displays  who  is  on
   server")
       register_cvar("amx_show_activity","2")
       get_time("addons/amx/logs/admin%m%d.log",logfilename,255)
       return PLUGIN_CONTINUE
   }
