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

Solved How to ignore the first 8 Characters when comparing two STEAMID32


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vijayar
Senior Member
Join Date: Sep 2020
Old 07-01-2021 , 02:39   How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #1

I need help in resolving a nagging issue in this plugin - https://forums.alliedmods.net/showthread.php?t=286965

This issue occurs due to the mismatch when comparing user with "STEAM_0:0:12345" that is stored in the database & when the same user joins CSGO server, the ID converts to "STEAM_1:0:12345", fails the database check.

I understand that STEAM_0 or STEAM_1 prefix depends on the game and also the first 8 characters of can be ignored, when comparing 2 STEAMID32.

Can someone help in resolving this.

Specifically need it in the part of script that compares connecting client to the mysql database

PHP Code:
//Checks if the SteamID is in the database, if not the player will get kicked.
public void SQL_CheckSteamID(Handle ownerDBResultSet results, const char[] errorany data)
{
    
int client GetClientOfUserId(data); 
    if (
client == || !IsClientConnected(client)) return; //connected check if not found do return
    
if (results == null || strlen(error) > 0)
    {
        
LogError("[Mysql-Whitelist] Query failed! %s"error);
        
KickClient(client"Authorization failed, please try again later.");
    }
    else if(
results.RowCount == 0)
    {
        
PrintToServer(client"User ID in Database is: %d"GetClientOfUserId(userid)); 
        
KickClient(client"You are not allowed to join this server");
    }

Complete source code is attached FYI
Attached Files
File Type: sp Get Plugin or Get Source (simple_mysql_whitelister.sp - 164 views - 22.0 KB)

Last edited by vijayar; 07-06-2021 at 01:31. Reason: SOLVED
vijayar is offline
little_froy
Senior Member
Join Date: May 2021
Old 07-01-2021 , 10:07   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #2

try
strcmp(STEAMID1[8], STEAMID2[8])
it means compare start from the NINE (from 0 to 8 )character ↓
S T E A M _ 1 : 0 : 1 2 3 4 5
0 1 2 3 4 5 6 7 8

Last edited by little_froy; 07-01-2021 at 10:13.
little_froy is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-02-2021 , 01:30   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #3

I guess the database contains the "STEAM_0:0:" part? would be more efficient and optimized to completely remove "STEAM_0:0:" from the database and skip saving that part, reading that part etc. Then you can query from SteamID[8] like little_froy mentioned. Maybe you can just query from SteamID[8] position anyway using a partial matching sql query like "%12345" or something.

Something like:
PHP Code:
Format(querysizeof(query), "SELECT steamid FROM %s WHERE steamid = '\%%s'"DB_Nameisteamid[8]); 
Don't know if % needs escaping or not, or maybe %%. Been a while since I used percent in format.
__________________

Last edited by Silvers; 07-02-2021 at 01:32.
Silvers is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 07-02-2021 , 04:19   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #4

Quote:
Originally Posted by little_froy View Post
try
strcmp(STEAMID1[8], STEAMID2[8])
it means compare start from the NINE (from 0 to 8 )character ↓
S T E A M _ 1 : 0 : 1 2 3 4 5
0 1 2 3 4 5 6 7 8
Thanks for your help, I did come across this command but not sure where in the script should I insert this.

Last edited by vijayar; 07-02-2021 at 04:21.
vijayar is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 07-02-2021 , 04:21   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #5

Quote:
Originally Posted by Silvers View Post
I guess the database contains the "STEAM_0:0:" part? would be more efficient and optimized to completely remove "STEAM_0:0:" from the database and skip saving that part, reading that part etc. Then you can query from SteamID[8] like little_froy mentioned. Maybe you can just query from SteamID[8] position anyway using a partial matching sql query like "%12345" or something.

Something like:
PHP Code:
Format(querysizeof(query), "SELECT steamid FROM %s WHERE steamid = '\%%s'"DB_Nameisteamid[8]); 
Don't know if % needs escaping or not, or maybe %%. Been a while since I used percent in format.
Thanks for your help, partial matching query did not work.

Somewhow this should have been a simple match and continue. Bit frustating that the plugin only works when stored with STEAM_1 prefix. Unfortunately the plugin dev has not sorted this out and has retired from sourcemod work

Last edited by vijayar; 07-02-2021 at 04:24.
vijayar is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-02-2021 , 04:29   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #6

Try putting it like '\%%s\%' maybe it needs % on either side of the query. Been a while since I used mysql.
__________________
Silvers is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 07-02-2021 , 11:41   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #7

Quote:
Originally Posted by Silvers View Post
Try putting it like '\%%s\%' maybe it needs % on either side of the query. Been a while since I used mysql.
Didnt work. Just to clarify (I am sourcemod noob/beginner btw) I am changing it the two places where Format command is being used. NOt sure if i am doing the right stuff.

This is the part of the script where connecting client is checked if admin or in the database and then processed accordingly

PHP Code:
//Check Player Access First Check!
public void OnClientAuthorized(int client, const char[] SteamID)
{
    if (
IsFakeClient(client)) return; //Allow bots to skip this check.
    
AdminId Admin FindAdminByIdentity(AUTHMETHOD_STEAMSteamID);
    if (
AdmFlag != && GetAdminFlags(AdminAccess_Effective) & AdmFlag) return;

    
//Start Checking
    //Send a check query to the database to see if the user is in the database.
    
char query[256];
    
Format(querysizeof(query), "SELECT steamid FROM %s WHERE steamid = 's%'"DB_NameSteamID);
    
db.Query(SQL_CheckSteamIDqueryGetClientUserId(client), DBPrio_High);
}

//Double Check our client, just incase person randomly somehow bypassed OnClientAuthorized check.
public void OnClientPostAdminCheck(int client)
{
    if (!
IsValidClient(client) || IsFakeClient(client)) return;
    
    
//Do Same check as in OnClientAuthorized, just different method.
    
char isteamid[64];
    if(
GetClientAuthId(clientAuthId_Steam2isteamidsizeof(isteamid)))
    {
        if(
AdmFlag != && CheckAdmFlag(client)) return; //If Admin with Adm flag, Skip check.

        //Start Checking
        //Send a check query to the database to see if the user is in the database.
        
char query[256];
        
Format(querysizeof(query), "SELECT steamid FROM %s WHERE steamid = 's%'"DB_Nameisteamid);
        
db.Query(SQL_CheckSteamIDqueryGetClientUserId(client), DBPrio_High);
    }
    else 
KickClient(client"Please retry connecting!"); //Tell clients to retry.
}

//Checks if the SteamID is in the database, if not the player will get kicked.
public void SQL_CheckSteamID(Handle ownerDBResultSet results, const char[] errorany data)
{
    
int client GetClientOfUserId(data); 
    if (
client == || !IsClientConnected(client)) return; //connected check if not found do return
    
if (results == null || strlen(error) > 0)
    {
        
LogError("[Mysql-Whitelist] Query failed! %s"error);
        
KickClient(client"Authorization failed, please try again later.");
    }
    else if(
results.RowCount == 0)
    {
        
//PrintToServer(client, "User ID in Database is: %d", GetClientOfUserId(userid)); 
        
KickClient(client"You are not allowed to join this server");
    }


Last edited by vijayar; 07-02-2021 at 11:41.
vijayar is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-02-2021 , 12:09   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #8

Change 's%' to '\%%s\%'
__________________
Silvers is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-04-2021 , 09:31   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #9

Not 100% sure, haven't tested
https://www.w3schools.com/sql/sql_like.asp



Code:
if string is like this, isteamid[8]

"SELECT steamid FROM %s WHERE steamid LIKE '\%%s'" // Is like %1:12345

or

"SELECT steamid FROM %s WHERE steamid LIKE '________%s'" // Is like ________1:12345
__________________
Do not Private Message @me

Last edited by Bacardi; 07-04-2021 at 11:22.
Bacardi is offline
vijayar
Senior Member
Join Date: Sep 2020
Old 07-06-2021 , 01:28   Re: How to ignore the first 8 Characters when comparing two STEAMID32
Reply With Quote #10

Quote:
Originally Posted by Bacardi View Post
Not 100% sure, haven't tested
https://www.w3schools.com/sql/sql_like.asp



[code]
if string is like this, isteamid[8]

"SELECT steamid FROM %s WHERE steamid LIKE '\%%s'" // Is like %1:12345

or

"SELECT steamid FROM %s WHERE steamid LIKE '________%s'" // Is like ________1:12345

Thank you so much ! this worked!!!

PHP Code:
"SELECT steamid FROM %s WHERE steamid LIKE '________%s'" 
vijayar is offline
Reply



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 10:25.


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