Raised This Month: $12 Target: $400
 3% 

[JailBreak] Dissapearing packs [Free Code For You]


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
KamiN
Senior Member
Join Date: Jun 2011
Old 06-21-2012 , 15:40   [JailBreak] Dissapearing packs [Free Code For You]
#1

I do have a little bit modified jailbreak shop 3.0
In plugin's version i do have JB Packs are saved in mysql by players IP adress.

Some players complaining that JB Packs they earned by killing CTs disappeared. JB Packs not disappearing periodically, in logs i cant find any errors. So i would like to ask you to look at the code and tell me if there's anything wrong why JB packs could disappear.

This is just a part of code witch is related with mysql
Code:
new Handle:g_hDbTuple;
new p_DbHost, p_DbUser, p_DbPass, p_DbName;

public plugin_init()
{
	p_DbHost = register_cvar( "amx_packs_dbhost", "xxx" );
	p_DbUser = register_cvar( "amx_packs_dbuser", "xxx" );
	p_DbPass = register_cvar( "amx_packs_dbpass", "xxx" );
	p_DbName = register_cvar( "amx_packs_dbname", "xxx" );

	SQL_CreateDbTuple( );
}

public plugin_end( )
{
	SQL_SaveAllDbTuple( );

	if ( g_hDbTuple )
	{
		SQL_FreeHandle( g_hDbTuple );
	}
}

public client_disconnect( id )
{
	SQL_SaveDbTuple( id );
}

public client_putinserver( id )
{
	SQL_LoadDbTuple( id );
}

SQL_CreateDbTuple( )
{
	new szDBHost[ 64 ], szDBUser[ 32 ], szDBPass[ 32 ], szDBName[ 32 ], szQuery[ 256 ];
	get_pcvar_string( p_DbHost, szDBHost, charsmax( szDBHost ) );
	get_pcvar_string( p_DbUser, szDBUser, charsmax( szDBUser ) );
	get_pcvar_string( p_DbPass, szDBPass, charsmax( szDBPass ) );
	get_pcvar_string( p_DbName, szDBName, charsmax( szDBName ) );

	g_hDbTuple = SQL_MakeDbTuple( szDBHost, szDBUser, szDBPass, szDBName, 0 );

	format( szQuery, charsmax( szQuery ), "CREATE TABLE IF NOT EXISTS nwk_packs (zaidejo_ip varchar(32) NOT NULL default '', zaidejo_paketai int(16) DEFAULT NULL) TYPE=MyISAM;" );
	SQL_ThreadQuery( g_hDbTuple, "QueryHandler", szQuery );
}

SQL_SaveAllDbTuple( )
{
	new players[ 32 ], pnum, i;
	get_players( players, pnum );

	for ( i = 0; i < pnum; i++ )
	{
		SQL_SaveDbTuple( players[ i ] );
	}
}

SQL_SaveDbTuple( id )
{
	if ( g_jbpacks[ id ] > 0 )
	{
		new user_ip[ 32 ], szQuery[ 256 ];
		get_user_ip( id, user_ip, charsmax( user_ip ), 1 );

		format( szQuery, charsmax( szQuery ), "UPDATE nwk_packs SET zaidejo_paketai = '%d' WHERE zaidejo_ip = '%s';", g_jbpacks[ id ], user_ip );
		SQL_ThreadQuery( g_hDbTuple, "QueryHandler", szQuery );
	}
}

SQL_LoadDbTuple( id )
{
	new user_ip[ 32 ], szQuery[ 256 ], data[ 1 ];
	get_user_ip( id, user_ip, charsmax( user_ip ), 1 );

	data[ 0 ] = id;

	format( szQuery, charsmax( szQuery ), "SELECT zaidejo_ip, zaidejo_paketai FROM nwk_packs WHERE zaidejo_ip = '%s';", user_ip );
	SQL_ThreadQuery( g_hDbTuple, "QuerySelect", szQuery, data, 1 );
}

public QuerySelect( failstate, Handle:query, error[ ], errnum, data[ ], size, Float:queuetime )
{
	if ( ( failstate == TQUERY_QUERY_FAILED ) || ( failstate == TQUERY_CONNECT_FAILED ) )
	{
		server_print( "* MySQL failstate: %s [%d]", error, errnum );
		return;
	}

	new id, user_ip[ 32 ];
	id = data[ 0 ];
	get_user_ip( id, user_ip, charsmax( user_ip ), 1 );

	if ( !SQL_NumResults( query ) )
	{
		new szQuery[ 256 ];
		format( szQuery, charsmax( szQuery ), "INSERT INTO nwk_packs (zaidejo_ip, zaidejo_paketai) VALUES ('%s', '0');", user_ip );
		SQL_ThreadQuery( g_hDbTuple, "QueryHandler", szQuery );

		g_jbpacks[ id ] = get_pcvar_num( g_startjp );
	}

	else
	{
		g_jbpacks[ id ] = SQL_ReadResult( query, 1 );
	}
}

