
   /* AMX Mod script.
   *
   * (c) Copyright 2002-2003, OLO
   * This file is provided as is (no warranties).
   *
   */
   #include <amxmod>
   #include <amxmisc>
   /*  Admin commads:
   *  amx_off - pause plugins not listed in dpause_list
   *  amx_on - enable all plugins not listed in dpause_list
   *  amx_pausemenu  -  displays menu by which you can pause, unpause and
   stop plugins
   *
   *
   *  Server command:
   *  amx_dpause  <plugin  title>  - add plugin which won't be in list to
   pause
   *
   *  NOTE:  Stoped plugins won't work properly after activation (without
   mapchange) due
   *  to  unactive  status  during  plugins initialization and at players
   connections.
   *  For proper activation clear the file with stoped plugins (option #7
   in menu)
   *  then change the map.
   */
   #define MAX_PLGDATA 64
   #define MAX_PLUGINS 192
   enum {
       PLG_ERROR,
       PLG_ON,
       PLG_OFF,
       PLG_STOPED
   }
   new dplist[MAX_PLGDATA][32]
   new dplist_num
   new menu_position[33]
   new dnpause[MAX_PLGDATA]
   new dnpause_num
   new pstatus[MAX_PLUGINS]
   new bool:modified
   new filetosave[] = "addons/amx/ppause.ini"
   new bool:cstrike_running
   public plugin_init(){
       register_plugin("Pause Plugins","0.9.3","default")

       register_concmd("amx_off","pause_all",ADMIN_CFG,"-    pause   some
   plugins")
       register_concmd("amx_on","unpause_all",ADMIN_CFG,"-  unpause  some
   plugins")
       register_concmd("amx_ppause","admin_pause",ADMIN_CFG,"- list cmds.
   for pause/unpause managment")
       register_clcmd("amx_pausemenu","show_pausemenu",ADMIN_CFG,"- pause
   or unpause plugins via menu")
       register_menucmd(register_menuid("Pause/Unpause
   Plugins"),1023,"action_pausemenu")

       /*  Put here titles of plugins which you don't want to pause. */
       server_cmd("amx_dpause ^"Pause Plugins^"")
       server_cmd("amx_dpause ^"Admin Commands^"")
       server_cmd("amx_dpause ^"TimeLeft^"")
       server_cmd("amx_dpause ^"Slots Reservation^"")
       server_cmd("amx_dpause ^"Admin Chat^"")
       server_cmd("amx_dpause ^"NextMap^"")
       server_cmd("amx_dpause ^"Admin Menu^"")
       server_cmd("amx_dpause ^"Admin Help^"")
       server_cmd("amx_dpause ^"Admin Base^"")
       server_cmd("amx_dpause ^"Welcome Message^"")
       server_cmd("amx_dpause ^"Stats Settings^"")

       new mod_name[32]
       get_modname(mod_name,31)
       cstrike_running   =   equal(mod_name,"cstrike")  ?  true  :  false

       return PLUGIN_CONTINUE
   }
   public plugin_precache(){
       register_srvcmd("amx_dpause","adddontpause")
       load_settings(filetosave)
       return PLUGIN_CONTINUE
   }
   public action_pausemenu(id,key){
       switch(key){
       case 6:{
               if (file_exists(filetosave)){
                   delete_file(filetosave)
                   client_print(id,print_chat,"*    Configuration    file
   cleared")
               }
               else
                   client_print(id,print_chat,"*     Configuration    was
   already cleared!")
               display_menu(id,menu_position[id])
       }
       case 7:{
               if (save_settings(filetosave)){
                   modified = false
                   client_print(id,print_chat,"*    Configuration   saved
   successfully")
               }
               else
                   client_print(id,print_chat,"*   Configuration   saving
   failed!!!")
               display_menu(id,menu_position[id])
           }
       case 8: display_menu(id,++menu_position[id])
       case 9:    display_menu(id,--menu_position[id])
       default:{
               new option = menu_position[id] * 6 + key
               new filename[32],title[32],version[2],author[2],status[2]
               get_plugin(option,filename,31,title,31,version,0,author,0,
   status,1)
               if (status[0]=='r'){
                   pause("ac",filename)
                   pstatus[option]=PLG_OFF
               }
               else      if      (     pstatus[option]!=PLG_STOPED     &&
   status[0]=='p'  ){
                   pstatus[option]=PLG_STOPED
                   modified = true
               }
               else {
                   unpause("ac",filename)
                   pstatus[option]=PLG_ON
               }
               display_menu(id,menu_position[id])
           }
       }
       return PLUGIN_HANDLED
   }
   display_menu(id, pos){
       if (pos < 0) return
       new filename[32],title[32],version[2],author[2],status[2]
       new datanum = get_pluginsnum()
       new menu_body[512], start = pos * 6
       if (start >= datanum) start = pos = menu_position[id] = 0
       new    len = format(menu_body,511,
       cstrike_running   ?   "\yPause/Unpause   Plugins\R%d/%d^n\w^n"   :
   "Pause/Unpause Plugins %d/%d^n^n" ,
               pos + 1,((datanum/6)+((datanum%6)?1:0)))
       new end = start + 6, keys = (1<<9)|(1<<7)|(1<<6)
       if (end > datanum) end = datanum
       pos = 0
       for(new a = start; a < end; ++a){
           get_plugin(a,filename,31,title,31,version,0,author,0,status,1)
           if (dontpause(a)||(status[0]!='r'&&status[0]!='p'))    {
               if (cstrike_running){
                   len     +=    format(menu_body[len],511-len,    "\d%d.
   %s\R%s^n\w",++pos,
                       title,   (   status[0]=='r'   )   ?  "ON"  :  (  (
   status[0]=='p' ) ? "OFF" : "ERROR" ) )
               }
               else{
                   ++pos
                   len += format(menu_body[len],511-len, "#. %s %s^n",
                       title,   (   status[0]=='r'   )   ?  "ON"  :  (  (
   status[0]=='p' ) ? "OFF" : "ERROR" ) )
               }
           }
           else{
               keys |= (1<<pos)
               len   +=  format(menu_body[len],511-len,cstrike_running  ?
   "%d. %s\y\R%s^n\w" : "%d. %s %s^n",++pos,
                   title,     (     status[0]=='r'    )    ?    "ON"    :
   ((pstatus[a]==PLG_STOPED)?"STOPED":"OFF"))
           }
       }
       len   +=   format(menu_body[len],511-len,"^n7.   Clear  file  with
   stoped^n")
       len  +=  format(menu_body[len],511-len,cstrike_running  ? "8. Save
   stoped \y\R%s^n\w"
           : "8. Save stoped %s^n" ,modified ? "*" : "")
       if (end != datanum){
           len += format(menu_body[len],511-len,"^n9. More...^n0. Back")
           keys |= (1<<8)
       }
       else {
           len += format(menu_body[len],511-len,"^n0. Back")
       }
       show_menu(id,keys,menu_body)
   }
   public show_pausemenu(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       if (dnpause_num != dplist_num) check_status()
       display_menu(id,menu_position[id] = 0)
       return PLUGIN_HANDLED
   }
   public adddontpause(){
       if (dplist_num>=MAX_PLGDATA || read_argc()<2)
           return PLUGIN_HANDLED
       new title[32]
       read_argv(1,title,31)
       copy(dplist[dplist_num++],31,title)
       return PLUGIN_HANDLED
   }
   pausecmd_all(id){
       if (dnpause_num != dplist_num) check_status()
       new filename[32],title[32],version[2],author[2],status[2]
       new count = 0, imax = get_pluginsnum()
       for (new a=0;a<imax;++a){
           get_plugin(a,filename,31,title,31,version,0,author,0,status,1)
           if (dontpause(a)||status[0]!='r') continue
           pause("ac",filename)
           ++count
           console_print(id,"Pausing %s (file ^"%s^")",title,filename)
       }
       console_print(id,"Paused %d plugins",count)
   }
   public pause_all(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       pausecmd_all(id)
       return PLUGIN_HANDLED
   }
   unpausecmd_all(id){
       if (dnpause_num != dplist_num) check_status()
       new filename[32],title[32],version[2],author[2],status[2]
       new count = 0, imax = get_pluginsnum()
       for (new a=0;a<imax;++a){
           get_plugin(a,filename,31,title,31,version,0,author,0,status,1)
           if (dontpause(a)||status[0]!='p') continue
           unpause("ac",filename)
           ++count
           console_print(id,"Unpausing %s (file ^"%s^")",title,filename)
       }
       console_print(id,"Unpaused %d plugins",count)
   }
   public unpause_all(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       unpausecmd_all(id)
       return PLUGIN_HANDLED
   }
   find_plugin(argument[32],&len){
       new plugin[32],title[32],version[2],author[2],status[2]
       new inum  = get_pluginsnum()
       for(new a = 0; a < inum; ++a){
           get_plugin(a,plugin,31,title,31,version,0,author,0,status,1)
           if ( equali(plugin,argument,len) &&
   (status[0]=='r'||status[0]=='p') ){
               len = copy(argument,31,plugin)
               return a
           }
       }
       return -1
   }
   public admin_pause(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       new cmds[32]
       read_argv(1,cmds,31)
       if ( equal(cmds, "off" ) ){
           pausecmd_all(id)
       }
       else if ( equal(cmds, "on" ) ){
           unpausecmd_all(id)
       }
       else if ( equal(cmds, "save" ) ){
           if (save_settings(filetosave)){
               modified = false
               console_print(id,"Configuration saved successfully")
           }
           else
               console_print(id,"Configuration saving failed!!!")
       }
       else if ( equal(cmds, "clear" ) )    {
           if (file_exists(filetosave)){
               delete_file(filetosave)
               console_print(id,"Configuration file cleared")
           }
           else
               console_print(id,"Configuration was already cleared!")
       }
       else if ( equal(cmds, "pause" )  )    {
           new arg[32], len, a
           if (  (len = read_argv(2,arg,31)) != 0 ){
               if ( (a = find_plugin(arg,len)) != -1){
                   if (pause("ac",arg)) pstatus[a] = PLG_OFF
                   console_print(id,"Plugin matching ^"%s^" paused",arg)
               }
           }
           if  (!len  || a==-1)    console_print(id,"Couldn't find plugin
   matching ^"%s^"",arg)
       }
       else if ( equal(cmds, "unpause" )  ) {
           new arg[32], len, a
           if (  (len = read_argv(2,arg,31)) != 0 ){
               if ( (a = find_plugin(arg,len)) != -1){
                   if (unpause("ac",arg)) pstatus[a] = PLG_ON
                   console_print(id,"Plugin        matching        ^"%s^"
   unpaused",arg)
               }
           }
           if  (!len  || a==-1)    console_print(id,"Couldn't find plugin
   matching ^"%s^"",arg)
       }
       else if ( equal(cmds, "stop" )  ) {
           new arg[32], len, a
           if (  (len = read_argv(2,arg,31)) != 0 ){
               if ( (a = find_plugin(arg,len)) != -1){
                   pause("ac",arg)
                   pstatus[a] = PLG_STOPED
                   modified = true
                   console_print(id,"Plugin matching ^"%s^" stoped",arg)
               }
           }
           if  (!len  || a==-1)    console_print(id,"Couldn't find plugin
   matching ^"%s^"",arg)
       }
       else if ( equal(cmds, "list" )  ) {
           new plugin[32],title[32],version[16],author[32],status[16]
           new inum  = get_pluginsnum()
           console_print(id, "Currently loaded plugins:")
           console_print(id,
   "      name               version  author             file
    status")
           new running = 0, plugins = 0
           for(new a = 0; a < inum; ++a){
               plugins++
               get_plugin(a,plugin,31,title,31,version,15,author,31,statu
   s,15)
               if (status[0] == 'r') running++
               console_print(id,   "   [%2d]   %-18.17s  %-8.7s  %-18.17s
   %-16.15s %-9.8s",plugins,
                   title,version,author,plugin,       (pstatus[a]      ==
   PLG_STOPED) ? "stoped" : status )
           }
           console_print(id, "%d plugins, %d running",plugins,running)
       }
       else {
           console_print(id,"Usage:  amx_ppause <command> [parameter]")
           console_print(id,"Commands:")
           console_print(id,"   off                 -  pause  all plugins
   (except put in list)")
           console_print(id,"   on                  -     unpause     all
   plugins")
           console_print(id,"   stop <filename>     - stop plugin")
           console_print(id,"   pause <filename>    - pause plugin")
           console_print(id,"   unpause <filename>  - unpause plugin")
           console_print(id,"   save                - save list of stoped
   plugins")
           console_print(id,"   clear               -   clear   list   of
   stoped plugins")
           console_print(id,"   list                - list plugins")
       }
       return PLUGIN_HANDLED
   }

   check_status(){
       new filename[32],title[32],version[2],author[2],status[2]
       new imax = get_pluginsnum()
       for (new a=0;a<imax;++a){
           get_plugin(a,filename,31,title,31,version,0,author,0,status,1)
           if (status[0]=='p'){
               if (pstatus[a]!=PLG_STOPED)    pstatus[a] = PLG_OFF
           }
           else if (status[0]=='r')
               pstatus[a] = PLG_ON
           else
               pstatus[a] = PLG_ERROR
           if (dontpause_pre(title))
               dnpause[dnpause_num++] = a
       }
   }
   bool:dontpause(myid) {
       for(new a=0;a<dnpause_num;++a)
           if (dnpause[a]==myid)
               return true
       return false
   }
   bool:dontpause_pre(name[]) {
       for(new a=0;a<dplist_num;++a)
           if (equali(dplist[a],name))
               return true
       return false
   }
   save_settings(filename[]){
       if (file_exists(filename))
           delete_file(filename)
       new text[256], plugin[32],title[32],version[2],author[2],status[2]
       new inum  = get_pluginsnum()
       if  (!write_file(filename,";Generated  by Pause Plugins Plugin. Do
   not modify!^n;Filename Description"))
           return 0
       for(new a = 0; a < inum; ++a){
           if (pstatus[a]==PLG_STOPED){
               get_plugin(a,plugin,31,title,31,version,0,author,0,status,
   1)
               format(text,255,"%s ;%s",plugin,title)
               write_file(filename,text)
           }
       }
       return 1
   }
   load_settings(filename[]){
       if (!file_exists(filename)) return 0
       new text[256], len, pos = 0
       while (read_file(filename,pos++,text,255,len)){
           if ( text[0] == ';' ) continue // line is a comment
           parse(text,dplist[dplist_num++],31)
       }
       new plugin[32],title[32],version[2],author[2],status[2]
       new inum  = get_pluginsnum()
       for(new a = 0; a < inum; ++a){
           get_plugin(a,plugin,31,title,31,version,0,author,0,status,1)
           if (!dontpause_pre(plugin)) continue
           pause("ac",plugin)
           pstatus[a] = PLG_STOPED
       }
       dplist_num = 0
       return 1
   }
