AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Player data in not inserting into DB Corectly (https://forums.alliedmods.net/showthread.php?t=317745)

kratoss1812 07-27-2019 16:57

Player data in not inserting into DB Corectly
 
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);



ThatOneGuy 07-27-2019 17:25

Re: Player data in not inserting into DB Corectly
 
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.

CrazyHackGUT 07-27-2019 17:38

Re: Player data in not inserting into DB Corectly
 
Escape values before inserting in query, or use Database.Format()

kratoss1812 07-27-2019 17:42

Re: Player data in not inserting into DB Corectly
 
Quote:

Originally Posted by ThatOneGuy (Post 2660864)
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

GetRektByNoob 07-28-2019 05:13

Re: Player data in not inserting into DB Corectly
 
you should also use the databse methodmap I'm not sure if it's better performance but ye...

ThatOneGuy 07-28-2019 14:37

Re: Player data in not inserting into DB Corectly
 
Quote:

Originally Posted by GetRektByNoob (Post 2660933)
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).

asherkin 07-28-2019 16:52

Re: Player data in not inserting into DB Corectly
 
Quote:

Originally Posted by ThatOneGuy (Post 2660989)
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.

kratoss1812 07-28-2019 16:59

Re: Player data in not inserting into DB Corectly
 
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

DJ Tsunami 07-28-2019 17:21

Re: Player data in not inserting into DB Corectly
 
There is a backtick between INTO and panel that doesn't belong there.

ThatOneGuy 07-29-2019 02:03

Re: Player data in not inserting into DB Corectly
 
Quote:

Originally Posted by asherkin (Post 2660996)
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.


All times are GMT -4. The time now is 02:29.

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