
   /*********************************************************************
   **
   * sqlcommands        version 1.0        November 3/2003
   * By Tom L'Ecluse    alias: RpR / Starscream    RpR@fragfun.be
   *
   *  This  is  just a plugin which will write all the commands in an sql
   database.
   *  And  with  the php file you can open all the specified commands for
   that player.
   * I've created this plugin by using most of the code from
   * http://amxmod.net/forums/viewtopic.php?t=18902&highlight=list
   * I just created the SQL version and the php file.
   *  And  I  need  to  say  a  big thx to kaksie because of his detailed
   comments
   * I finally got a grip of the amx programming :)
   * Ingame use say /commands to open a motd with the commands in it
   **********************************************************************
   ***/
   #include <amxmod>
   #include <amxmisc>
   #include <mysql>
   new mhost[64]
   new muser[32]
   new mpass[32]
   new mdb[32]
   new mysql = 0
   public sql_init(){
       //Get server and database info...
       get_cvar_string("amx_sqlban_host",mhost,63)
       get_cvar_string("amx_sqlban_user",muser,31)
       get_cvar_string("amx_sqlban_pass",mpass,31)
       get_cvar_string("amx_sqlban_db",mdb,31)
       new merror[64]
       mysql = mysql_connect(mhost,muser,mpass,mdb,merror,63)
       if(mysql < 1)
           server_print("[AMX][SQLCOMMANDS]   MySQL   error:   could  not
   connect : '%s'",merror)
       else
           server_print("[AMX][SQLCOMMANDS] Successfully connected to the
   database.")
       return PLUGIN_CONTINUE
   }
   public writeinfo(){
       sql_init()
       new query[256]
       format(query,255,"DELETE FROM `amx_commands`")
       //Execute the querry
       mysql_query(mysql,query)
       new merror[64]
       mysql_error(mysql,merror,63)

       //If an error uccures
       if (merror[0]){
           server_print("[AMX][SQLBAN] MYSQL error: %s",merror)
           return PLUGIN_HANDLED
       }

       new oldcmd[32],sflags[32],info[128],cmd[32]
       new flags,eflags
       flags = read_flags("abcdefghijklmnopqrstuvwxyz")
       new id = -1

       new clcmdsnum = get_concmdsnum(flags,id)
       get_flags(flags,sflags,31)
       for (new i = 0; i < clcmdsnum; i++){
           get_concmd(i,cmd,31,eflags,info,127,flags,id)
           server_print("[AMX]  Writing  commands  to sql. Progress: %d /
   %d",i+1,clcmdsnum)
           get_flags(eflags,sflags,31)
           if(!equal(oldcmd,cmd))
           {
               format(query,255,"INSERT         into         amx_commands
   (commands,description,flags) values ('%s','%s','%s')",cmd,info,sflags)

               //Execute the querry
               mysql_query(mysql,query)
               mysql_error(mysql,merror,63)

               //If an error uccures
               if (merror[0]){
                   server_print("[AMX][SQLBAN] MYSQL error: %s",merror)
                   return PLUGIN_HANDLED
               }
           }
           copy(oldcmd,31,cmd)
       }
       return PLUGIN_CONTINUE
   }
   public show_commands(id){
       new url[128]
       new myflags,stringofflags[32]
       myflags=get_user_flags(id)
       get_flags(myflags,stringofflags,31)
       format(url, 127,
   "http://www.fragfun.be/publicserver/commands.php?flags=%s",stringoffla
   gs)
       show_motd(id,url,"Commands")
       return PLUGIN_CONTINUE
   }
   public plugin_init() {
      register_plugin("SQL commands","1.0","Starscream")
      register_cvar("amx_sqlban_host","")
      register_cvar("amx_sqlban_user","")
      register_cvar("amx_sqlban_pass","")
      register_cvar("amx_sqlban_db","")
      register_clcmd("say  /commands",  "show_commands",0,"- displays the
   commands")
      set_task(5.0,"writeinfo",0)
      return PLUGIN_CONTINUE
   }
