Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < amxmodx >
- #include < sqlx >
- #define TABLE_NAME "player_info"
- /* Database */
- new Host[] = ""
- new User[] = ""
- new Pass[] = ""
- new Db[] = ""
- new MySQL_Query[ 512 ]
- new Handle:MySQL_Tuple
- new Handle:MySQL_Connection
- public plugin_init( ) {
- register_plugin( "PlayerInfo", "v1", "???" )
- }
- public client_putinserver( id )
- {
- MySQL_Load(id);
- }
- public plugin_precache( )
- {
- MySQL_Tuple = SQL_MakeDbTuple( Host, User, Pass, Db )
- #if AMXX_VERSION_NUM >= 183
- SQL_SetCharset(MySQL_Tuple,"utf8");
- #endif
- new ErrorCode
- MySQL_Connection = SQL_Connect( MySQL_Tuple, ErrorCode, MySQL_Query, charsmax( MySQL_Query ) )
- if( MySQL_Connection == Empty_Handle )
- set_fail_state( MySQL_Query )
- formatex( MySQL_Query, charsmax( MySQL_Query ), "CREATE TABLE IF NOT EXISTS %s (id int NOT NULL AUTO_INCREMENT, username VARCHAR(128), steam_id VARCHAR(20), ip_adress VARCHAR(15), date DATE, time TIME, primary key (id) )", TABLE_NAME )
- SQL_ThreadQuery( MySQL_Tuple, "SQL_TrashHandler", MySQL_Query )
- }
- public MySQL_Load( id )
- {
- new szAuth[32];
- get_user_authid(id, szAuth, 31);
- new Temp[ 1 ]
- Temp[ 0 ] = id
- formatex( MySQL_Query, charsmax( MySQL_Query ), "SELECT `steam_id` FROM %s WHERE `steam_id` = '%s'", TABLE_NAME, szAuth )
- SQL_ThreadQuery( MySQL_Tuple, "Load_PlayerInfo", MySQL_Query, Temp, sizeof( Temp ) )
- }
- public Load_PlayerInfo( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
- {
- if( FailState == TQUERY_CONNECT_FAILED ) { return PLUGIN_HANDLED; }
- else if( FailState == TQUERY_QUERY_FAILED ) { return PLUGIN_HANDLED; }
- new id = Data[ 0 ]
- if( !is_user_connected( id ) )
- return PLUGIN_HANDLED;
- new szAuth[32], szName[32], szIP[23], currentTime[9], currentDate[11];
- get_user_authid(id, szAuth, 31);
- get_user_name(id, szName, 31);
- get_user_ip(id, szIP, 22, 1);
- get_time("%H:%M:%S", currentTime, 8)
- get_time("%Y/%m/%d", currentDate, 10)
- if( SQL_NumResults( Query ) < 1 )
- {
- formatex( MySQL_Query, charsmax( MySQL_Query ), "INSERT INTO %s (`username`, `steam_id`, `ip_adress`, `date`, `time`) VALUES ('%s', '%s', '%s', '%s', '%s')", TABLE_NAME, szName, szAuth, szIP, currentDate, currentTime )
- SQL_ThreadQuery( MySQL_Tuple, "SQL_TrashHandler", MySQL_Query )
- }
- else {
- formatex( MySQL_Query, charsmax( MySQL_Query ), "UPDATE %s SET `date` = '%s', `time` = '%s' WHERE `steam_id` = '%s'", TABLE_NAME, currentDate, currentTime, szAuth )
- SQL_ThreadQuery( MySQL_Tuple, "SQL_TrashHandler", MySQL_Query )
- }
- return PLUGIN_CONTINUE;
- }
- public SQL_TrashHandler( FailState,Handle:Query, Error[ ], Errcode,Data[ ], DataSize )
- {
- if( FailState == TQUERY_CONNECT_FAILED )
- return PLUGIN_HANDLED;
- else if( FailState == TQUERY_QUERY_FAILED )
- return PLUGIN_HANDLED;
- SQL_FreeHandle( Query )
- return PLUGIN_CONTINUE;
- }
- public plugin_end( )
- {
- SQL_FreeHandle( MySQL_Connection )
- }
Add Comment
Please, Sign In to add comment