
   /*
   * Keypad Login
   * Idea by ReMuZe
   * Code by OLO
   *Place codes.ini in addons/amx folder
   * The lines should have format: code access
   * For example:
   * ; Example codes file
   * 12345 abcdefg
   * 54745 fgh
   */
   #include <amxmod>
   new g_codePos[33]
   new g_codeEntered[33][8]
   new g_codeFile[] = "addons/amx/codes.ini"
   new g_blankCode[] = "xxxxx"
   // Uncomment if you don't want to print to a screen entered digits
   //#define HIDEENTEREDCODE
   public plugin_init() {
     register_plugin("Keypad Login","1.0","ReMuZe")
     register_cvar("mp_keypad","1")
     register_menucmd(register_menuid("Enter code:"), 1023, "actionKey")
     register_menucmd(register_menuid("Reset      or      Exit?"),     3,
   "actionClose")
     register_clcmd("amx_keypad","cmdKeyPad")
     return PLUGIN_CONTINUE
   }
   public cmdKeyPad( id ) {
     if ( get_cvar_num("mp_keypad") == 0 )  {
        client_print(id  , print_chat, "KL: Logging from keypad disabled"
   )
        return PLUGIN_HANDLED
     }
     g_codePos[ id ] = 0
     g_codeEntered[ id ][ 0 ] = 0
     displayKey( id )
     client_print(id , print_chat, "KL: Please enter a 5 digit code" )
     return PLUGIN_HANDLED
   }
   displayKey( id ) {
   #if defined HIDEENTEREDCODE
     show_menu( id , 1023 , "\yEnter
   code:^n^n\w1   2   3^n4   5   6^n7   8   9^n^n0. Reset/Exit" )
   #else
     new menuBody[256]
     format(menuBody,255, "\yEnter
   code:^n\r%s%s^n^n\w1   2   3^n4   5   6^n7   8   9^n^n0. Reset/Exit",
       g_codeEntered[ id ] , g_blankCode[ g_codePos[ id ] ] )
     show_menu( id , 1023 , menuBody )
   #endif
   }
   public actionClose(id,key) {
     if ( !key ) cmdKeyPad( id )
     return PLUGIN_HANDLED
   }
   public actionKey(id,key){
     if ( key == 9 )
       show_menu( id , 3, "\yReset or Exit?\w^n^n1. Reset^n2. Exit" )
     else  {
       g_codeEntered[ id ][ g_codePos[ id ]++  ] = '0' + 1 + key
       g_codeEntered[ id ][ g_codePos[ id ] ] = 0
       if ( g_codePos[ id ] < 5 )
         displayKey( id )
       else   {
         new sFlags[32], iFlags
         if   (  (iFlags   =  authCode(  sFlags,  31,  g_codeEntered[  id
   ]  ))  )  {
           set_user_flags( id, iFlags )
           client_print(id , print_chat, "KL: You have been given access:
   %s" , sFlags )
           //set_hudmessage(255,  100,  0,  -1.0,  0.3, 0, 2.0, 5.0, 0.4,
   0.4, 4)
           //show_hudmessage(id,"KL:  You  have  been  given access: %s",
   sFlags )
         }
         else
           client_print(id , print_chat, "KL: Invalid code" )
       }
     }
     return PLUGIN_HANDLED
   }
   authCode( flags[], iflags, code[] ) {
     if ( !file_exists( g_codeFile ) ) {
       server_print( "KL: File %s with codes not found!" , g_codeFile  )
       return 0
     }
     new sCode[8], sLine[256], iLen, iLine = 0
     while(  read_file( g_codeFile ,iLine++, sLine ,255 ,iLen ) )  {
       parse( sLine, sCode, 7,  flags, iflags )
       if ( sCode[ 0 ]!=';' && equal( sCode, code ) ) // if not a comment
   and code match
         return read_flags( flags )
     }
     return 0 // code not on list
   }
