View Single Post
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