Raised This Month: $12 Target: $400
 3% 

[HELP PLZ] Check if connecting client's steamid is in database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
juss
Senior Member
Join Date: Jan 2016
Old 03-28-2016 , 04:19   [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #1

Im trying to write plugin that checks if a connecting player steamid in DB and if not it kicks him and show a message, but if player steamid is in DB it will check if his date is not expired (when i add the player on DB it will have date column with the future date till the player can play on the server, think of it as a billing system) so if the date is < then current date it will kick the player and show the message that his steamid is expired

So far:

PHP Code:

#include <sourcemod>
#define PLUGIN_VERSION    "1.0"

new Handle:DB INVALID_HANDLE;

public 
Plugin:myinfo = {
    
name "Mysql_SteamID_Check",
    
author "juss",
    
description "[ANY] MySQL-T check if client's steam id in DB",
    
version PLUGIN_VERSION,
    
url "rullers.ru"
};

public 
OnPluginStart()
{
    new 
String:Error[70];
    
DB SQL_Connect("Mysql_SteamID_Check"trueErrorsizeof(Error));
    if(
DB == INVALID_HANDLE)
    {
        
PrintToServer("[ERROR] Cannot connect to MySQL Server: %s"Error);
        
CloseHandle(DB);
    }
    else
    {
        
PrintToServer("Connection Successful");
    }
}

public 
OnClientPostAdminCheck(client)
{
    if (
IsClientInGame(client) && !IsFakeClient(client))
    {
        new 
String:steamid[20];
        
GetClientAuthString(clientsteamidsizeof(steamid));
        
        new 
String:query[1024];
        
FormatEx(querysizeof(query),  "SELECT * FROM TABLE WHERE steamid='%s' LIMIT 1"steamid);
         
//didnt come up yet with right select query so this one ^ is just random
        
        
SQL_TQuery(dbMysqlCheckIDqueryclient);
    }
}

public 
MysqlCheckID(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("error: %s"error);
    }

    if    (
SQL_FetchRow(hndl))
    {
      
/////////////////////////////////////////////////////////////////////////////////////////////////////
      //from this i dont know how to manage
      //it supposed to check if steamid is in DB, next if steamid is in DB it will check if its expired, if expired it will kick the player and show the message. or else if steamid not in DB it will kick the player and show the message 
       
if(steamid == DBsteamid)
         { 
      if (
players steam id is not expired) { then player can connect to the server }
      else {  
then kick the player an show the message that his payed time is expired}
       }
      else 
      { if 
client steamid not  in DB then kick the player an show the message for examplethat his not register on this server and he can register on LINK}
     
/////////////////////////////////////////////////////////////////////////////////////////////////////////

    
}



from that im trying to make a simple billing system

thanks for the help! <3

Last edited by juss; 03-28-2016 at 07:25.
juss is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-30-2016 , 05:39   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #2

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");

__________________
Do not Private Message @me
Bacardi is offline
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
juss
Senior Member
Join Date: Jan 2016
Old 04-02-2016 , 07:33   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #4

Bacardi:

... had a busy week, but checked your script last night ..Man, It works just the way i wanted to! <3

THANKS again! you da Best!

Last edited by juss; 04-02-2016 at 07:33.
juss is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-02-2016 , 11:56   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #5

you'r welcome
__________________
Do not Private Message @me
Bacardi is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 04-28-2021 , 03:39   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #6

Was this released as a plugin anywhere ? Or should I just compile the above script and use it ? I am assuming this is with default mysql support ; does the script automatically create the database structure ? Would it be possible to use this for any Steam game
vijayar is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-28-2021 , 04:25   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #7

Quote:
Originally Posted by vijayar View Post
Was this released as a plugin anywhere ? Or should I just compile the above script and use it ? I am assuming this is with default mysql support ; does the script automatically create the database structure ? Would it be possible to use this for any Steam game
what is posted above is not a full plugin just snippets
__________________
8guawong is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 04-28-2021 , 05:42   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #8

Quote:
Originally Posted by 8guawong View Post
what is posted above is not a full plugin just snippets
I did realize, it is parts of script. Was it released as a full plugin or is the complete scripting available, anywhere ? I would like to use it in my servers

Last edited by vijayar; 04-28-2021 at 05:46.
vijayar is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-28-2021 , 11:57   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #9

Quote:
Originally Posted by vijayar View Post
I did realize, it is parts of script. Was it released as a full plugin or is the complete scripting available, anywhere ? I would like to use it in my servers
i do not know
but you can search here https://www.sourcemod.net/plugins.php to see if there are any plugins with the functionality you want
__________________
8guawong is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 05-13-2021 , 11:20   Re: [HELP PLZ] Check if connecting client's steamid is in database
Reply With Quote #10

Quote:
Originally Posted by 8guawong View Post
i do not know
but you can search here https://www.sourcemod.net/plugins.php to see if there are any plugins with the functionality you want
Nothing there !
vijayar is offline
Reply


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 21:54.


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