
   /*
   *  AMX Mod script.
   *
   * (c) Copyright 2003, ST4life
   * This file is provided as is (no warranties).
   */
   #include <amxmod>
   /*
   *  "RulesAgreement" is a plugin to ask players if they agree with your
   serverrules.
   * If not, they will be kicked, otherwise they can play on server.
   */
   new rulesindexfile[]="addons/amx/ra_rulesindex.txt"
   new rulesfile[]="addons/amx/ra_rules.txt"
   new ruleslog[]="addons/amx/rulesagreement.log"
   /*********************************************************************
   **********
   ** initialize
   plugin                                                          **
   **********************************************************************
   *********/
   public plugin_init(){
      register_plugin("RulesAgreement","0.2","ST4life")
      register_menucmd(register_menuid("ServerRules
   agreement"),1023,"action_ra_menu")
      register_concmd("amx_ra_eraselog","erase_log",ADMIN_LEVEL_A,"-
   erase RulesAgreement Log-File")
      register_cvar("amx_ra_immunitycheck","1")
      register_cvar("amx_ra_agreetime","30")
      return PLUGIN_CONTINUE
   }
   /*********************************************************************
   **********
   **   register   client  put  in  server  and  initiat  menu  after  15
   secs.              **
   **********************************************************************
   *********/
   setTime(id){
      new param[5]
      param[0] = id
      set_task(15.0,"dispMenu",0,param,5)
   }
   public client_putinserver(id){
      new checkauthid=-1
      if(get_cvar_num("amx_ra_immunitycheck")        ==        1       &&
   get_user_flags(id)&ADMIN_IMMUNITY){
         checkauthid=1
      }
      if(checkauthid == -1){
         if(file_exists(ruleslog)){
            new authid[32]
            get_user_authid(id,authid,31)
            new rulesline[128], a, line = 0
            while(read_file(ruleslog,line++,rulesline,128,a)){
               if(equal(authid,rulesline))
                  checkauthid=1
            }
         }
      }
      if(checkauthid == -1)
         setTime(id)
   }
   /*********************************************************************
   **********
   ** show agreement menu with
   rules                                             **
   **********************************************************************
   *********/
   public dispMenu(param[]){
      new id = param[0]
      if(!id){
         return PLUGIN_CONTINUE
      }
      new agreeleft2=param[3]
      if(!agreeleft2)
         agreeleft2 = get_cvar_num("amx_ra_agreetime") + 1
      if(agreeleft2 == 1){
         remove_task(123214+id)
         client_cmd(id,"disconnect")
      }
      new agreeleft3 = agreeleft2 - 1
      if(!file_exists(rulesindexfile)) return 0
      new text[1023]
      new len = format(text,1023,"\yServerRules agreement: ^n^n\w")
      new rulesline[128], a, line = 0
      while(read_file(rulesindexfile,line++,rulesline,128,a)){
         if(rulesline[0] == ';') continue
         len += format(text[len],1023-len,"%s^n",rulesline)
      }
      if(agreeleft3<=10){
         len   +=   format(text[len],1023-len,"^n\y1.\w  I  agree.  (\r%d
   sec.\w)^n\y2.\w View ServerRules^n\y9.\w I don't agree.",agreeleft3)
      }
      else {
         len   +=   format(text[len],1023-len,"^n\y1.\w  I  agree.  (\y%d
   sec.\w)^n\y2.\w View ServerRules^n\y9.\w I don't agree.",agreeleft3)
      }
      show_menu(id,(1<<0)|(1<<1)|(1<<8),text)
      param[0]=id
      param[3]=--agreeleft2
      set_task(1.0,"dispMenu",123214+id,param,5)
      return PLUGIN_CONTINUE
   }
   /*********************************************************************
   **********
   ** show agreement menu after
   motd                                             **
   **********************************************************************
   *********/
   public dispMenu2(param[]){
      new id = param[0]
      if(!id){
         return PLUGIN_CONTINUE
      }
      if(!file_exists(rulesindexfile)) return 0
      new text[1023]
      new len = format(text,1023,"\yServerRules agreement: ^n^n\w")
      new rulesline[128], a, line = 0
      while(read_file(rulesindexfile,line++,rulesline,128,a)){
         if(rulesline[0] == ';') continue
         len += format(text[len],1023-len,"%s^n",rulesline)
      }
      len += format(text[len],1023-len,"^n\y1.\w I agree.^n\y9.\w I don't
   agree.")
      show_menu(id,(1<<8)|(1<<0),text)
      return PLUGIN_CONTINUE
   }
   /*********************************************************************
   **********
   ** running menu
   command                                                       **
   **********************************************************************
   *********/
   public action_ra_menu(id,key) {
      remove_task(123214+id)
      switch(key) {
         case 0: {
            new authid[32]
            get_user_authid(id,authid,31)
            write_file(ruleslog,authid,-1)
         }
         case 1: {
            show_motd(id,rulesfile,"Server Rules")
            new param[2]
            param[0] = id
            set_task(0.1,"dispMenu2",0,param,2)
         }
         case 8: {
            client_cmd(id,"disconnect")
         }
      }
      return PLUGIN_HANDLED
   }
   /*********************************************************************
   **********
   ** running menu
   command                                                       **
   **********************************************************************
   *********/
   public client_disconnect(id) {
      remove_task(123214+id)
      return PLUGIN_CONTINUE
   }
   /*********************************************************************
   **********
   ** erase
   log                                                                  *
   *
   **********************************************************************
   *********/
   public erase_log(id) {
      if(get_user_flags(id)&ADMIN_IMMUNITY){
         if(delete_file(ruleslog)){
            client_print(id,print_chat,"[RulesAgreement] Log deleted!")
         }
         else {
            client_print(id,print_chat,"[RulesAgreement]  Couldn't delete
   Logfile '%s'!",ruleslog)
         }
      }
      else {
         client_print(id,print_chat,"[RulesAgreement]  You have no access
   to use this command!")
      }
      return PLUGIN_CONTINUE
   }
