View Single Post
vijayar
Senior Member
Join Date: Sep 2020
Old 06-07-2021 , 03:23   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #8

Hi,

I need help in creating a plugin. I am not a dev so anything that you ask me to do from a dev perspective will go over my head !

I am in particular looking at a plugin that will check if a connecting player STEAMID is in a DB and if not it disconnects him with a message. If the player's STEAMID is in DB it will further check if his subscription validity date is not expired (when I add the player on DB it will have date column with the "subscription valid till" date).So if the current date is beyond this expiry date it will again disconnect the player and show the message that his access is expired.

I did come across this post, https://forums.alliedmods.net/showthread.php?t=280933 I guess the coding is in bits and pieces.

Your plugin listed here is on same line. Would it be possible to guide me in getting this done correctly ?

I tried doing some scripting with the available scripts (this post and the post I have linked to) & my very very limited knowledge of Sourcepawn ; I have and reached here

PHP Code:
#pragma tabsize 0
#include <sourcemod>
#define PLUGIN_VERSION    "1.0"

new Handle:db INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "Subscription Check",
    
version "1.0",
};

public 
OnPluginStart()
{
    
SQL_TConnect(SQL_OnConnect"idchk");
}

public 
SQL_OnConnect(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("Error connecting to the database: %s"error);
    }
    else
    {
        
db hndl;
        
PrintToServer("Connection successful");
    }
}

public 
OnClientPostAdminCheck(client)
{
    if(
IsClientInGame(client)&&!IsFakeClient(client)) return;

    if(
CheckCommandAccess(client"sm_rcon"ADMFLAG_RCON)) return;
    
    {
        new 
String:steamid[20];
        
GetClientAuthId(clientsteamidsizeof(steamid));
        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");

On Compiling, i get the following errors

PHP Code:
Compiling idchk.sp...
SourcePawn Compiler 1.10.0.6502
Copyright 
(c1997-2006 ITB CompuPhase
Copyright 
(c2004-2018 AlliedModders LLC

idchk
.sp(39) : error 035argument type mismatch (argument 2)
idchk.sp(39) : error 035argument type mismatch (argument 3)
idchk.sp(40) : warning 204symbol is assigned a value that is never used"query"
idchk.sp(45) : error 017undefined symbol "query"
idchk.sp(45) : error 072"sizeof" operator is invalid on "function" symbols
idchk
.sp(48) : error 017undefined symbol "query"
idchk.sp(50) : error 017undefined symbol "query"
idchk.sp(50) : error 072"sizeof" operator is invalid on "function" symbols
idchk
.sp(51) : error 017undefined symbol "query"
idchk.sp(53) : error 017undefined symbol "query"
idchk.sp(53) : error 072"sizeof" operator is invalid on "function" symbols
idchk
.sp(54) : error 017undefined symbol "query"

11 Errors
Appreciate any help to complete this.

I assume I have to create a mysql db and add the user details, manually for this plugin to connect to check & do its stuff.

Last edited by vijayar; 06-07-2021 at 03:28.
vijayar is offline