Rejack

AMXX Admins Manager v0.3b by Rejack

Mar 19th, 2013 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.23 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < amxmisc >
  3.  
  4. #define MAX_ACCESS 5
  5. #define OWNER_ACCESS ADMIN_IMMUNITY
  6. #define STR_LEN 64
  7.  
  8. new const g_Access[ MAX_ACCESS ][] =
  9. {
  10.     "Owner",
  11.     "Manager",
  12.     "Super-Admin",
  13.     "Admin",
  14.     "VIP"
  15. };
  16.  
  17. new const g_AccessFlags[ MAX_ACCESS ][] =
  18. {
  19.     "abcdefghijklmnopqrstu",
  20.     "bcdefijmnopqrstu",
  21.     "cdefijmnopqrst",
  22.     "cefijmnopqrst",
  23.     "eij"
  24. };
  25.  
  26. new const g_AccessMainFlag[ MAX_ACCESS ] =
  27. {
  28.     ADMIN_IMMUNITY, ADMIN_RESERVATION, ADMIN_BAN, ADMIN_KICK, ADMIN_SLAY
  29. };
  30.  
  31. new const g_AccessType[ 2 ][ ] =
  32. {
  33.     "Steam ID", "IP Address"
  34. };
  35.  
  36. new const g_AccessTypeID[ 2 ][ ] = { "steamid", "ip" };
  37.  
  38. new g_Variable[ 33 ], g_AccessID[ 33 ];
  39.  
  40. new gConfigsDir[STR_LEN];
  41. new gAdminsFile[STR_LEN];
  42.  
  43. public plugin_init()
  44. {
  45.     register_plugin( "Access Menu", "v0.3b", "Rejack" );
  46.    
  47.     register_clcmd( "say /access", "CmdAccess" );
  48.     register_clcmd( "say /manage", "CmdAccess" );
  49.    
  50.     get_configsdir(gConfigsDir, sizeof gConfigsDir - 1);
  51.     formatex(gAdminsFile, sizeof gAdminsFile - 1, "%s/users.ini", gConfigsDir);
  52.    
  53.     if(!file_exists(gAdminsFile))
  54.         set_fail_state("Non-existent file.");
  55. }
  56.  
  57. public CmdAccess( client )
  58. {
  59.     if ( !( get_user_flags( client ) & ADMIN_IMMUNITY ) )
  60.         return ColorPrint( client, "You have no access to this command." );
  61.        
  62.     new Menu = menu_create( "Add Admins Menu", "SubAccess" );
  63.    
  64.     menu_additem( Menu, "Add Admins", "0" );
  65.     menu_additem( Menu, "Remove Admins", "1" );
  66.    
  67.     return menu_display( client, Menu );
  68. }
  69.  
  70. public SubAccess( client, Menu, Item )
  71. {
  72.     if ( Item == MENU_EXIT )    return menu_destroy( Menu );
  73.    
  74.     if ( Item == 0 )    return CmdAdd( client );
  75.    
  76.     return CmdRemove( client );
  77. }
  78.  
  79. public CmdAdd( client )
  80. {
  81.     if ( !( get_user_flags( client ) & ADMIN_IMMUNITY ) )
  82.         return ColorPrint( client, "You have no access to this command." );
  83.        
  84.     new Menu = menu_create( "Add Admins Menu", "SubAdd" );
  85.    
  86.     new szItem[ 128 ];
  87.     formatex( szItem, charsmax( szItem ), "\yAdd a:\r %s",  g_Access[ g_Variable[ client ] ] );
  88.     menu_additem( Menu, szItem, "0" );
  89.    
  90.     formatex( szItem, charsmax( szItem ), "\yAccess Type:\r %s",  g_AccessType[ g_AccessID[ client ] ] );
  91.     menu_additem( Menu, szItem, "1" );
  92.    
  93.     menu_additem( Menu, "Choose a player!", "2" );
  94.    
  95.     return menu_display( client, Menu );
  96. }
  97.  
  98. public SubAdd( client, Menu, Item )
  99. {
  100.     if ( Item == MENU_EXIT )    return menu_destroy( Menu );
  101.    
  102.     switch ( Item )
  103.     {
  104.         case 0:
  105.         {
  106.             if ( g_Variable[ client ] == MAX_ACCESS - 1 )
  107.             {
  108.                 g_Variable[ client ] = 0;
  109.                
  110.                 return CmdAdd( client );
  111.             }
  112.            
  113.             g_Variable[ client ] += 1;
  114.         }
  115.         case 1:
  116.         {
  117.             if ( g_AccessID[ client ] == 1 )
  118.             {
  119.                 g_AccessID[ client ] = 0;
  120.                
  121.                 return CmdAdd( client );
  122.             }
  123.            
  124.             g_AccessID[ client ] += 1;
  125.         }
  126.         case 2: return CmdPlayers( client );
  127.     }
  128.    
  129.     CmdAdd( client );
  130.        
  131.     return menu_destroy( Menu );
  132. }
  133.  
  134. public CmdPlayers( client )
  135. {
  136.     new szItem[ 128 ];
  137.     formatex( szItem, charsmax( szItem ), "Add a\r %s\y Account!", g_Access[ g_Variable[ client ] ] );
  138.     new Menu = menu_create( szItem, "SubPlayers" );
  139.    
  140.     new Players[ 32 ], PNum, szTempid[ 10 ];
  141.     static szName[ 32 ];
  142.    
  143.     get_players( Players, PNum, "ch" );
  144.    
  145.     for ( new i; i<PNum; i++ )
  146.     {
  147.         new iPlayer = Players[ i ];
  148.        
  149.         get_user_name( iPlayer, szName, charsmax( szName ) );
  150.        
  151.         num_to_str( iPlayer, szTempid, charsmax( szTempid ) );
  152.        
  153.         if ( get_user_flags( iPlayer ) & g_AccessMainFlag[ g_Variable[ client ] ] ) continue;
  154.        
  155.         menu_additem( Menu, szName, szTempid );
  156.     }
  157.     return menu_display( client, Menu );   
  158. }
  159.  
  160. public SubPlayers( client, Menu, Item )
  161. {
  162.     if ( Item == MENU_EXIT )    return menu_destroy( Menu );
  163.    
  164.     new Data[ 6 ], Name[ 64 ], Access, Callback;
  165.    
  166.     menu_item_getinfo( Menu, Item, Access, Data, charsmax( Data ), Name, charsmax( Name ), Callback );
  167.    
  168.     new iPlayer = str_to_num( Data );
  169.    
  170.     static szName[ 32 ];get_user_name( client, szName, charsmax( szName ) );
  171.     static szName2[ 32 ];get_user_name( iPlayer, szName2, charsmax( szName2 ) );
  172.     static szAuth[ 32 ]
  173.    
  174.     switch ( g_AccessID[ client ] )
  175.     {
  176.         case 0: get_user_authid( iPlayer, szAuth, charsmax( szAuth ) );
  177.        
  178.         case 1: get_user_ip( iPlayer, szAuth, charsmax( szAuth ) );
  179.     }
  180.  
  181.     server_cmd( "amx_addadmin ^"%s^" ^"%s^" ^"^" ^"%s^"", szAuth, g_AccessFlags[ g_Variable[ client ] ], g_AccessTypeID[ g_AccessID[ client ] ] );
  182.     server_cmd( "amx_reloadadmins" );
  183.    
  184.     ColorPrint( client, "You gave a^4 %s Access^3 to^4 %s", g_Access[ g_Variable[ client ] ], szName2 );
  185.     ColorPrint( iPlayer, "^3Owner:^4 %s^3 gave you an^4 %s Access^3.", szName, g_Access[ g_Variable[ client ] ] );
  186.    
  187.     return menu_destroy( Menu );
  188. }
  189.  
  190. public CmdRemove(id)
  191. {
  192.     static iMenu;
  193.     iMenu = menu_create("Remove Admins Menu", "SubRemove");
  194.    
  195.     static sBuffer[128], sTempItem[128];
  196.     static sTemp[5][STR_LEN];
  197.    
  198.     static iFileP;
  199.     iFileP = fopen(gAdminsFile, "rt");
  200.    
  201.     while(!feof(iFileP))
  202.     {
  203.         fgets(iFileP, sBuffer, sizeof sBuffer - 1);
  204.        
  205.         if((strlen(sBuffer) < 3) || sBuffer[0] == ';')
  206.             continue;
  207.        
  208.         parse(sBuffer, sTemp[0], sizeof sTemp[] - 1, sTemp[1], sizeof sTemp[] - 1, sTemp[2], sizeof sTemp[] - 1, sTemp[3], sizeof sTemp[] - 1, sTemp[4] ,sizeof sTemp[] - 1 );
  209.        
  210.         for(new j = 0 ; j < sizeof sTemp ; j++)
  211.         {
  212.             remove_quotes(sTemp[j]);
  213.         }
  214.        
  215.         formatex(sTempItem, sizeof sTempItem - 1, "\w %s \r|\w %s \r|\w %s \r|\w %s \r", sTemp[0], sTemp[1], sTemp[2], sTemp[3], sTemp[4]);
  216.        
  217.         menu_additem(iMenu, sTempItem, "", 0, -1);
  218.     }
  219.     fclose(iFileP);
  220.    
  221.     menu_addblank(iMenu, 0);
  222.     menu_display(id, iMenu, 0);
  223.    
  224.     return PLUGIN_HANDLED;
  225. }
  226.  
  227. public SubRemove( client, Menu, Item )
  228. {
  229.     if ( Item == MENU_EXIT )
  230.     {
  231.         CmdAccess( client );
  232.        
  233.         return menu_destroy( Menu );
  234.     }
  235.    
  236.     static iAccess, iCallback;
  237.     static sBuffer[128], sTemp[STR_LEN];
  238.     menu_item_getinfo( Menu, Item, iAccess, "", 0, sBuffer, sizeof sBuffer - 1, iCallback );
  239.    
  240.     strtok(sBuffer, sTemp, sizeof sTemp - 1, sBuffer, sizeof sBuffer - 1, '|');
  241.    
  242.     replace(sTemp, sizeof sTemp - 1, "\w", "");
  243.     replace(sTemp, sizeof sTemp - 1, "\r", "");
  244.     trim(sTemp);
  245.    
  246.     static iFileP;
  247.     iFileP = fopen( gAdminsFile, "rt" );
  248.    
  249.     static sTempAccount[STR_LEN];
  250.     new i;
  251.    
  252.     while(!feof(iFileP))
  253.     {
  254.         fgets(iFileP, sBuffer, sizeof sBuffer - 1);
  255.        
  256.         i++;
  257.        
  258.         if((strlen(sBuffer) < 3) || sBuffer[0] == ';')
  259.             continue;
  260.        
  261.         parse(sBuffer, sTempAccount, sizeof sTempAccount - 1);
  262.        
  263.         remove_quotes(sTempAccount);
  264.        
  265.         if(equali(sTempAccount, sTemp))
  266.         {
  267.             format(sBuffer, sizeof sBuffer - 1, ";%s", sBuffer);
  268.             write_file(gAdminsFile, sBuffer, i - 1);
  269.             break;
  270.         }
  271.     }
  272.     fclose( iFileP );
  273.     ColorPrint( client, "You removed^4 %s^1 from the admins list.", sTemp );
  274.     server_cmd( "amx_reloadadmins" );
  275.    
  276.     return 1;
  277. }
  278. stock ColorPrint( const client, const string[], any:... )
  279. {
  280.     new msg[ 191 ], players[ 32 ], count = 1;
  281.    
  282.     static len; len = formatex( msg, charsmax( msg ), "^3[^4 HitAndRun ^3] " );
  283.    
  284.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 );
  285.    
  286.     if( client )  players[ 0 ] = client;
  287.    
  288.     else    get_players( players,count,"ch" );
  289.    
  290.     for ( new i = 0; i < count; i++ )
  291.     {
  292.         if( is_user_connected( players[ i ] ) )
  293.         {
  294.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] );
  295.            
  296.             write_byte( players[ i ] );
  297.            
  298.             write_string( msg );
  299.            
  300.             message_end( );
  301.         }
  302.     }
  303.     return PLUGIN_HANDLED;
  304. }
Advertisement
Add Comment
Please, Sign In to add comment