Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
|
01-15-2018
, 08:25
Re: Loop order
|
#3
|
Quote:
Originally Posted by Bugsy
I would do a step by step debug. You have a good understanding of the process your plugin takes to do things. At each step I would put a print and you can then determine which code is getting reached when it shouldn't or vice versa. Also a good idea to check values in these prints as well.
|
Debug with a 10 second delay, if you wanna test it, here's the code, just stay with 0. x second delay to see the real bug. With the 10 second delay, you can barely notice it.
First of all, put a new entry in the .ini file with your information, second, when you're in-game, change the password in .ini file then change it in-game just like it is in the .ini, it still will keep kicking you. Make sure to disable admin.amxx.
PHP Code:
[The part that works correctly] L 01/15/2018 - 14:11:58: #1 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:11:58: #2 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:11:58: #3 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:11:58: #1 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:11:58: #3 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 |
[The part that also works correctly, I changed my setinfo _pw] L 01/15/2018 - 14:12:09: #1 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:12:09: #3 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:12:09: #1 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:12:09: #3 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi77 | L 01/15/2018 - 14:12:09: #4 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi7 | szPassword: kenshi77 |
[The part that bugs, my setinfo = kenshi7 | my pw in .ini = kenshi7 , but Player_Password hasn't changed] L 01/15/2018 - 14:12:19: #4 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi7 | L 01/15/2018 - 14:12:19: #4 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi77 | szPassword: kenshi7 | L 01/15/2018 - 14:12:19: #1 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi7 | szPassword: kenshi7 | L 01/15/2018 - 14:12:19: #3 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi7 | szPassword: kenshi7 | L 01/15/2018 - 14:12:19: #1 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi7 | szPassword: kenshi7 | L 01/15/2018 - 14:12:19: #3 Called | Player_Name: DoNii | szName: DoNii | Player_Password: kenshi7 | szPassword: kenshi7 |
Code:
PHP Code:
#include < amxmodx > #include < amxmisc > #include < colorchat >
#define PLUGIN_AUTHOR "DoNii" #define PLUGIN_VERSION "1.2" #define PLUGIN_NAME "New Admin System"
#define TASK_CHECK_STEAL 0.3
#define ADMIN_ADD_FLAG ADMIN_RCON
enum _:PlayerData { Player_Name[ 32 ], Player_Password[ 18 ], Player_AccessFlags[ 32 ], Player_Prefix[ 24 ] }
new szPlayerPrefix[ 33 ][ 24 ]; // bugfix v1.2 new g_iItems[ PlayerData ]; new Array:g_aDatabase; new const g_szFile[ ] = "AccountUsers.ini";
public plugin_init( ) { register_plugin( PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR ); register_concmd( "amx_addadmin", "OnAddNewAdmin" ); g_aDatabase = ArrayCreate( PlayerData ); register_clcmd( "say", "OnHookSay" ); register_clcmd( "say_team", "OnHookSay" ); set_task( TASK_CHECK_STEAL, "OnTaskCheckStealAdmin", _, _, _, "b" ); ReadFile( ); }
public client_connect( id ) FreeString( szPlayerPrefix[ id ] );
public OnAddNewAdmin( id ) { if( ~ get_user_flags( id ) & ADMIN_ADD_FLAG ) { client_print( id, print_console, "You have no Access to this command" ); return PLUGIN_HANDLED; }
if( read_argc( ) != 5 ) { client_print( id, print_console, "Usage is : amx_addadmin <Nick|SteamID> <Password> <Flags> <Prefix>" ); return PLUGIN_HANDLED; }
new szAdminName[ 32 ], szAdminPassword[ 18 ], szAdminFlags[ 32 ], szAdminPrefix[ 18 ]; read_argv( 1, szAdminName, charsmax( szAdminName ) ); read_argv( 2, szAdminPassword, charsmax( szAdminPassword ) ); read_argv( 3, szAdminFlags, charsmax( szAdminFlags ) ); read_argv( 4, szAdminPrefix, charsmax( szAdminPrefix ) ); if( ( strlen( szAdminName ) < 3 ) || ( strlen( szAdminFlags ) < 1 ) ) { client_print( id, print_console, "ERROR: Incorrect Format of Admin" ); return PLUGIN_HANDLED; } new szConfigs[ 64 ], szFormat[ 128 ]; get_configsdir( szConfigs, charsmax( szConfigs ) ); formatex( szFormat, charsmax( szFormat ), "%s/%s", szConfigs, g_szFile ); new iFile = fopen( szFormat, "r+" );
new szByteVal[ 1 ], szNewLine[ 256 ]; fseek( iFile , -1 , SEEK_END ); fread_raw( iFile , szByteVal , sizeof( szByteVal ) , BLOCK_BYTE ); fseek( iFile , 0 , SEEK_END ); formatex( szNewLine , charsmax( szNewLine ) , "%s^"%s^" ^"%s^" ^"%s^" ^"%s^"" , ( szByteVal[ 0 ] == 10 ) ? "" : "^n", szAdminName, szAdminPassword, szAdminFlags, szAdminPrefix );
fprintf( iFile, szNewLine ); fclose( iFile ); client_print( id, print_console, "Successfully Added New Admin: Name: %s | Password: %s | Flags: %s | Prefix: %s |", szAdminName, szAdminPassword, szAdminFlags, szAdminPrefix ); return PLUGIN_CONTINUE; }
public OnTaskCheckStealAdmin( ) { ReadFile( );
new szPlayers[ 32 ], iNum, szName[ 32 ], szAuthID[ 32 ], szPassword[ 18 ]; get_players( szPlayers, iNum ); static iTempID;
new iArraySize = ArraySize( g_aDatabase );
for( new i; i < iNum; i++ ) { iTempID = szPlayers[ i ];
for( new iIndex; iIndex < iArraySize; iIndex++ ) { ArrayGetArray( g_aDatabase, iIndex, g_iItems ); get_user_info( iTempID, "name", szName, charsmax( szName ) ); get_user_authid( iTempID, szAuthID, charsmax( szAuthID ) ); get_user_info( iTempID, "_pw", szPassword, charsmax( szPassword ) ); if( equal( g_iItems[ Player_Name ], szName ) || equal( g_iItems[ Player_Name ], szAuthID ) ) { if( ! g_iItems[ Player_Password ][ 0 ] || equal( g_iItems[ Player_Password ], szPassword ) ) { remove_user_flags( iTempID ); set_user_flags( iTempID, read_flags( g_iItems[ Player_AccessFlags ] ) ); log_to_file( "DebugTest.txt", "#1 Called | Player_Name: %s | szName: %s | Player_Password: %s | szPassword: %s |", g_iItems[ Player_Name ], szName, g_iItems[ Player_Password ], szPassword ); if( ! equal( szPlayerPrefix[ iTempID ], g_iItems[ Player_Prefix ] ) ) { copy( szPlayerPrefix[ iTempID ], charsmax( szPlayerPrefix[ ] ), g_iItems[ Player_Prefix ] ); log_to_file( "DebugTest.txt", "#2 Called | Player_Name: %s | szName: %s | Player_Password: %s | szPassword: %s |", g_iItems[ Player_Name ], szName, g_iItems[ Player_Password ], szPassword ); } log_to_file( "DebugTest.txt", "#3 Called | Player_Name: %s | szName: %s | Player_Password: %s | szPassword: %s |", g_iItems[ Player_Name ], szName, g_iItems[ Player_Password ], szPassword ); } else if( ! equal( g_iItems[ Player_Password ], szPassword ) ) { remove_user_flags( iTempID ); server_cmd( "kick #%d ^"KICKED: you have no entry to this server^"", get_user_userid( iTempID ) ); log_to_file( "DebugTest.txt", "#4 Called | Player_Name: %s | szName: %s | Player_Password: %s | szPassword: %s |", g_iItems[ Player_Name ], szName, g_iItems[ Player_Password ], szPassword ); } } } } }
public client_infochanged( id ) { new szOldName[ 32 ], szNewName[ 32 ]; get_user_name( id, szOldName, charsmax( szOldName ) ); get_user_info( id, "name", szNewName, charsmax( szNewName ) );
if( ! equal( szOldName, szNewName ) ) remove_user_flags( id ); }
public client_authorized( id ) { new iArraySize = ArraySize( g_aDatabase ); new szName[ 32 ], szAuthID[ 32 ], szPassword[ 18 ]; for( new iIndex; iIndex < iArraySize; iIndex++ ) { ArrayGetArray( g_aDatabase, iIndex, g_iItems ); get_user_info( id, "name", szName, charsmax( szName ) ); get_user_authid( id, szAuthID, charsmax( szAuthID ) ); get_user_info( id, "_pw", szPassword, charsmax( szPassword ) ); if( equal( g_iItems[ Player_Name ], szName ) || equal( g_iItems[ Player_Name ], szAuthID ) ) { if( ! g_iItems[ Player_Password ][ 0 ] || equal( g_iItems[ Player_Password ], szPassword ) ) { remove_user_flags( id ); set_user_flags( id, read_flags( g_iItems[ Player_AccessFlags ] ) ); } else { server_cmd( "kick #%d ^"KICKED: you have no entry to this server^"", get_user_userid( id ) ); } } } return PLUGIN_CONTINUE; }
public OnHookSay( id ) { ReadFile( );
new iArraySize = ArraySize( g_aDatabase ); new szArgs[ 192 ], szName[ 32 ], szAuthID[ 32 ], szPassword[ 18 ]; for( new iIndex; iIndex < iArraySize; iIndex++ ) { ArrayGetArray( g_aDatabase, iIndex, g_iItems ); read_args( szArgs, charsmax( szArgs ) ); remove_quotes( szArgs ); get_user_info( id, "name", szName, charsmax( szName ) ); get_user_authid( id, szAuthID, charsmax( szAuthID ) ); get_user_info( id, "_pw", szPassword, charsmax( szPassword ) ); if( equal( g_iItems[ Player_Name ], szName ) || equal( g_iItems[ Player_Name ], szAuthID ) ) { if( ! g_iItems[ Player_Password ][ 0 ] || equal( g_iItems[ Player_Password ], szPassword ) ) { if( szPlayerPrefix[ id ][ 0 ] ) { if( is_user_alive( id ) ) { client_print_color( 0, DontChange, "^4%s ^3%s^1: ^4%s", szPlayerPrefix[ id ][ 0 ], szName, szArgs ); return PLUGIN_HANDLED_MAIN; } else { client_print_color( 0, DontChange, "^1*DEAD* ^4%s ^3%s^1: ^4%s", szPlayerPrefix[ id ][ 0 ], szName, szArgs ); return PLUGIN_HANDLED_MAIN; } } else return PLUGIN_CONTINUE; } } } return PLUGIN_CONTINUE; }
ReadFile( ) { new szConfigs[ 32 ], szFormat[ 64 ], szPlayerData[ 512 ], szName[ 32 ], szPassword[ 18 ], szAccessFlags[ 25 ], szPrefix[ 24 ]; get_configsdir( szConfigs, charsmax( szConfigs ) ); formatex( szFormat, charsmax( szFormat ), "%s/%s", szConfigs, g_szFile ); new iFile = fopen( szFormat, "r" ); if( iFile ) { while( ! feof( iFile ) ) { fgets( iFile, szPlayerData, charsmax( szPlayerData ) ); trim( szPlayerData ); if( szPlayerData[ 0 ] == ';' || ( szPlayerData[ 0 ] == '/' && szPlayerData[ 1 ] == '/' ) ) continue; parse( szPlayerData, szName, charsmax( szName ), szPassword, charsmax( szPassword ), szAccessFlags, charsmax( szAccessFlags ), szPrefix, charsmax( szPrefix ) ); g_iItems[ Player_Name ] = szName; g_iItems[ Player_Password ] = szPassword; g_iItems[ Player_AccessFlags ] = szAccessFlags; g_iItems[ Player_Prefix ] = szPrefix; ArrayPushArray( g_aDatabase, g_iItems ); } fclose( iFile ); } }
FreeString( szString[ ] ) { for( new i; i < strlen( szString ); i++ ) { szString[ i ] = EOS; } return 1; }
Quote:
Originally Posted by Clauu
Since you're using global vars, you should empty them before reading again
|
Which global vars?
Quote:
Originally Posted by Clauu
g_iItems[ index ][0]=0
|
What even is that? Makes no sense at all.
Quote:
Originally Posted by Clauu
Same thing for the array g_aDatabase, it should be emptied too before adding new entries.
|
How do you empty an array? And where should I do that?
Quote:
Originally Posted by Clauu
g_iItems[ Player_Name ] = szName // you shouldn't do this, use copy or format(ex) or better parse directly in to g_iItems[ index ]
|
I don't really get what this index thingy of yours is, at all. Why should I call a native when I can do it directly!?
Quote:
Originally Posted by Clauu
And also as a thing of optimization i don't think that it's a good ideea to parse files in chat hook, set_task is enough for this job
|
Neither do I get this one. Where do you see parse in chat hook?
Quote:
Originally Posted by Natsheh
You forgot to remove the quotes from szName, etc...
|
Where?
Quote:
Originally Posted by Natsheh
And check if the line you retrieved is greater than 5 characters
|
Which line?
Quote:
Originally Posted by Natsheh
#define FreeString(%1) %1[0]=EOS
|
Thanks!
__________________
Last edited by edon1337; 01-15-2018 at 12:42.
|
|