Raised This Month: $85 Target: $400
 21% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Oylsister
Member
Join Date: Aug 2019
Location: KhonKaen, Thailand
Old 08-15-2020 , 12:49   [Help!] Showing Expiration Time of client from Sourcebans Donation Control
Reply With Quote #1

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.
__________________
Oylsister is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-17-2020 , 02:07   Re: [Help!] Showing Expiration Time of client from Sourcebans Donation Control
Reply With Quote #2

Quote:
Originally Posted by Oylsister View Post
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
__________________
8guawong 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 03:00.


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