public QueryHandler( failstate, Handle:query, error[ ], errnum, data[ ], size, Float:queuetime )
{
	if ( ( failstate == TQUERY_QUERY_FAILED ) || ( failstate == TQUERY_CONNECT_FAILED ) )
	{
		server_print( "* MySQL failstate: %s [%d]", error, errnum );
	}
}

Last edited by ConnorMcLeod; 06-22-2012 at 14:40.
KamiN is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-22-2012 , 09:05   Re: Dissapearing packs
#2

Make a check if the data has been loaded when saving it, because you will save nothing.
__________________
<VeCo> is offline
KamiN
Senior Member
Join Date: Jun 2011
Old 06-22-2012 , 10:24   Re: Dissapearing packs
#3

You mean like that?
Code:
new bool:SQLLoaded[ 33 ];

public client_disconnect( id )
{
	if(SQLLoaded[ id ])
	{
		SQL_SaveDbTuple( id );
		SQLLoaded[ id ] = false;
	}
}

public QuerySelect( failstate, Handle:query, error[ ], errnum, data[ ], size, Float:queuetime )
{
	if ( ( failstate == TQUERY_QUERY_FAILED ) || ( failstate == TQUERY_CONNECT_FAILED ) )
	{
		server_print( "* MySQL failstate: %s [%d]", error, errnum );
		return;
	}

	new id, user_ip[ 32 ];
	id = data[ 0 ];
	get_user_ip( id, user_ip, charsmax( user_ip ), 1 );

	if ( !SQL_NumResults( query ) )
	{
		new szQuery[ 256 ];
		format( szQuery, charsmax( szQuery ), "INSERT INTO nwk_packs (zaidejo_ip, zaidejo_paketai) VALUES ('%s', '0');", user_ip );
		SQL_ThreadQuery( g_hDbTuple, "QueryHandler", szQuery );

		g_jbpacks[ id ] = get_pcvar_num( g_startjp );
	}

	else
	{
		g_jbpacks[ id ] = SQL_ReadResult( query, 1 );
		SQLLoaded[ id ] = true;
	}
}
Tip: just check for SQLLoaded[ id ] nothing else changed

Last edited by ConnorMcLeod; 06-22-2012 at 14:38.
KamiN is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-22-2012 , 10:29   Re: Dissapearing packs
#4

Yes, that should work.
__________________
<VeCo> is offline
KamiN
Senior Member
Join Date: Jun 2011
Old 06-22-2012 , 11:11   Re: Dissapearing packs
#5

But now i'm thinking, how about "public plugin_end()"? Packed are saved there too. So i guess more sensible would be to check if data have been loaded not in PLUGIN_END() or CLIENT_DISSCONECT( id ), but in SQL_SaveDbTuple( id )

Just like that

Code:
SQL_SaveDbTuple( id )
{
	if(SQLLoaded[ id ])
	{
		if ( g_jbpacks[ id ] > 0 )
		{
			new user_ip[ 32 ], szQuery[ 256 ];
			get_user_ip( id, user_ip, charsmax( user_ip ), 1 );

			format( szQuery, charsmax( szQuery ), "UPDATE nwk_packs SET zaidejo_paketai = '%d' WHERE zaidejo_ip = '%s';", g_jbpacks[ id ], user_ip );
			SQL_ThreadQuery( g_hDbTuple, "QueryHandler", szQuery );
		}
		SQLLoaded[ id ] = false;
	}
}
Or i'm wrong?

Last edited by ConnorMcLeod; 06-22-2012 at 14:38.
KamiN is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-22-2012 , 11:21   Re: Dissapearing packs
#6

Yeah, you can check it there too.
__________________
<VeCo> is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-22-2012 , 14:11   Re: delete this thread
#7

Dude....don't delete all your posts from a question. Someone could learn from them.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-22-2012 , 14:37   Re: [JailBreak] Dissapearing packs [Free Code For You]
#8

This forum is not your personal forum.
Put back posts.
Next time you do such a think i request a ban, i hope you understand.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Closed Thread



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 17:12.


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