Raised This Month: $ Target: $400
 0% 

authID to steamID


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
jingojang
Senior Member
Join Date: Feb 2010
Location: The Moon
Old 12-31-2013 , 06:08   authID to steamID
Reply With Quote #1

Hello, need help translating this so it saves by steamID. Now it saves a new tablerow every time a player reconnects. If you can explain why it does that aswell it would be golden. Thanks!

Code:
// SQL tiedot:
new Host[]     = "";
new User[]     = "";
new Pass[]     = "";
new Db[]       = "";

new g_data_loaded, Handle:g_sql_tuple, g_error[ 512 ];

public client_putinserver( id )
	Load( id );

public MySQLInit()
{
	g_sql_tuple = SQL_MakeDbTuple( Host, User, Pass, Db );
	
	new ErrorCode, Handle:SqlConnection = SQL_Connect( g_sql_tuple, ErrorCode, g_error, charsmax( g_error ) );
	if ( SqlConnection == Empty_Handle )
		set_fail_state( g_error );
	
	new Handle:Queries;
	
	Queries = SQL_PrepareQuery( SqlConnection, "CREATE TABLE IF NOT EXISTS `knifemodels` ( `authid` VARCHAR(35) NOT NULL, `model` INT(11) NOT NULL );" );
	
	if ( ! SQL_Execute( Queries ) )
	{
		SQL_QueryError( Queries, g_error, charsmax( g_error ) );
		set_fail_state( g_error );
	}
	SQL_FreeHandle( Queries );
	SQL_FreeHandle( SqlConnection );
}

public Save( id )
{
	static szAuthId[ 35 ], szName[ 33 ], query[ 512 ];
	get_user_authid( id, szAuthId, charsmax( szAuthId ) );
	get_user_name( id, szName, charsmax( szName ) );
	
	if( g_data_loaded )
	{
		formatex( query, charsmax( query ), "UPDATE `knifemodels` SET `model` = %i WHERE `authid` = '%s';", knife_model[ id ], szAuthId );
	}
	else
	{
		formatex( query, charsmax( query ), "INSERT INTO `knifemodels` ( `authid`, `model` ) VALUES ( '%s', %i );", szName, knife_model[ id ] );
	}
	SQL_ThreadQuery( g_sql_tuple, "QuerySaveData", query );
}

public QuerySaveData( failstate, Handle:query, error[], errnum, data[], size, Float:queuetime )
{
	if ( failstate == TQUERY_CONNECT_FAILED
	|| failstate == TQUERY_QUERY_FAILED )
	{
		set_fail_state( error );
	}
}

public Load( id )
{
	static szAuthId[ 35 ], query[ 512 ];
	get_user_authid(id, szAuthId, charsmax(szAuthId))
	
	new Data[ 1 ]
	Data[ 0 ] = id;
	
	format( query, charsmax( query ), "SELECT * FROM `knifemodels` WHERE authid = '%s'", szAuthId );
	
	SQL_ThreadQuery( g_sql_tuple, "register_client", query, Data,  1 ); 
}

public register_client( FailState, Handle:Query, Error[], Errcode, Data[], DataSize )
{
	if( FailState == TQUERY_CONNECT_FAILED )
	{
		log_amx( "Load - Could not connect to SQL database.  [%d] %s", Errcode, Error );
	}
	else if(FailState == TQUERY_QUERY_FAILED)
	{
		log_amx( "Load Query failed. [%d] %s", Errcode, Error );
	}
	
	new id = Data[ 0 ];
	
	if( SQL_NumResults( Query ) ) 
	{
		g_data_loaded = 1;
		
		knife_model[ id ] = SQL_ReadResult( Query, 1 );
	}
	return PLUGIN_HANDLED
}

public plugin_end()
	SQL_FreeHandle( g_sql_tuple );
__________________
jingojang is offline
 


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 20:34.


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