AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [Help!] Showing Expiration Time of client from Sourcebans Donation Control (https://forums.alliedmods.net/showthread.php?t=326759)

Oylsister 08-15-2020 12:49

[Help!] Showing Expiration Time of client from Sourcebans Donation Control
 
Hi, I tried to write a plugin that fetches the data from MySQL. the Donations Control itself is not a plugin and working mostly on the website (https://forums.alliedmods.net/showthread.php?t=221742)

So the plugin has to fetch the data from another table since the plugin doesn't have a table itself. I did ask my player on the server to try out but it showing a message of that player has no perk.

This is my first time doing the SQL and database stuff.

PHP Code:

#pragma newdecls required

Handle g_hDatabase INVALID_HANDLE;

char g_sDatabaseName[] = "sourcedonate";

bool g_bhaveperk[MAXPLAYERS]; 

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_vip"Expiration_Check);
}

public 
void OnConfigsExecuted() 
{
    
SQL_TConnect(SQL_Connectedg_sDatabaseName);
}

public 
void SQL_Connected(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
g_hDatabase != INVALID_HANDLE)
    {
        
CloseHandle(g_hDatabase);
        
g_hDatabase INVALID_HANDLE;
    }
    
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("[Source Donator] could not connect to database.");
        return;
    }
    
    
g_hDatabase hndl;
        
LogMessage("[Source Donator] Connected successfully to database.");
}

