View Single Post
juss
Senior Member
Join Date: Jan 2016
Old 03-30-2016 , 10:02   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
here a start
PHP Code:

new Handle:db;

public 
OnPluginStart()
{
    new 
String:error[512];

    
db SQL_Connect("Mysql_SteamID_Check"trueerrorsizeof(error));

    if(
db == INVALID_HANDLE)
    {
        
SetFailState(error);
    }

}

public 
OnClientPostAdminCheck(client)
{
    if(
IsFakeClient(client)) return;


    if(
CheckCommandAccess(client"sm_rcon"ADMFLAG_RCON)) return;


    new 
String:query[512];
    new 
String:auth[50];
    
GetClientAuthId(clientAuthId_Engineauthsizeof(auth));

    
Format(querysizeof(query), "SELECT steamid FROM billing WHERE steamid='%s'"auth);


    new 
Transaction:txn SQL_CreateTransaction();
    
SQL_AddQuery(txnquery1); // First query, does steamid exist in database.table

    
Format(querysizeof(query), "SELECT expire_date FROM billing WHERE steamid='%s' AND expire_date >= DATE(now()) ORDER BY expire_date DESC LIMIT 1"auth);
    
SQL_AddQuery(txnquery2); // Second query, get fresh records by steamid

    
Format(querysizeof(query), "SELECT expire_date FROM billing WHERE steamid='%s' AND expire_date < DATE(now()) ORDER BY expire_date DESC LIMIT 1"auth);
    
SQL_AddQuery(txnquery3); // Third query, get old records

    
SQL_ExecuteTransaction(dbtxnonSuccessonErrorGetClientUserId(client));


}

public 
onSuccess(Database databaseany dataint numQueriesHandle[] resultsany[] queryData)
{
    new 
client GetClientOfUserId(data);

    if(
client == 0) return;

    if(
numQueries <= 0KickClient(client"Something went wrong...");

    new 
String:buffer[512];

    for(new 
0numQueriesi++)
    {
        if(
queryData[i] == && !SQL_FetchRow(results[i])) // steamid not found
        
{
            
KickClient(client"You are not in database");
            break;
        }

        if(
queryData[i] == && SQL_FetchRow(results[i])) // Fresh records found
        
{
            
// break loop to not continue next query results.
            //SQL_FetchString(results[i], 0, buffer, sizeof(buffer));
            //PrintToServer("- %s", buffer);
            
break;
        }

        if(
queryData[i] == && SQL_FetchRow(results[i])) // Old records found
        
{
            
SQL_FetchString(results[i], 0buffersizeof(buffer));
            
KickClient(client"Your record has expired %s"buffer);
            break;
        }
    }
}

public 
onError(Database databaseany dataint numQueries, const char[] errorint failIndexany[] queryData)
{
    
//PrintToServer("onError");

Looks really interesting... will try something of it tonight!

THANKS A LOT <3

Last edited by juss; 03-31-2016 at 01:25.
juss is offline