
   /**
   * AMX plugin for giving player info on misc server things.
   *
   * (C) 2003, toadhunter[NOX]
   *
   * Plugin scans the list of info_*.txt files in the infobot/
   * directory and can dump the file contents as msg to client
   * who requested them.
   *
   * This is useful for storing eg. server rules, output from other
   * programs etc.
   *
   *
   * Example:
   *
   * <your-hl-or-mod-dir>/infobot/:
   *                                files.lst
   *                                info_rules.txt
   *                                info_about.txt
   *                                info_donate.txt
   *
   * client can write in console:
   *  "!ishow rules", and will get the contents of
   *  info_rules.txt on their screen.
   *
   * files.lst should contain the list and description
   * of other files in the dir. Its contents are shown
   * to client when he execs "!ifiles".
   *
   * if files.lst is missing, !ifiles simply shows the
   * names of info_*.txt files, like: rules, about, donate.
   *
   * Supported commands:
   * !ibot - gives info about plugin
   * !ifiles - list of files available
   * !ishow <file> - show file
   *
   */
   #include <amxmod>
   #include <amxmisc>
   #include <core>
   #include <string>
   #include <file>
   // all files must start be in form info_<cmdname>.txt
   new fnPrefix[]="info_"
   // in the directory msgDir
   new msgDir[]="infobot"
   // this is what files will be looked at
   new fnExt[]=".txt"
   // if this file exists in msgDir[], then it will be
   // given to client when requested by !ifiles, instead of
   // simple list of files
   new descFile[]="files.lst"
   // all players can exec this cmd
   #define ADMIN_ALL 0
   // Maximum file name length handled by plugin
   #define MAX_FN_LEN 10
   // max real filename length as in
   strlen(fnPrefix+filename+fnExt+msgDir)
   #define MAX_REAL_FN_LEN 30
   // Up to 5KB messages can be sent to user (files + etc.)
   #define MAX_MSG_LEN 5000
   // maximum length of filenames total...
   #define MAX_FILECOUNT 50
   new gVersion[]="1.02"
   /* Event Handlers */
   public plugin_init() {
     register_plugin("infoBot",gVersion, "toadhunter")
     log_message("[AMX]   infoBot   v%s   loading,   assuming   files  in
   %s/",gVersion,msgDir)
     register_clcmd("!ibot","ibInfo",   ADMIN_ALL,  "Displays  to  client
   server txt files upon request.")
     register_clcmd("!ifiles","ibFiles",  ADMIN_ALL, "Shows list of files
   available for reading.")
     register_clcmd("!ishow",   "ibShowFile",ADMIN_ALL,"Shows  particular
   server info file.")
     return PLUGIN_CONTINUE
   }
   /* When player connects we tell him our commands */
   public plugin_connect(id)
   {
       client_print(id,print_console,"Welcome  to  toadhunter's  infoBot!
   Type:  !ibot  in  console  to  get more information about what you can
   do.")
       return PLUGIN_CONTINUE
   }
   public ibInfo(id)
   {
       show_motd(id,"infoBot available commands:^n !ibot - this message^n
   !ifiles - list of files available^n !ishow <title> - shows appropriate
   file.^n(C) 2003, toadhunter","toadhunter's infoBot")
       return PLUGIN_HANDLED
   }
   public ibFiles(id)
   {
       new UserMessage[MAX_MSG_LEN]
       new fName[MAX_FN_LEN+10]
       new flcount=0
       new iLen
       copy(fName, MAX_REAL_FN_LEN, msgDir)
       add(fName, MAX_REAL_FN_LEN, "/",0)
       add(fName, MAX_REAL_FN_LEN, descFile,0)
       // if desc file exists, use it, instead of simple flist
       if (file_exists(fName))
       {
           show_motd(id,fName,"infoBot - show files")
           return PLUGIN_HANDLED
       }
       copy(UserMessage,MAX_MSG_LEN,"Available files:^n")
       while(read_dir(msgDir,flcount++,fName,MAX_FN_LEN+10,iLen)       &&
   flcount < MAX_FILECOUNT)
       {
           // get rid of extension
           iLen-=4
           if      (iLen>0      &&      equali(fName[iLen],fnExt)      &&
   equali(fName,fnPrefix,strlen(fnPrefix)))
           {
               replace(fName,iLen,fnPrefix,"")
               replace(fName,iLen,fnExt,"")
               // up to the first . we assume that it is the .txt
               add(UserMessage,MAX_MSG_LEN," ",0)
               add(UserMessage,MAX_MSG_LEN,fName,0)
               add(UserMessage,MAX_MSG_LEN,"^n",0)
           }
       }
       show_motd(id,UserMessage,"infoBot - show files")
       return PLUGIN_HANDLED
   }
   // we show the particular file requested.
   ibShowThis(id,file[])
   {
       new fle[MAX_FN_LEN]
       new fName[MAX_REAL_FN_LEN]
       new titleMsg[30]
       copy(fle,MAX_FN_LEN,file)
       if (strlen(file)>0)
       {
           copy(fName, MAX_REAL_FN_LEN, msgDir)
           add(fName, MAX_REAL_FN_LEN, "/",0)
           add(fName, MAX_REAL_FN_LEN, fnPrefix,0)
           add(fName,MAX_REAL_FN_LEN,fle,0)
           add(fName,MAX_REAL_FN_LEN,fnExt,0)
           if (file_exists(fName))
           {
               copy(titleMsg,30,"Infobot: ")
               add(titleMsg,MAX_REAL_FN_LEN,fle,0)
               show_motd(id, fName, titleMsg)
               return PLUGIN_HANDLED
           }
           else
           {
               client_print(id,print_console,"infoBot: No such file.^n")
           }
       }
       else
       {
           client_print(id,print_console,"infoBot: Nothing specified.^n")
       }
       return PLUGIN_CONTINUE
   }
   // this is when player himself requests file
   public ibShowFile(id)
   {
       new arg[MAX_FN_LEN]
       read_argv(1,arg,MAX_FN_LEN)
       return ibShowThis(id,arg)
   }