public 
void OnClientPostAdminCheck(int client
{
    
g_bhaveperk[client] = false;
    
LoadVip(client);
}

public 
Action Expiration_Check(int clientint args)
{
    if (
g_hDatabase == INVALID_HANDLE)
    {    
        
CReplyToCommand(client"\x04[Sourcebans Donator] \x01the Database is now being loaded.");    
        return 
Plugin_Handled;
    }

    if (
g_bhaveperk[client]) 
    {
        
char sSteamID[32];
        
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

        
char sQuery[1024];
        
Format(sQuerysizeof(sQuery), "SELECT tier, sign_up_date, renewal_date, expiration_date FROM donors WHERE steam_id = '%s';"sSteamID);

        
SQL_TQuery(g_hDatabaseSQL_ProcessResultsQueryclient);
    }
    
    else
    {
        
CReplyToCommand(client"\x04[Sourcebans Donator] \x01You don't have donator perk right now or the database is not loaded yet.");
        return 
Plugin_Handled;
    }

    return 
Plugin_Handled;
}

public 
void SQL_ProcessResult(Handle dbHandle hQuery, const char[] errorany client)
{
    
int iDayiMonthiYeariHouriMinuteiSecond;
    
int iDay2iMonth2iYear2iHour2iMinute2iSecond2;
    
int iDay3iMonth3iYear3iHour3iMinute3iSecond3;

    
char m_clienttier[64];
    
    if (
hQuery == INVALID_HANDLE)
    {
        
LogError("[Source Donator] Query failed: %s"error);
        return;
    }
    
    while (
SQL_FetchRow(hQuery))
    {
        
int ClientTier SQL_FetchInt(hQuery0);
        
        if (
ClientTier == 1)
            
Format(m_clienttiersizeof(m_clienttier), "Donator");

        else if (
ClientTier == 3)
            
Format(m_clienttiersizeof(m_clienttier), "VIP-Diamond");

        
int SignUnixTime SQL_FetchInt(hQuery1);
        
int RenewalUnixTime SQL_FetchInt(hQuery2);
        
int ExpUnixTime SQL_FetchInt(hQuery3);

        
UnixToTime(SignUnixTimeiYeariMonthiDayiHouriMinuteiSecondUT_TIMEZONE_SERVER);
        
UnixToTime(RenewalUnixTimeiYear2iMonth2iDay3iHour2iMinute2iSecond2UT_TIMEZONE_SERVER);
        
UnixToTime(ExpUnixTimeiYear3iMonth3iDay3iHour3iMinute3iSecond3UT_TIMEZONE_SERVER);
    }
    
    
Menu SourcedonatorMenu CreateMenu(SourcedonatorMenuHandler);

    
char m_signdate[512];
    
char m_renewdate[512];
    
char m_expdate[512];
    
char sSteamID[32];
    
char m_type[512];

    
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

    
Format(m_signdatesizeof(m_signdate), "First Signup date: %02d/%02d/%d"iMonthiDayiYear);
    
Format(m_renewdatesizeof(m_renewdate), "Renewal Date: %02d/%02d/%d"iMonth2iDay2iYear2);
    
Format(m_expdatesizeof(m_expdate), "Expiry date: %02d/%02d/%d"iMonth3iDay3iYear3);
    
Format(m_typesizeof(m_type), "Perk Type: %s"m_clienttier);

    
SetMenuTitle(SourcedonatorMenu"Sourcebans Donator Status");
    
AddMenuItem(SourcedonatorMenu"SteamID: %s"sSteamIDITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s\n"m_typeITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s"m_signdateITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s\n"m_renewdateITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s"m_expdateITEMDRAW_DISABLED);
    
DisplayMenu(SourcedonatorMenuclient60);
}

public 
int SourcedonatorMenuHandler(Handle menuMenuAction actionint clientint item
{
    
char sString[32];
    
GetMenuItem(menuitemsStringsizeof(sString));
    if (
action == MenuAction_Select
    {
        
// Meh nothing to do with the option
    
}
}

public 
void LoadVip(int client
{
    
char sSteamID[32];
    
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

    
char isDonatorQuery[1024];
    
Format(isDonatorQuerysizeof(isDonatorQuery), "SELECT expiration_date FROM Donors WHERE steam_id '%s';"sSteamID);
    
SQL_TQuery(g_hDatabaseSQLCheckPerkQueryisDonatorQueryGetClientUserId(client));
}

public 
void SQLCheckPerkQuery(Handle ownerHandle hDonatorQuery, const char[] errorany client)
{
    if (
IsValidClient(client)) 
    {
        while (
SQL_FetchRow(hDonatorQuery))
        {
            
int ExpUnixTime SQL_FetchInt(hDonatorQuery0);
            
int CurrentTime GetTime();
            
            if (
ExpUnixTime CurrentTime)
                
g_bhaveperk[client] = true;
        }
    }
}

stock bool IsValidClient(int client
{
    return (
<= client <= MaxClients && IsClientInGame(client));


Plugin successfully connect to the database btw.

8guawong 08-17-2020 02:07

Re: [Help!] Showing Expiration Time of client from Sourcebans Donation Control
 
Quote:

Originally Posted by Oylsister (Post 2714324)
Hi, I tried to write a plugin that fetches the data from MySQL. the Donations Control itself is not a plugin and working mostly on the website (https://forums.alliedmods.net/showthread.php?t=221742)

So the plugin has to fetch the data from another table since the plugin doesn't have a table itself. I did ask my player on the server to try out but it showing a message of that player has no perk.

This is my first time doing the SQL and database stuff.

PHP Code:

#pragma newdecls required

Handle g_hDatabase INVALID_HANDLE;

char g_sDatabaseName[] = "sourcedonate";

bool g_bhaveperk[MAXPLAYERS]; 

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_vip"Expiration_Check);
}

public 
void OnConfigsExecuted() 
{
    
SQL_TConnect(SQL_Connectedg_sDatabaseName);
}

public 
void SQL_Connected(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
g_hDatabase != INVALID_HANDLE)
    {
        
CloseHandle(g_hDatabase);
        
g_hDatabase INVALID_HANDLE;
    }
    
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("[Source Donator] could not connect to database.");
        return;
    }
    
    
g_hDatabase hndl;
        
LogMessage("[Source Donator] Connected successfully to database.");
}

public 
void OnClientPostAdminCheck(int client
{
    
g_bhaveperk[client] = false;
    
LoadVip(client);
}

public 
Action Expiration_Check(int clientint args)
{
    if (
g_hDatabase == INVALID_HANDLE)
    {    
        
CReplyToCommand(client"\x04[Sourcebans Donator] \x01the Database is now being loaded.");    
        return 
Plugin_Handled;
    }

    if (
g_bhaveperk[client]) 
    {
        
char sSteamID[32];
        
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

        
char sQuery[1024];
        
Format(sQuerysizeof(sQuery), "SELECT tier, sign_up_date, renewal_date, expiration_date FROM donors WHERE steam_id = '%s';"sSteamID);

        
SQL_TQuery(g_hDatabaseSQL_ProcessResultsQueryclient);
    }
    
    else
    {
        
CReplyToCommand(client"\x04[Sourcebans Donator] \x01You don't have donator perk right now or the database is not loaded yet.");
        return 
Plugin_Handled;
    }

    return 
Plugin_Handled;
}

public 
void SQL_ProcessResult(Handle dbHandle hQuery, const char[] errorany client)
{
    
int iDayiMonthiYeariHouriMinuteiSecond;
    
int iDay2iMonth2iYear2iHour2iMinute2iSecond2;
    
int iDay3iMonth3iYear3iHour3iMinute3iSecond3;

    
char m_clienttier[64];
    
    if (
hQuery == INVALID_HANDLE)
    {
        
LogError("[Source Donator] Query failed: %s"error);
        return;
    }
    
    while (
SQL_FetchRow(hQuery))
    {
        
int ClientTier SQL_FetchInt(hQuery0);
        
        if (
ClientTier == 1)
            
Format(m_clienttiersizeof(m_clienttier), "Donator");

        else if (
ClientTier == 3)
            
Format(m_clienttiersizeof(m_clienttier), "VIP-Diamond");

        
int SignUnixTime SQL_FetchInt(hQuery1);
        
int RenewalUnixTime SQL_FetchInt(hQuery2);
        
int ExpUnixTime SQL_FetchInt(hQuery3);

        
UnixToTime(SignUnixTimeiYeariMonthiDayiHouriMinuteiSecondUT_TIMEZONE_SERVER);
        
UnixToTime(RenewalUnixTimeiYear2iMonth2iDay3iHour2iMinute2iSecond2UT_TIMEZONE_SERVER);
        
UnixToTime(ExpUnixTimeiYear3iMonth3iDay3iHour3iMinute3iSecond3UT_TIMEZONE_SERVER);
    }
    
    
Menu SourcedonatorMenu CreateMenu(SourcedonatorMenuHandler);

    
char m_signdate[512];
    
char m_renewdate[512];
    
char m_expdate[512];
    
char sSteamID[32];
    
char m_type[512];

    
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

    
Format(m_signdatesizeof(m_signdate), "First Signup date: %02d/%02d/%d"iMonthiDayiYear);
    
Format(m_renewdatesizeof(m_renewdate), "Renewal Date: %02d/%02d/%d"iMonth2iDay2iYear2);
    
Format(m_expdatesizeof(m_expdate), "Expiry date: %02d/%02d/%d"iMonth3iDay3iYear3);
    
Format(m_typesizeof(m_type), "Perk Type: %s"m_clienttier);

    
SetMenuTitle(SourcedonatorMenu"Sourcebans Donator Status");
    
AddMenuItem(SourcedonatorMenu"SteamID: %s"sSteamIDITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s\n"m_typeITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s"m_signdateITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s\n"m_renewdateITEMDRAW_DISABLED);
    
AddMenuItem(SourcedonatorMenu"%s"m_expdateITEMDRAW_DISABLED);
    
DisplayMenu(SourcedonatorMenuclient60);
}

public 
int SourcedonatorMenuHandler(Handle menuMenuAction actionint clientint item
{
    
char sString[32];
    
GetMenuItem(menuitemsStringsizeof(sString));
    if (
action == MenuAction_Select
    {
        
// Meh nothing to do with the option
    
}
}

public 
void LoadVip(int client
{
    
char sSteamID[32];
    
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID));

    
char isDonatorQuery[1024];
    
Format(isDonatorQuerysizeof(isDonatorQuery), "SELECT expiration_date FROM Donors WHERE steam_id '%s';"sSteamID);
    
SQL_TQuery(g_hDatabaseSQLCheckPerkQueryisDonatorQueryGetClientUserId(client));
}

public 
void SQLCheckPerkQuery(Handle ownerHandle hDonatorQuery, const char[] errorany client)
{
    if (
IsValidClient(client)) 
    {
        while (
SQL_FetchRow(hDonatorQuery))
        {
            
int ExpUnixTime SQL_FetchInt(hDonatorQuery0);
            
int CurrentTime GetTime();
            
            if (
ExpUnixTime CurrentTime)
                
g_bhaveperk[client] = true;
        }
    }
}

stock bool IsValidClient(int client
{
    return (
<= client <= MaxClients && IsClientInGame(client));


Plugin successfully connect to the database btw.

show a result of your menu and your sql table

Oylsister 11-28-2020 08:40

Re: [Help!] Showing Expiration Time of client from Sourcebans Donation Control
 
Quote:

Originally Posted by 8guawong (Post 2714496)
show a result of your menu and your sql table

There is no menu showing up and a message showing as "[Sourcebans Donator] You don't have donator perk right now or the database is not loaded yet."

But I just figure out later that because SourceBans Donation using steam id as "STEAM_0" while CS:GO uses "STEAM_1". To solve this problem it only needs to match the string of steam id. or Only try to match some part of steam id

GsiX 11-28-2020 14:37

Re: [Help!] Showing Expiration Time of client from Sourcebans Donation Control
 
Can you pull something from the database to begin with?

Oylsister 12-05-2020 22:07

Re: [Help!] Showing Expiration Time of client from Sourcebans Donation Control
 
Quote:

Originally Posted by GsiX (Post 2726562)
Can you pull something from the database to begin with?

Like how? I mean I'm really amateur about this thing.

DJ Tsunami 12-06-2020 04:37

Re: [Help!] Showing Expiration Time of client from Sourcebans Donation Control
 
PHP Code:

WHERE steam_id '%s'

You are missing an = here. You should add error handling in SQLCheckPerkQuery so you can catch mistakes in your query.

You are also passing GetClientUserId(client) to SQLCheckPerkQuery, but then you treat it as a client index, so IsValidClient probably fails. You need to use GetClientOfUserId to convert the userid back to a client index.


All times are GMT -4. The time now is 12:24.

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