Raised This Month: $32 Target: $400
 8% 

Solved [CSGO] Steamid check.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DazhLarsson
Junior Member
Join Date: Dec 2012
Location: Denmark
Old 01-24-2020 , 21:58   [CSGO] Steamid check.
Reply With Quote #1

Why isnt this working for me?
No errors, just dont work, i dont get kicked when i join the server, and my steamid isnt in the database :s?

#pragma semicolon 1

#define DEBUG

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

Database hDatabase = null;

public Plugin myinfo =
{
name = "Database test",
author = "Morten",
description = "database tester",
version = "1.0",
url = "none"
};

public void OnPluginStart()
{
Database.Connect(GotDatabase);
}


public void GotDatabase(Database db, const char[] error, any data)
{
if (db == null)
{
LogError("Database failure: %s", error);
}
else
{
hDatabase = db;
}
}

public void CheckSteamID(int userid, const char[] auth)
{
char query[255];
FormatEx(query, sizeof(query), "SELECT steamid FROM player WHERE steamid = '%s'", auth);
hDatabase.Query(T_CheckSteamID, query, userid);
}

public void T_CheckSteamID(Database db, DBResultSet results, const char[] error, any data)
{
int client = 0;

/* Make sure the client didn't disconnect while the thread was running */
if ((client = GetClientOfUserId(data)) == 0)
{
return;
}

if (results == null)
{
LogError("Query failed! %s", error);
KickClient(client, "Authorization failed");
} else if (results.RowCount == 0) {
KickClient(client, "You are not a member");
}
}

Last edited by DazhLarsson; 01-25-2020 at 15:57.
DazhLarsson is offline
Balimbanana
Member
Join Date: Jan 2017
Old 01-25-2020 , 01:38   Re: [CSGO] Steamid check.
Reply With Quote #2

It might depend on when CheckSteamID is being called. If you need to check SteamID's, I think the earliest you can check is by the forward:
Code:
public void OnClientAuthorized(int client, const char[] auth)
Then call CheckSteamID inside OnClientAuthorized.
Could also check what ID is being returned by having a PrintToServer("CheckSteamID %s",auth); inside CheckSteamID to see if it retrieved correctly.

Last edited by Balimbanana; 01-25-2020 at 01:42. Reason: public void
Balimbanana is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-25-2020 , 08:21   Re: [CSGO] Steamid check.
Reply With Quote #3

Use PHP tags for code examples.
What is CheckSteamID function?
Use OnClientPostAdminCheck function instead of CheckSteamID
__________________
Ilusion9 is offline
DazhLarsson
Junior Member
Join Date: Dec 2012
Location: Denmark
Old 01-25-2020 , 14:22   Re: [CSGO] Steamid check.
Reply With Quote #4

I tried this, but i get the error: Exception reported: Error fetching data from field 1
whyyyyyyy

PHP Code:
#pragma semicolon 1

#define DEBUG

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

char dbconfig[] = "MyDB";
Database g_DB;

public 
Plugin myinfo =
{
name "Database test",
author "Morten",
description "database tester",
version "1.0",
url "none"
};

public 
void OnPluginStart()
{
    
char error[255];
    
g_DB SQL_Connect(dbconfigtrueerrorsizeof(error));
    
SQL_SetCharset(g_DB"utf8");
    
RegConsoleCmd("sm_Morten"Morten);
}

public 
Action Morten(int clientint args)
{
char query[255], steamid[32];
GetClientAuthId(clientAuthId_Steam2,steamidsizeof(steamid) );
FormatEx(querysizeof(query), "SELECT steamid FROM player WHERE steamid = '%s'"steamid);
SQL_TQuery(g_DBMortenCallBackqueryclient);
PrintToChatAll("Test 1");
return 
Plugin_Handled;
}



public 
void MortenCallBack(Handle ownerHandle hndl, const char[] errorany data)
{
    
char p1[128];
    
char p2[128];
    
char p3[64];
    while (
SQL_FetchRow(hndl)) {
        
SQL_FetchString(hndl1p1sizeof(p1));
        
SQL_FetchString(hndl2p2sizeof(p2));
        
SQL_FetchString(hndl3p3sizeof(p3));
        
PrintToChatAll("Database : %s"p1);
}

DazhLarsson is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-25-2020 , 15:12   Re: [CSGO] Steamid check.
Reply With Quote #5

Because you get only one field in (you are selecting only only steamid):
PHP Code:
SELECT steamid FROM player WHERE steamid '%s' 
and you are fetching 3 fields:
PHP Code:
        SQL_FetchString(hndl1p1sizeof(p1));
        
SQL_FetchString(hndl2p2sizeof(p2));
        
SQL_FetchString(hndl3p3sizeof(p3)); 
Also, the first field has index 0.
Do this:

PHP Code:

public void MortenCallBack(Database dbDBResultSet rs, const char[] errorany data)
{
    if (!
rs)  return;

    
char steamid[65];
    if (
rs.FetchRow())
    {
        
rs.FetchString(0steamidsizeof(steamid));
        
PrintToChatAll("Database : %s"steamid);
    }

__________________

Last edited by Ilusion9; 01-25-2020 at 15:12.
Ilusion9 is offline
DazhLarsson
Junior Member
Join Date: Dec 2012
Location: Denmark
Old 01-25-2020 , 15:27   Re: [CSGO] Steamid check.
Reply With Quote #6

Thx for the answer, but should i do if i want to Fetch the index 2 field?
DazhLarsson is offline
Balimbanana
Member
Join Date: Jan 2017
Old 01-25-2020 , 15:41   Re: [CSGO] Steamid check.
Reply With Quote #7

Select all columns with:
Code:
FormatEx(query, sizeof(query), "SELECT * FROM player WHERE steamid = '%s'", steamid);
Then do the while (SQL_FetchRow(hndl)) and start from index 0. Unless index 0 is the steamid column, in which case, you could probably skip 0.

If there are a lot of columns, and you only want a few specific ones, then you should probably set up:
Code:
Transaction SQL_CreateTransaction()
int SQL_AddQuery(Transaction txn, const char[] query, any data)
void SQL_ExecuteTransaction(Handle db, Transaction txn, SQLTxnSuccess onSuccess, SQLTxnFailure onError, any data, DBPriority priority)
Balimbanana is offline
DazhLarsson
Junior Member
Join Date: Dec 2012
Location: Denmark
Old 01-25-2020 , 15:56   Re: [CSGO] Steamid check.
Reply With Quote #8

Thank you<3333
DazhLarsson 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 20:39.


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