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

[Need help] Check if connecting client's steamid is in database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mooni
SourceMod Donor
Join Date: Dec 2012
Location: Sweden
Old 01-30-2013 , 06:56   [Need help] Check if connecting client's steamid is in database
Reply With Quote #1

Okey, lets jump right in to it.

Im kinda new to coding overall. (made some minecraft bukkit plugins(java) and also some kind of 2d java game about 6-8 moths ago.)

And i started trying with sourcepawn about 1 month ago and after searching the forum, api and wiki, and whatching some youtube tuts I desided to ask for help.

I think it is pretty simple,
when client connect it checks if his steamid is in the database and if it is he gets the 2 admin flags, if not it checks if he got the 2 flags and if he do it removes them.

(It's for Counter-Strike: Source)

Here is what i currently got:
PHP Code:
#include <sourcemod>

#define PLUGIN_VERSION    "1.0"

new Handle:DB INVALID_HANDLE;

public 
Plugin:myinfo = {
    
name "VipReload",
    
author "Mooni",
    
description "Vip Reload Plugin",
    
version PLUGIN_VERSION,
    
url "www.ggaming.se"
};

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

public 
OnClientConnect(client)
{
//I think something like: if(steamid == DBsteamid)
    /**
    new String:steamid[32];
    GetClientAuthString(client, steamid, 32);
    
    if(steamid == hQuery)
    {
        SetAdminFlag(steamid, ADMFLAG_CUSTOM6);
        SetAdminFlag(steamid, ADMFLAG_RESERVATION);
    }
    **/
}

GetSomeInfo(Handle:DB, const String:name[], client)
{
    new 
Handle:hQuery
    
new String:query[200]
    
    
/* Create enough space to make sure our string is quoted properly  */
    
new buffer_len strlen(name) * 1
    
new String:new_name[buffer_len]
    
    
/* Ask the SQL driver to make sure our string is safely quoted */
    
SQL_QuoteString(DBnamenew_namebuffer_len);
    
    
/* Build the query */
    
Format(querysizeof(query), "SELECT steamid FROM viplist");
    
    
/* Execute the query */
    
if ((hQuery SQL_Query(query)) == INVALID_HANDLE)
    {
        return 
0
    
}
    
/* Get some info here */
    
DBsteamid SQL_FetchRow(hQuery)
    
    
CloseHandle(hQuery)

And im pretty sure i got the databases.cfg setup right but here it is anyway:
Code:
	"VipPlugin"
	{
		"driver"			"default"
		"host"				"my host ip"
		"database"			"my db"
		"user"				"my db user"
		"pass"				"my db user pw"
		//"timeout"			"0"
		"port"			"3306"
	}

Last edited by Mooni; 01-30-2013 at 07:04. Reason: (It's for Counter-Strike: Source)
Mooni is offline
ecca
Sexy Santa
Join Date: Jan 2011
Old 01-30-2013 , 07:44   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #2

Threaded querys is much better. Anyway try this one

PHP Code:
#pragma semicolon 1
#include <sourcemod>

new Handle:db INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "VIP",
    
author "ecca",
    
description "",
    
version "1.0",
    
url ""
};

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

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))
    {
        new 
String:steamid[20];
        
GetClientAuthString(clientsteamidsizeof(steamid));
        
        new 
String:query[1024];
        
FormatEx(querysizeof(query),  "SELECT * FROM viplist WHERE steamid='%s'"steamid);
        
        
SQL_TQuery(dbCheckVIPqueryclient);
    }
}

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

    if    (
SQL_FetchRow(hndl))
    {
        new 
AdminId:admin CreateAdmin("VIP");
        
SetAdminFlag(adminAdmin_Reservationtrue);
        
SetAdminFlag(adminAdmin_Custom6true);
        
SetUserAdmin(clientadmin);
    }


Last edited by ecca; 01-30-2013 at 07:45.
ecca is offline
Mooni
SourceMod Donor
Join Date: Dec 2012
Location: Sweden
Old 01-30-2013 , 09:03   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #3

Thx ecca!
Just some small problems, if the connecting client have other admin flags and is in the database the client only have those 2 flags untill he is not in the db anymore or untill a sm_reloadadmins.

Last edited by Mooni; 01-30-2013 at 09:05.
Mooni is offline
ecca
Sexy Santa
Join Date: Jan 2011
Old 01-30-2013 , 09:29   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #4

This will just add some temporary flags i think, so try this one out instead.

PHP Code:
#pragma semicolon 1
#include <sourcemod>

new Handle:db INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "VIP",
    
author "ecca",
    
description "",
    
version "1.0",
    
url ""
};

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

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))
    {
        new 
String:steamid[20];
        
GetClientAuthString(clientsteamidsizeof(steamid));
        
        new 
String:query[1024];
        
FormatEx(querysizeof(query),  "SELECT * FROM viplist WHERE steamid='%s'"steamid);
        
        
SQL_TQuery(dbCheckVIPqueryclient);
    }
}

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

    if    (
SQL_FetchRow(hndl))
    {
        new 
clientFlags 0;
        
clientFlags GetUserFlagBits(client);
        
clientFlags |= ADMFLAG_RESERVATION|ADMFLAG_CUSTOM6;
        
SetUserFlagBits(clientclientFlags);
    }

ecca is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 01-30-2013 , 09:40   [Need help] Check if connecting client's steamid is in database
Reply With Quote #5

What's wrong with SourceMod's built-in admin system?
__________________
Dr. McKay is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 01-30-2013 , 09:46   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #6

Like ecca said, threaded queries are the best you can do, although i have some suggestions.
It's important that you don't pass clientindexes to asynchronous callbacks like this one.
Either use getclientserial/getclientfromserial; getclientuserid/getclientofuserid or fetch the steamid in the callback and find the client with the steamid.
If you only want to check if an row with this steamid exists i guess something like this is faster.
Spoiler


Yours sincerey
Impact
__________________

Last edited by Impact123; 01-30-2013 at 10:49.
Impact123 is offline
Mooni
SourceMod Donor
Join Date: Dec 2012
Location: Sweden
Old 01-30-2013 , 10:20   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #7

Quote:
Originally Posted by Dr. McKay View Post
What's wrong with SourceMod's built-in admin system?
It's for a automatic 1 month vip access.
And i want my admins to be able to buy vip too, and with sourcebans they only have vip on the server they are admin on.

Edit:
Quote:
Originally Posted by Impact123 View Post
Like ecca said, threaded queries are the best you can do, although i have some suggestions.
It's important that you don't pass clientindexes to asynchronous callbacks like this one.
Either use getclientserial/getclientfromserial; getclientuserid/getclientofuserid or fetch the steamid in the callback and find the client with the steamid.
If you only want to check if an row with this steamid exists i guess something like this is faster.
Spoiler


Yours sincerey
Impact
Are you talking about ecca's or my code and if you talking about ecca's then i cant see whats wrong with it so please describe and try to use less terms so i can understand :s

However the second code that ecca posted worked perfect and this is now solved if im not terrible wrong.

Last edited by Mooni; 01-31-2013 at 01:05.
Mooni is offline
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
canadianjeff
BANNED
Join Date: Sep 2016
Old 06-08-2021 , 15:24   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #9

is this like a pay to play on the server type plugin? just curious
canadianjeff is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 06-09-2021 , 06:42   Re: [Need help] Check if connecting client's steamid is in database
Reply With Quote #10

Quote:
Originally Posted by canadianjeff View Post
is this like a pay to play on the server type plugin? just curious
more like register to play, subscription can be an addon
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 15:14.


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