Raised This Month: $119 Target: $400
 29% 

ArrayPushArray return value bug?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-21-2020 , 15:33   ArrayPushArray return value bug?
Reply With Quote #1

ArrayPushArray returns wrong values. According to the documentation it's supposed to return the index of the new entry that we push into the array.

I'm using this code:
Code:
public myFunction()
{
	new iIndex = ArrayPushArray( g_aBans, eData );
	BanPlayer( g_szName[ iPlayer ], g_szAuthId[ iPlayer ], g_szIp[ iPlayer ], szExpireDate, szReason, g_szName[ id ] );
	
	if( is_user_connected( iPlayer ) )
	{
	    ScreenShot( iPlayer );
	    KickPlayerOut( iPlayer, iIndex );
	}
	return PLUGIN_HANDLED;
}

public KickPlayerOut( const id, const iIndex )
{
	if( get_user_flags( id ) & g_iConfig[ IMMUNITY_FLAG ] )
	{
		return PLUGIN_HANDLED;
	}

	else
	{
		new eData[ PlayerBan ];
		ArrayGetArray( g_aBans, iIndex, eData );
		
		log_to_file( "bans.txt", "#3 g_szAuthId: %s | eData: %s | Index: %d", g_szAuthId[ id ], eData[ Player_SteamId ], iIndex );
		
		if( equal( g_szAuthId[ id ], eData[ Player_SteamId ] ) || equal( g_szIp[ id ], eData[ Player_IP ] ) )
		{
			if( ! HasDatePassed( eData[ Player_BanExpire ] ) || equali( eData[ Player_BanExpire ], "never" ) )
			{
				if( equali( eData[ Player_BanExpire ], "never" ) )
				{				
					send_message( id, CONSOLE, false, "^n************************************************" );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_BANNED" );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_EXPIRE_NEVER" );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_REASON", eData[ Player_BanReason ] );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_BY", eData[ Player_BannedBy ] );
					send_message( id, CONSOLE, false, "************************************************" );
				}
				
				else
				{
					send_message( id, CONSOLE, false, "^n************************************************" );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_BANNED" );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_EXPIRE", eData[ Player_BanExpire ] );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_REASON", eData[ Player_BanReason ] );
					send_message( id, CONSOLE, false, "%L", id, "BAN_INFO_BY", eData[ Player_BannedBy ] );
					send_message( id, CONSOLE, false, "************************************************" );
				}
				server_cmd( "kick #%d %L", get_user_userid( id ), id, "CHECK_CONSOLE_INFO" );
			}
		}
	}
	return PLUGIN_HANDLED;
}

BanPlayer( const szName[ ], const szSteamId[ ], const szIP[ ], const szExpireDate[ ], const szReason[ ], const szBannedBy[ ] )
{
	new szFormat[ 128 ];
	formatex( szFormat, charsmax( szFormat ), "%s/%s", g_szConfigsDir, g_iConfig[ BANS_FILE ] );
	
	new iFilePointer = fopen( szFormat, "r+" );
	
	if( iFilePointer )
	{			
		new szByteVal[ 1 ];
		
		fseek( iFilePointer , -1 , SEEK_END );
		fread_raw( iFilePointer , szByteVal , sizeof( szByteVal ) , BLOCK_BYTE );
		fseek( iFilePointer , 0 , SEEK_END );
		
		fprintf( iFilePointer, "%s^"%s^" ^"%s^" ^"%s^" ^"%s^" ^"%s^" ^"%s^"", ( szByteVal[ 0 ] == 10 ) ? "" : "^n", szName, szSteamId, szIP, szExpireDate, szReason, szBannedBy ); // add him to banlist
		fclose( iFilePointer );
	}
	return 1;
}
Quote:
#3 g_szAuthId: HIDDEN | eData: HIDDEN | Index: 1
OK my array size might be 1, fine, but no. I added a command to check the size of g_aBans, and it shows 37.
__________________

Last edited by edon1337; 01-21-2020 at 15:57.
edon1337 is offline
Send a message via Skype™ to edon1337
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-21-2020 , 16:17   Re: ArrayPushArray return value bug?
Reply With Quote #2

If your claim is some native is broken don't show your code. Instead, create a minimal example that we can run and reproduce the issue.
If you suspect the code is the problem, then yes, show what you did.

PHP Code:
#include <amxmodx>

enum _:dummy
{
    
a,
    
b[10],
    
c
};

public 
plugin_init()
{
    new 
buffer[dummy];
    new Array:
test ArrayCreate(sizeof(buffer));
    
    new 
bool:ok true;
    for(new 
01000i++)
    {
        new 
position ArrayPushArray(testbuffer);
        if(
position != i)
        {
            
server_print("Wrong return value: %d != %d"iposition);
            
ok false;
            break;
        }
    }
    
    if(
ok)
    {
        
server_print("Return value is fine")
    }

Output:
Code:
Return value is fine
The native is not wrong.
__________________
HamletEagle is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:50.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode