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

Solved Player data in not inserting into DB Corectly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-27-2019 , 16:57   Player data in not inserting into DB Corectly
Reply With Quote #1

The Table is creating corectly, but players are not insterted into db. Why?

Code:
PHP Code:
#define PLUGIN_AUTHOR "kRatoss & qSeek"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <vip_core>
#include <sdktools>

#pragma newdecls required


/*
: ADMIN GROUP
: LAST SEEN
: VIP GROUP
: LOGS
*/

Handle g_DB INVALID_HANDLE;

char     g_sSQLBuffer[3096],
        
g_sName[MAXPLAYERS 1][MAX_NAME_LENGTH],
        
g_sAdminGroup[MAXPLAYERS 1][MAX_NAME_LENGTH],
        
g_sVIPGroup[MAXPLAYERS 1][MAX_NAME_LENGTH],
        
g_sSteamID[MAXPLAYERS 1][64],
        
g_sLastSeen[MAXPLAYERS 1][64];
        

public 
Plugin myinfo 
{
    
name "Panel",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
SQL_TConnect(OnSQLConnect"tz_panel");
}

public 
int OnSQLConnect(Handle ownerHandle hndlchar [] errorany data)
{
    if(
hndl == INVALID_HANDLE)
    {
        
LogError("Database failure: %s"error);
        
SetFailState("Databases dont work. See in logs more info.");
    }
    else
    {
        
g_DB hndl;
        
        
Format(g_sSQLBuffersizeof(g_sSQLBuffer), \
        
"CREATE TABLE IF NOT EXISTS `tz_panel` (`playername` varchar(128) NOT NULL, `steamid` varchar(32) PRIMARY KEY NOT NULL, `last_seen` varchar(128) NOT NULL, `admin_group` varchar(128) NOT NULL, `vip_group` varchar(128) NOT NULL)");
        
        
SQL_TQuery(g_DBOnSQLConnectCallbackg_sSQLBuffer);
    }
}

public 
int OnSQLConnectCallback(Handle ownerHandle hndlchar [] errorany data)
{
    if(
hndl == INVALID_HANDLE)
    {
        
LogError("Query failure: %s"error);
        return;
    }
    
    for(
int client 1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client))
            
OnClientPostAdminCheck(client);
    }
}

void OnClientPostAdminCheck(int Client)
{
    
GetStrings(Client);
    
InsertIntoDataBase(Client);
    
UpdateGroups(Client);
}

void GetStrings(int Client)
{
    
char GroupName[32], VIPGroup[32], Name[32], SteamId[128], buffer[64];
    
    if(
CheckCommandAccess(Client"sm_admin"ADMFLAG_GENERICfalse))
    {
        
AdminId ClientAccess GetUserAdmin(Client);
        
        if(
ClientAccess)
        {
            
int AdminGroupsCount GetAdminGroupCount(ClientAccess);

            for (
int x 0AdminGroupsCountx++)
                
GetAdminGroup(ClientAccessxGroupNamesizeof(GroupName))
        }
    }
    
    if(
VIP_IsClientVIP(Client))
        
VIP_GetClientVIPGroup(ClientVIPGroupsizeof(VIPGroup));
        
    
GetClientName(ClientNamesizeof(Name));
    
GetClientAuthId(ClientAuthId_Steam2SteamIdsizeof(SteamId));
    
FormatTime(buffersizeof(buffer), "%e%B%G"GetTime());
     
    
strcopy(g_sAdminGroup[Client], sizeof(GroupName), GroupName);
    
strcopy(g_sVIPGroup[Client], sizeof(VIPGroup), VIPGroup);
    
strcopy(g_sName[Client], sizeof(Name), Name);
    
strcopy(g_sSteamID[Client], sizeof(SteamId), SteamId);
    
strcopy(g_sLastSeen[Client], sizeof(buffer), buffer);
}

void InsertIntoDataBase(int Client)
{
    
char query[255];
    
Format(querysizeof(query), "INSERT INTO tz_panel(playername, steamid, last_seen, admin_group, vip_group) VALUES('%s', '%s', '%s', '%s', '%s');"
                                
g_sName[Client], g_sSteamID[Client], g_sLastSeen[Client], g_sAdminGroup[Client], g_sVIPGroup[Client]);
    
SQL_TQuery(g_DBSaveSQLPlayerCallbackquery_);    
}

void UpdateGroups(int Client)
{
    
char query[255];
    
Format(querysizeof(query), "UPDATE tz_panel SET playername = '%s', last_seen = '%s', admin_group = '%s', vip_group = '%s' WHERE steamid = '%s';"
                                
g_sName[Client], g_sLastSeen[Client], g_sAdminGroup[Client], g_sVIPGroup[Client], g_sSteamID[Client]);
    
SQL_TQuery(g_DBSaveSQLPlayerCallbackquery_);    
}

public 
int SaveSQLPlayerCallback(Handle ownerHandle hndlchar [] errorany data)
{
    if(
hndl == INVALID_HANDLE)
        
LogError("Query failure: %s"error);

__________________

Last edited by kratoss1812; 07-31-2019 at 13:30.
kratoss1812 is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 07-27-2019 , 17:25   Re: Player data in not inserting into DB Corectly
Reply With Quote #2

Check your error logs. Also, you should check if the database is connected to yet (g_DB != INVALID_HANDLE) before running your query. If you are loading the plugin late, all OnClientPostAdminCheck have likely already fired, so you will want to add a late load check and run all valid clients through OnClientPostAdminCheck. I dont see anything that would keep it from firing otherwise.
__________________
ThatOneGuy is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 07-27-2019 , 17:38   Re: Player data in not inserting into DB Corectly
Reply With Quote #3

Escape values before inserting in query, or use Database.Format()
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-27-2019 , 17:42   Re: Player data in not inserting into DB Corectly
Reply With Quote #4

Quote:
Originally Posted by ThatOneGuy View Post
Check your error logs. Also, you should check if the database is connected to yet (g_DB != INVALID_HANDLE) before running your query. If you are loading the plugin late, all OnClientPostAdminCheck have likely already fired, so you will want to add a late load check and run all valid clients through OnClientPostAdminCheck. I dont see anything that would keep it from firing otherwise.
Nothing in logs
Will try, thanks
__________________
kratoss1812 is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 07-28-2019 , 05:13   Re: Player data in not inserting into DB Corectly
Reply With Quote #5

you should also use the databse methodmap I'm not sure if it's better performance but ye...
GetRektByNoob is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 07-28-2019 , 14:37   Re: Player data in not inserting into DB Corectly
Reply With Quote #6

Quote:
Originally Posted by GetRektByNoob View Post
you should also use the databse methodmap I'm not sure if it's better performance but ye...
From what I've read on these forums (someone say something if the following is incorrect), the methodmap is just a wrapper for the normal functions, so if anything, it is less performance (likely next to negligible), since it has to convert it to the normal functions. The methodmaps provide readability and object-oriented programming feel (I use them as well).
__________________
ThatOneGuy is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-28-2019 , 16:52   Re: Player data in not inserting into DB Corectly
Reply With Quote #7

Quote:
Originally Posted by ThatOneGuy View Post
From what I've read on these forums (someone say something if the following is incorrect), the methodmap is just a wrapper for the normal functions, so if anything, it is less performance (likely next to negligible), since it has to convert it to the normal functions. The methodmaps provide readability and object-oriented programming feel (I use them as well).
It is entirely incorrect, the "conversion" is at compile-time.
__________________
asherkin is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-28-2019 , 16:59   Re: Player data in not inserting into DB Corectly
Reply With Quote #8

PHP Code:
public void OnPluginStart()
{
    
SQL_TConnect(OnSQLConnect"panel");
}

public 
int OnSQLConnect(Handle pOwnerHandle pHandlechar [] szErrorany Data)
{
    if(
pHandle == INVALID_HANDLE)
    {
        
LogError("[Panel] Database failure: %s"szError);
        
SetFailState("Databases Error: %s"szError);
    }    
    else 
    {
        
g_pDatabase pHandle;
        
char sQ[255];
        
FormatEx(sQsizeof(sQ), "CREATE TABLE IF NOT EXISTS `panel` (`name` varchar(32) NOT NULL, `steam` varchar(32) PRIMARY KEY NOT NULL);");
        
        
SQL_TQuery(g_pDatabaseCheckThreadsQ);
    }
}

public 
int CheckThread(Handle pOwnerHandle pHandlechar [] szErrorany Data)
{
    if(
pHandle == INVALID_HANDLE)
    {
        
LogError("Query failure: %s"szError);
        
SetFailState("Databases Error: %s"szError);
        return;
    }
}

public 
void OnClientPostAdminCheck(int Client)
{
    if(
g_pDatabase == INVALID_HANDLE)
    {
        return;
    }
    else 
    {
        
char Steam[128], Name[MAX_NAME_LENGTH], SafeName[MAX_NAME_LENGTH];
        
GetClientAuthId(ClientAuthId_EngineSteamsizeof(Steam));
        
GetClientName(ClientNameMAX_NAME_LENGTH);
        
        
TrimString(Name);
        
SQL_EscapeString(g_pDatabaseNameSafeNamesizeof(SafeName));
        
        
char sQ[255];
        
FormatEx(sQsizeof(sQ), "INSERT INTO`panel(name, steam) VALUES (`%s`, `%s`);",    SafeNameSteam);
                
        
SQL_TQuery(g_pDatabaseCheckThreadsQ);
    }

I've tried to make it from 0. What habe i dont wrong this time?
http://prntscr.com/ol7bas
__________________
kratoss1812 is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-28-2019 , 17:21   Re: Player data in not inserting into DB Corectly
Reply With Quote #9

There is a backtick between INTO and panel that doesn't belong there.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 07-29-2019 , 02:03   Re: Player data in not inserting into DB Corectly
Reply With Quote #10

Quote:
Originally Posted by asherkin View Post
It is entirely incorrect, the "conversion" is at compile-time.
Oh, good to know! I've been using the methodmaps, but was under the impression that it was a slight impact to performance. Thanks for the info!

So, i guess there is literally no difference (performance wise) using the normal format vs methodmaps. Good to know, since I prefer OO coding myself.
__________________
ThatOneGuy 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 06:01.


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