Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Includes
- #include < amxmodx >
- #include < AdminsManager >
- #include < fvault >
- // Defines
- //define NEED_PASS
- #if defined NEED_PASS
- #define g_mPass "h1z1"
- new bool: bAllowPassword[ 33 ];
- #endif
- #define g_mTaskCheck 5 // 5 minutes
- #define MENU_ACCESS ACCESS_MANAGER
- #define MAX_NICKNAME_CHARS 12
- #define MAX_PASSWORD_CHARS 4
- #define gIndex(%1,%2) g_mIndex[ %1 ][ %2 ]
- enum _: time_data
- {
- time_unit[ 7 ],
- time_max
- };
- new const g_szTimes[ ][ time_data ] =
- {
- { "month", 36 },
- { "week", 52 },
- { "day", 30 },
- { "hour", 24 },
- { "minute", 60 },
- { "second", 60 }
- };
- new szItem[ 128 ];
- new bool: bAllowedPassword[ 33 ];
- enum _: client_data
- {
- g_mPlayer,
- g_mSaving,
- g_mGroup,
- g_mTime,
- g_mTimeData,
- g_mMonth,
- g_mWeek,
- g_mDay,
- g_mHour,
- g_mMinute,
- g_mSecond,
- g_mNoNick,
- g_mNoPassword,
- g_mRemovable
- };
- enum _: client_strings
- {
- g_mNickname[ MAX_NICKNAME_CHARS + 3 ],
- g_mPassword[ MAX_PASSWORD_CHARS + 3 ]
- };
- new szIndex[ 33 ][ client_strings ];
- new g_mIndex[ 33 ][ client_data ];
- new const szAllowedSteamIDs[ ][ ] =
- {
- "steam1",
- "steam2"
- };
- public plugin_init()
- {
- register_plugin( "Jailbreak: Games API", "1.0", "Rejack" );
- register_clcmd( "say /manage", "cmdPreMainMenu" );
- register_concmd( "admin_nick", "cmdAdminNick" );
- register_concmd( "admin_pass", "cmdAdminPass" );
- register_concmd( "admin_time", "cmdAdminTime" );
- /*
- register_concmd( "amx_reloadadmins", "cmdReloadAdmins" );
- register_concmd( "manage_password", "cmdPassword" );
- set_task( g_mTaskCheck * 60.0, "taskCheckAdminTimes" );
- */
- }
- /* --------------------------------------------
- Client Side
- -------------------------------------------- */
- public cmdAdminNick( const client )
- {
- new szArgs[ 16 ];
- read_args( szArgs, charsmax( szArgs ) );
- remove_quotes( szArgs );
- if ( strlen( szArgs ) >= MAX_NICKNAME_CHARS )
- {
- client_cmd( client, "messagemode admin_nick" );
- return ColorPrint( client, "Nickname need to be shorter than^4 %i characters^1." , MAX_NICKNAME_CHARS );
- }
- if ( !is_str_alpha( szArgs ) )
- {
- client_cmd( client, "messagemode admin_nick" );
- return ColorPrint( client, "Nickname need to contain only^3 english letters^1." );
- }
- g_mIndex[ client ][ g_mNoNick ] = 1;
- formatex( szIndex[ client ][ g_mNickname ], ( MAX_NICKNAME_CHARS - 1 ) + 3, szArgs );
- return cmdAddAdminMenu( client );
- }
- public cmdAdminPass( const client )
- {
- new szArgs[ 16 ];
- read_args( szArgs, charsmax( szArgs ) );
- remove_quotes( szArgs );
- if ( is_str_empty( szArgs ) )
- {
- g_mIndex[ client ][ g_mNoPassword ] = 0;
- return cmdAddAdminMenu( client );
- }
- if ( strlen( szArgs ) != MAX_PASSWORD_CHARS )
- {
- client_cmd( client, "messagemode admin_pass" );
- return ColorPrint( client, "Password needs to be a^3 %i numbers^1 PIN code.", MAX_PASSWORD_CHARS );
- }
- if ( !is_str_num( szArgs ) )
- {
- client_cmd( client, "messagemode admin_pass" );
- return ColorPrint( client, "Password can only contain^3 numbers^1." );
- }
- g_mIndex[ client ][ g_mNoPassword ] = 1;
- formatex( szIndex[ client ][ g_mPassword ], ( MAX_PASSWORD_CHARS - 1 ) + 3, szArgs );
- return cmdAddAdminMenu( client );
- }
- public cmdAdminTime( const client )
- {
- new szArgs[ 16 ];
- read_args( szArgs, charsmax( szArgs ) );
- remove_quotes( szArgs );
- if ( !is_str_num( szArgs ) )
- {
- client_cmd( client, "messagemode admin_time" );
- return ColorPrint( client, "You can only use numbers." );
- }
- static iData;
- iData = gIndex( client, g_mTimeData );
- ColorPrint( 0, "%i | %i | %i", str_to_num( szArgs ), iData, g_mMonth );
- if ( str_to_num( szArgs ) > g_szTimes[ iData][ time_max ] )
- {
- client_cmd( client, "messagemode admin_time" );
- return ColorPrint( client, "You can set^3 %ss^1 to a maximum of^4 %i %ss^1.",
- g_szTimes[ iData ][ time_unit ], g_szTimes[ iData ][ time_max ], g_szTimes[ iData ][ time_unit ] );
- }
- g_mIndex[ client ][ iData + g_mMonth ] = str_to_num( szArgs );
- return cmdTimeMenu( client );
- }
- public client_authorized( client )
- {
- bAllowedPassword[ client ] = false;
- }
- public cmdReloadAdmins( const client )
- {
- // If someone was removed or added it closes all opened manage
- return client;
- }
- public cmdPassword( const client )
- {
- bAllowedPassword[ client ] = true;
- return 1;
- }
- /* --------------------------------------------
- Main Menu
- -------------------------------------------- */
- public cmdPreMainMenu( const client ) // A check to see if a client has access to the manager system.
- {
- if ( !is_user_allowed( client ) )
- {
- if ( !bAllowedPassword[ client ] )
- {
- client_cmd( client, "messagemode manage_password" );
- return 1;
- }
- return ColorPrint( client, "You don't have access to this menu." );
- }
- return cmdMainMenu( client );
- }
- public cmdMainMenu( const client )
- {
- static Menu;
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Manage Server Admins", szPrefix )
- Menu = menu_create( szItem, "handlerMainMenu" );
- menu_additem( Menu, "Add a new admin^n" );
- menu_additem( Menu, "Edit server admin\d(s)" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerMainMenu( client, Menu, Item )
- {
- menu_destroy( Menu );
- if ( Item == 0 ) // Add a new admin
- {
- static i;
- for ( i = 0; i < client_data; i++ )
- {
- if ( i == g_mMonth )
- g_mIndex[ client ][ i ] = 1;
- else
- g_mIndex[ client ][ i ] = 0;
- }
- return cmdAddAdminMenu( client );
- }
- else if ( Item == 1 )
- return cmdEditServerAdmins( client );
- return 1;
- }
- public cmdAddAdminMenu( const client )
- {
- static Menu;
- static szBuffer[ 32 ];
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Manage Server Admins", szPrefix )
- Menu = menu_create( szItem, "handlerAddAdminMenu" );
- // Select a Player
- if ( gIndex( client, g_mPlayer ) == 0 )
- szBuffer = "\r NONE";
- else
- formatex( szBuffer, charsmax( szBuffer ), "\y %s", szName( gIndex( client, g_mPlayer ) ) );
- formatex( szItem, charsmax( szItem ), "%sSelect a player: %s", ( gIndex( client, g_mPlayer ) == 0 ) ? "\r*\w " : "", szBuffer );
- menu_additem( Menu, szItem, "0" );
- // Nickname
- if ( gIndex( client, g_mNoNick ) == 0 )
- szBuffer ="\r NONE";
- else
- formatex( szBuffer, charsmax( szBuffer ), "\y %s", szIndex[ client ][ g_mNickname ] );
- formatex( szItem, charsmax( szItem ), "%sNickname:%s^n", ( gIndex( client, g_mNoNick ) == 0 ) ? "\r*\w " : "", szBuffer );
- menu_additem( Menu, szItem, "4" );
- // Saving Method
- formatex( szItem, charsmax( szItem ), "Saving method:\y %s", ( gIndex( client, g_mSaving ) == 0 ) ? "STEAM ID" : "IP ADDRESS" );
- menu_additem( Menu, szItem, "1" );
- // Admin group
- formatex( szItem, charsmax( szItem ), "Admin group:\y %s^n", g_szAccessNames[ gIndex( client, g_mGroup ) ][ ACCESS_NAME ] );
- menu_additem( Menu, szItem, "2" );
- // Set time
- menu_additem( Menu, "Time Menu^n", "3" );
- // Password
- if ( gIndex( client, g_mNoPassword ) == 0 )
- szBuffer ="\y NONE";
- else
- formatex( szBuffer, charsmax( szBuffer ), "\r %s", szIndex[ client ][ g_mPassword ] );
- formatex( szItem, charsmax( szItem ), "Password:%s", szBuffer );
- menu_additem( Menu, szItem );
- // Removable
- formatex( szItem, charsmax( szItem ), "Removable:%s^n", ( gIndex( client, g_mRemovable ) == 0 ) ? "\y YES" : "\r NO" );
- menu_additem( Menu, szItem, "6" );
- if ( gIndex( client, g_mPlayer ) != 0 && gIndex( client, g_mNoNick ) != 0 )
- {
- menu_additem( Menu, "Add Admin!", "7" );
- menu_addblank( Menu, 1 );
- menu_additem( Menu, "Back" );
- menu_setprop( Menu, MPROP_PERPAGE, 0 );
- }
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerAddAdminMenu( client, Menu, Item )
- {
- if ( Item == MENU_EXIT )
- {
- menu_destroy( Menu );
- return cmdMainMenu( client );
- }
- switch ( Item )
- {
- case 0: // Select a Player
- {
- /*
- if ( get_potential_admins( ) < 1 )
- {
- ColorPrint( 0, "No potential admin currently available." );
- return cmdMainMenu( client );
- }
- */
- return cmdSelectPlayerMenu( client );
- }
- case 1: // Nickname
- {
- client_cmd( client, "messagemode admin_nick" );
- menu_destroy( Menu );
- return 1;
- }
- case 2: // Saving method
- {
- if ( gIndex( client, g_mSaving ) == 0 )
- g_mIndex[ client ][ g_mSaving ] = 1;
- else
- g_mIndex[ client ][ g_mSaving ] = 0;
- }
- case 3: // Admin group
- {
- if ( gIndex( client, g_mGroup ) >= sizeof ( g_szAccessNames ) - 1 )
- g_mIndex[ client ][ g_mGroup ] = -1;
- g_mIndex[ client ][ g_mGroup ]++;
- }
- case 4: // Time Menu
- return cmdTimeMenu( client );
- case 5: // Password
- {
- client_cmd( client, "messagemode admin_pass" );
- }
- case 6: // Removable
- {
- if ( gIndex( client, g_mRemovable ) == 0 )
- g_mIndex[ client ][ g_mRemovable ] = 1;
- else
- g_mIndex[ client ][ g_mRemovable ] = 0;
- }
- case 7: // Add Admin!
- {
- static index, iNick;
- index = gIndex( client, g_mPlayer );
- iNick = gIndex( client, g_mNoNick );
- if ( gIndex( client, g_mPlayer ) != 0 && gIndex( client, g_mNoNick ) != 0 )
- {
- ColorPrint( client, "You need to select a^3 player^1 and add a^4 nickname^1." );
- return cmdAddAdminMenu( client );
- }
- if ( !is_user_connected( index ) )
- {
- ColorPrint( client, "Invalid player was selected^1." );
- return cmdAddAdminMenu( client );
- }
- static ,iMethod, iGroup, iPass, iRemove;
- static szNick[ MAX_NICKNAME_CHARS + 3 ], szPass[ MAX_PASSWORD_CHARS + 3 ];
- formatex( szNick, charsmax( szNick ), szIndex[ client ][ g_mNickname ] );
- iMethod = gIndex( client, g_mMethod );
- iGroup = gIndex( client, g_mGroup );
- iPass = gIndex( client, g_mPassword );
- if ( iPass != 0 )
- formatex( szPass, charsmax( szPass ), szIndex[ client ][ g_mPassword ] );
- else
- szPass = "";
- iRemove = gIndex( client, g_mRemovable );
- server_cmd( "amx_addadmin ^"%s^" ^"%s^" ^"%s^" ^"%s^"", ( iMethod == 0 ) ? szAuth( index ) : szAuth( index ), g_szAccessNames[ iGroup ][ ACCESS_LETTERS ], szPass, ( iMethod == 0 ) ? "steamid" : "ip" );
- }
- }
- return cmdAddAdminMenu( client );
- }
- new const szIDVault[ ] = "vaultIDs";
- new const szVault[ ] = "vaultAdmins";
- stock addAdmin( const Auth[], const Pass[], const Removable, const iMethod, const Nickname[], const Time )
- {
- static CurrentTime, ExpirationTime;
- static szKey[ 64 ], szData[ 128 ], szAdminIndex[ 32 ];
- CurrentTime = get_systime();
- ExpirationTime = CurrentTime + Time;
- static adminIndex;
- if ( fvault_size( szIDVault ) < 1 )
- szAdminIndex = "0";
- else
- {
- fvault_get_keyname( szIDVault, fvault_size( szIDVault ) - 1, szKey, charsmax( szKey ) );
- fvault_get_data( szIDVault, szKey, szData, charsmax( szData ) );
- formatex( szAdminIndex, charsmax( szAdminIndex ), "%i", str_to_num( szData ) + 1 );
- }
- fvault_set_data( szIDVault, Auth, szAdminIndex );
- Nickname |
- formatex( szData, charsmax( szData ), "%s
- public cmdSelectPlayerMenu( const client )
- {
- /*
- if ( get_potential_admins( ) < 1 )
- {
- ColorPrint( 0, "No potential admin currently available." );
- return cmdMainMenu( client );
- }
- */
- static Menu;
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Manage Server Admins^n^nSelect a player", szPrefix )
- Menu = menu_create( szItem, "handlerSelectPlayerMenu" );
- static Players[ 32 ], iNum, i, index, szBuffer[ 3 ];
- get_players( Players, iNum, "ch" );
- for ( i = 0; i < iNum; i++ )
- {
- index = Players[ i ];
- /*
- if ( get_user_flags( index ) & ACCESS_VIP )
- continue;
- */
- num_to_str( index, szBuffer, charsmax( szBuffer ) );
- menu_additem( Menu, szName( index ), szBuffer );
- }
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerSelectPlayerMenu( client, Menu, Item )
- {
- if ( Item == MENU_EXIT )
- {
- menu_destroy( Menu );
- return cmdAddAdminMenu( client );
- }
- static mData[ 3 ], index, Trash;
- menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
- g_mIndex[ client ][ g_mPlayer ] = str_to_num( mData );
- if ( !is_user_connected( g_mIndex[ client ][ g_mPlayer ] ) )
- {
- ColorPrint( client, "Invalid user selected, please try again." );
- g_mIndex[ client ][ g_mPlayer ] = 0;
- return cmdSelectPlayerMenu( client );
- }
- return cmdAddAdminMenu( client );
- }
- public cmdTimeMenu( const client )
- {
- static Menu, i, z;
- static szBuffer[ 2 ];
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Manage Server Admins^n^nSelect a player", szPrefix )
- Menu = menu_create( szItem, "handlerTimeMenu" );
- // Permanent
- formatex( szItem, charsmax( szItem ), "Permanent:%s^n", ( gIndex( client, g_mTime ) == 0 ) ? "\r YES" : "\y NO" );
- menu_additem( Menu, szItem );
- if ( gIndex( client, g_mTime ) == 0 ) // End menu if Permanent is yes
- {
- menu_display( client, Menu );
- return 1;
- }
- // Set times
- z = 0;
- for ( i = g_mMonth; i < g_mSecond + 1; i++ )
- {
- formatex( szItem, charsmax( szItem ), "Set %s(s):\r %i %s(s)", g_szTimes[ z ], gIndex( client, i ), g_szTimes[ z ] );
- num_to_str( i, szBuffer, charsmax( szBuffer ) );
- menu_additem( Menu, szItem, szBuffer );
- z++;
- }
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerTimeMenu( client, Menu, Item )
- {
- if ( Item == MENU_EXIT )
- {
- menu_destroy( Menu );
- return cmdAddAdminMenu( client );
- }
- if ( Item == 0 ) // Permanent
- g_mIndex[ client ][ g_mTime ] = ( gIndex( client, g_mTime ) == 0 ) ? 1 : 0;
- else
- {
- static mData[ 3 ], Trash;
- menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
- g_mIndex[ client ][ g_mTimeData ] = str_to_num( mData );
- g_mIndex[ client ][ g_mTimeData ] = Item - 1;
- client_cmd( client, "messagemode admin_time" );
- return 1;
- }
- return cmdTimeMenu( client );
- }
- public cmdEditServerAdmins( const client )
- {
- return 1;
- }
- /* --------------------------------------------
- Tasks
- -------------------------------------------- */
- /* --------------------------------------------
- Stocks & Natives
- -------------------------------------------- */
- stock get_potential_admins( )
- {
- static Players[ 32 ], iNum, i, count;
- count = 0;
- get_players( Players, iNum, "ch" );
- for ( i = 0; i < iNum; i++ )
- {
- if ( get_user_flags( Players[ i ] ) & ACCESS_VIP )
- count++;
- }
- return count;
- }
- stock bool: is_user_allowed( const index, gAccess = MENU_ACCESS )
- {
- // If a steamid is coded
- if ( is_user_special( szAuth( index ) ) )
- return true;
- #if defined NEED_PASS
- // If user hasn't typed in the password
- if ( !bAllowedPassword[ index ] )
- return false;
- #endif
- // If user has MENU_ACCESS
- if ( get_user_flags( index ) & gAccess )
- return true;
- return false;
- }
- stock bool: is_user_special( const Authid[] )
- {
- static i;
- for ( i = 0; i < sizeof szAllowedSteamIDs; i++ )
- {
- if ( equali( Authid, szAllowedSteamIDs[ i ] ) )
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment