PHP Code:
new Handle:db;
public OnPluginStart()
{
new String:error[512];
db = SQL_Connect("Mysql_SteamID_Check", true, error, sizeof(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(client, AuthId_Engine, auth, sizeof(auth));
Format(query, sizeof(query), "SELECT steamid FROM billing WHERE steamid='%s'", auth);
new Transaction:txn = SQL_CreateTransaction();
SQL_AddQuery(txn, query, 1); // First query, does steamid exist in database.table
Format(query, sizeof(query), "SELECT expire_date FROM billing WHERE steamid='%s' AND expire_date >= DATE(now()) ORDER BY expire_date DESC LIMIT 1", auth);
SQL_AddQuery(txn, query, 2); // Second query, get fresh records by steamid
Format(query, sizeof(query), "SELECT expire_date FROM billing WHERE steamid='%s' AND expire_date < DATE(now()) ORDER BY expire_date DESC LIMIT 1", auth);
SQL_AddQuery(txn, query, 3); // Third query, get old records
SQL_ExecuteTransaction(db, txn, onSuccess, onError, GetClientUserId(client));
}
public onSuccess(Database database, any data, int numQueries, Handle[] results, any[] queryData)
{
new client = GetClientOfUserId(data);
if(client == 0) return;
if(numQueries <= 0) KickClient(client, "Something went wrong...");
new String:buffer[512];
for(new i = 0; i < numQueries; i++)
{
if(queryData[i] == 1 && !SQL_FetchRow(results[i])) // steamid not found
{
KickClient(client, "You are not in database");
break;
}
if(queryData[i] == 2 && 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] == 3 && SQL_FetchRow(results[i])) // Old records found
{
SQL_FetchString(results[i], 0, buffer, sizeof(buffer));
KickClient(client, "Your record has expired %s", buffer);
break;
}
}
}
public onError(Database database, any data, int numQueries, const char[] error, int failIndex, any[] queryData)
{
//PrintToServer("onError");
}