AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Sourcemod member authorisation (https://forums.alliedmods.net/showthread.php?t=75599)

Corrosive 08-08-2008 19:03

Sourcemod member authorisation
 
Hi there,

I have a database with a member table which contains the fields: playername, steamid and ipadress.

Is there a script which authorizes joining players by these fields? When they are not authorized they should be kicked out with a kickmessage something like "you're not a member, please register!"

Thanks in advance,

Joost.

Corrosive 08-08-2008 22:06

Re: Sourcemod member authorisation
 
We're trying it with the following code, but it isn't really responding :|

PHP Code:

#include <sourcemod>
 
public Plugin:myinfo =
{
 
name "Authentication",
 
author " ",
 
description "Client Authentication",
 
version "1.0.0.0",
 
url " "
};
 
public 
OnPluginStart()
{
}
 
new 
Handle:hDatabase INVALID_HANDLE;
StartSQL()
{
 
SQL_TConnect(GotDatabase);
}
 
public 
GotDatabase(Handle:ownerHandle:hndl, const String:error[], any:data)
{
 if (
hndl == INVALID_HANDLE)
 {
  
LogError("Database failure: %s"error);
 } else {
  
hDatabase hndl;
 }
}

CheckSteamID(userid, const String:auth[], maxstrlen)
{
 
decl String:query[255];
 
Format(querysizeof(query), "SELECT steamid FROM cpay_users WHERE steamid = '%s'"auth);
 
SQL_TQuery(hdatabaseT_CheckSteamIDqueryuserid)
}
 
public 
T_CheckSteamID(Handle:ownerHandle:hndl, const String:error[], any:data)
{
 new 
client;
 
 
/* Make sure the client didn't disconnect while the thread was running */
 
if ((client GetClientOfUserId(data)) == 0)
 {
  return;
 }
 
 if (
hndl == INVALID_HANDLE)
 {
  
LogError("Query failed! %s"error);
  
KickClient(client"Authorization failed");
 } else if (!
SQL_GetRowCount(hndl)) {
  
KickClient(client"You are not a member");
 }


Pleeeaase help us out here!!

Nican 08-09-2008 00:20

Re: Sourcemod member authorisation
 
You defined the function "StartSQL", but you never called it...
The plugin never gets connected to the database.

Put it like this:
PHP Code:

public OnPluginStart()
{
   
StartSQL();



Corrosive 08-09-2008 07:11

Re: Sourcemod member authorisation
 
Nice, that resolved one problem with compiling! Thnx man!


Still having 2 errors now..

/home/groups/sourcemod/upload_tmp/phpJaSUZW.sp(69) : warning 203: symbol is never used: "CheckSteamID"

/home/groups/sourcemod/upload_tmp/phpJaSUZW.sp(36) : warning 204: symbol is assigned a value that is never used: "hDatabase"

What seams to be te problem here? Am i doing something really stupid, or should this work fine in-game?

bl4nk 08-09-2008 07:49

Re: Sourcemod member authorisation
 
You need to use your CheckSteamID function somewhere. I suggest putting it inside of OnClientAuthorized(client), just like you did with the StartSQL function for OnPluginStart.

Corrosive 08-09-2008 09:49

Re: Sourcemod member authorisation
 
Quote:

Originally Posted by bl4nk (Post 666909)
You need to use your CheckSteamID function somewhere. I suggest putting it inside of OnClientAuthorized(client), just like you did with the StartSQL function for OnPluginStart.


Hmmm, could you give me an example? I'm not sure how to do this exactly..

The following code is used at the moment:

PHP Code:

#include <sourcemod>
 
public Plugin:myinfo =
{
 
name "Authentication",
 
author " ",
 
description "Client Authentication",
 
version "1.0.0.0",
 
url " "
};
 
public 
OnPluginStart()
{
 
StartSQL()
}

public 
OnClientAuthorized(client)
{
 
CheckSteamID()
}
 

new 
Handle:hDatabase INVALID_HANDLE;
StartSQL()
{
 
SQL_TConnect(GotDatabase);
}
 
public 
GotDatabase(Handle:ownerHandle:hndl, const String:error[], any:data)
{
 if (
hndl == INVALID_HANDLE)
 {
  
LogError("Database failure: %s"error);
 } else {
  
hDatabase hndl;
 }
}

CheckSteamID(userid, const String:auth[], maxstrlen)
{
 
decl String:query[255];
 
Format(querysizeof(query), "SELECT steamid FROM cpay_users WHERE steamid = '%s'"auth);
 
SQL_TQuery(hdatabaseT_CheckSteamIDqueryuserid)
}
 
public 
T_CheckSteamID(Handle:ownerHandle:hndl, const String:error[], any:data)
{
 new 
client;
 
 
/* Make sure the client didn't disconnect while the thread was running */
 
if ((client GetClientOfUserId(data)) == 0)
 {
  return;
 }
 
 if (
hndl == INVALID_HANDLE)
 {
  
LogError("Query failed! %s"error);
  
KickClient(client"Authorization failed");
 } else if (!
SQL_GetRowCount(hndl)) {
  
KickClient(client"You are not a member");
 }


Am i doing this the right way? It is giving the following errors:

/home/groups/sourcemod/upload_tmp/phpxA2sKr.sp(24) : error 092: number of arguments does not match definition
/home/groups/sourcemod/upload_tmp/phpxA2sKr.sp(53) : error 017: undefined symbol "hdatabase"
/home/groups/sourcemod/upload_tmp/phpxA2sKr.sp(44) : warning 204: symbol is assigned a value that is never used: "hDatabase"

2 Errors.



Any suggestions on how to get this script working?

Thnx in advance!

Lebson506th 08-09-2008 10:57

Re: Sourcemod member authorisation
 
Code:

forward OnClientAuthorized(client, const String:auth[]);
Use the Sourcemod API to see proper use of functions.

http://docs.sourcemod.net/api/

Also, rename "hdatabase" to "hDatabase"

in
PHP Code:

CheckSteamID(userid, const String:auth[], maxstrlen)
{
 
decl String:query[255];
 
Format(querysizeof(query), "SELECT steamid FROM cpay_users WHERE steamid = '%s'"auth);
 
SQL_TQuery(hdatabaseT_CheckSteamIDqueryuserid)



bl4nk 08-09-2008 12:48

Re: Sourcemod member authorisation
 
PHP Code:

#include <sourcemod>

new Handle:hDatabase INVALID_HANDLE;

public 
Plugin:myinfo =
{
 
name "Authentication",
 
author " ",
 
description "Client Authentication",
 
version "1.0.0.0",
 
url " "
};

public 
OnPluginStart()
{
    
StartSQL()
}

public 
OnClientAuthorized(client)
{
    
decl String:auth[32];
    
GetClientAuthString(clientauthsizeof(auth));

    
CheckSteamID(clientauth)
}

public 
GotDatabase(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("Database failure: %s"error);
    }
    else
    {
        
hDatabase hndl;
    }
}

public 
T_CheckSteamID(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    
/* Make sure the client didn't disconnect while the thread was running */
    
if (!IsClientConnected(client))
    {
        return;
    }

    if (
hndl == INVALID_HANDLE)
    {
        
LogError("Query failed! %s"error);
        
KickClient(client"Authorization failed");
    }
    else if (!
SQL_GetRowCount(hndl))
    {
        
KickClient(client"You are not a member");
    }
}

StartSQL()
{
    
SQL_TConnect(GotDatabase);
}

CheckSteamID(userid, const String:auth[])
{
    
decl String:query[255];
    
Format(querysizeof(query), "SELECT steamid FROM cpay_users WHERE steamid = '%s'"auth);
    
SQL_TQuery(hDatabaseT_CheckSteamIDqueryuserid)



Corrosive 08-10-2008 18:59

Re: Sourcemod member authorisation
 
SWEET! :) it's working!!

Big up for mr. bl4nk :up:

Lebson506th 07-12-2011 16:01

Re: Sourcemod member authorisation
 
The one that bl4nk posted 2 above you is only for Steam ID


All times are GMT -4. The time now is 21:31.

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