Raised This Month: $12 Target: $400
 3% 

[Any][MySQL] tVip (2.3 | 04-04-21) - The simplest to use Vip Manager


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
ApoziX
Member
Join Date: Sep 2018
Old 11-03-2018 , 12:48   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #11

Quote:
Originally Posted by Totenfluch View Post
That's nice to know but I need way more info to confirm that and even more to reproduce this.
Thank you for the fast reply

PHP Code:
#pragma semicolon 1

#define PLUGIN_AUTHOR "Totenfluch"
#define PLUGIN_VERSION "2.1"

#include <sourcemod>
#include <sdktools>
#include <multicolors>
#include <autoexecconfig>


#pragma newdecls required

char dbconfig[] = "tVip";
Database g_DB;

/*
    https://wiki.alliedmods.net/Checking_Admin_Flags_(SourceMod_Scripting)
    19 -> Custom5
    20 -> Custom6
*/

Handle g_hTestVipDuration;
int g_iTestVipDuration;

Handle g_hFlag;
int g_iFlags[20];
int g_iFlagCount 0;


bool g_bIsVip[MAXPLAYERS 1];

public 
Plugin myinfo 
{
    
name "[FZG] tVIP"
    
author PLUGIN_AUTHOR
    
description "VIP functionality for the GGC"
    
version PLUGIN_VERSION
    
url "https://totenfluch.de"
};


public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
//Create natives
    
CreateNative("tVip_GrantVip"NativeGrantVip);
    
CreateNative("tVip_DeleteVip"NativeDeleteVip);
    return 
APLRes_Success;
}


public 
void OnPluginStart() {
    
char error[255];
    
g_DB SQL_Connect(dbconfigtrueerrorsizeof(error));
    
SQL_SetCharset(g_DB"utf8");
    
    
char createTableQuery[4096];
    
Format(createTableQuerysizeof(createTableQuery), 
        
"CREATE TABLE IF NOT EXISTS `tVip` ( \
         `Id` bigint(20) NOT NULL AUTO_INCREMENT, \
          `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, \
          `playername` varchar(36) COLLATE utf8_bin NOT NULL, \
          `playerid` varchar(20) COLLATE utf8_bin NOT NULL, \
          `enddate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', \
          `admin_playername` varchar(36) COLLATE utf8_bin NOT NULL, \
          `admin_playerid` varchar(20) COLLATE utf8_bin NOT NULL, \
          PRIMARY KEY (`Id`), \
           UNIQUE KEY `playerid` (`playerid`)  \
           ) ENGINE = InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"
        
);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackcreateTableQuery);
    
    
AutoExecConfig_SetFile("tVip");
    
AutoExecConfig_SetCreateFile(true);
    
    
g_hFlag AutoExecConfig_CreateConVar("tVip_flag""19""20=Custom6, 19=Custom5 etc. Numeric Flag See: 'https://wiki.alliedmods.net/Checking_Admin_Flags_(SourceMod_Scripting)' for Definitions ---- Multiple flags seperated with Space: '16 17 18 19' !!");
    
g_hTestVipDuration AutoExecConfig_CreateConVar("tVip_testVipDuration""15""Test Vip duration in minutes");
    
    
AutoExecConfig_CleanFile();
    
AutoExecConfig_ExecuteFile();
    
    
RegAdminCmd("sm_tvip"cmdtVIPADMFLAG_ROOT"Opens the tVIP menu");
    
RegAdminCmd("sm_addvip"cmdAddVipADMFLAG_ROOT"Adds a VIP Usage: sm_addvip \"<SteamID>\" <Duration in Month> \"<Name>\"");
    
RegAdminCmd("sm_removevip"removeVipADMFLAG_ROOT"Removes a VIP Usage: sm_removevip \"<SteamID>\"");
    
RegConsoleCmd("sm_vipss"cmdListVips"Shows all VIPs");
    
RegConsoleCmd("sm_vsub"openVipPanel"Opens the Vip Menu");
    
    
reloadVIPs();
}

public 
void OnConfigsExecuted() {
    
g_iFlagCount 0;
    
g_iTestVipDuration GetConVarInt(g_hTestVipDuration);
    
char cFlags[256];
    
GetConVarString(g_hFlagcFlagssizeof(cFlags));
    
char cSplinters[20][6];
    for (
int i 020i++)
    
strcopy(cSplinters[i], 6"");
    
ExplodeString(cFlags" "cSplinters206);
    for (
int i 020i++) {
        if (
StrEqual(cSplinters[i], ""))
            break;
        
g_iFlags[g_iFlagCount++] = StringToInt(cSplinters[i]);
    }
}

public 
Action openVipPanel(int clientint args) {
    if (
g_bIsVip[client]) {
        
char playerid[20];
        
GetClientAuthId(clientAuthId_Steam2playeridsizeof(playerid));
        if (
StrContains(playerid"STEAM_") != -1)
            
strcopy(playeridsizeof(playerid), playerid[8]);
        
        
char getDatesQuery[1024];
        
Format(getDatesQuerysizeof(getDatesQuery), "SELECT timestamp,enddate,DATEDIFF(enddate, NOW()) as timeleft FROM tVip WHERE playerid = '%s';"playerid);
        
        
SQL_TQuery(g_DBgetDatesQueryCallbackgetDatesQueryclient);
    }
    return 
Plugin_Handled;
    
}

public 
void getDatesQueryCallback(Handle ownerHandle hndl, const char[] errorany data) {
    
int client data;
    
char ends[128];
    
char started[128];
    
char left[64];
    while (
SQL_FetchRow(hndl)) {
        
SQL_FetchString(hndl0startedsizeof(started));
        
SQL_FetchString(hndl1endssizeof(ends));
        
SQL_FetchString(hndl2leftsizeof(left));
    }
    
    
Menu VipPanelMenu CreateMenu(VipPanelMenuHandler);
    
char m_started[256];
    
char m_ends[256];
    
Format(m_startedsizeof(m_started), "Started: %s"started);
    
Format(m_endssizeof(m_ends), "Ends: %s (%s Days)"endsleft);
    
SetMenuTitle(VipPanelMenu"[FZG] VIP Subscription");
    
AddMenuItem(VipPanelMenu"x"m_startedITEMDRAW_DISABLED);
    
AddMenuItem(VipPanelMenu"x"m_endsITEMDRAW_DISABLED);
    
DisplayMenu(VipPanelMenuclient60);
}

public 
int VipPanelMenuHandler(Handle menuMenuAction actionint clientint item) {
    
char cValue[32];
    
GetMenuItem(menuitemcValuesizeof(cValue));
    if (
action == MenuAction_Select) {
        
// TODO ?
    
}
}

public 
Action removeVip(int clientint args) {
    if (
args != 1) {
        if (
client != 0)
            
CPrintToChat(client"{olive}[-T-] {lightred}Invalid Params Usage: sm_removevip \"<SteamID>\"");
        else
            
PrintToServer("[-T-] Invalid Params Usage: sm_removevip \"<SteamID>\"");
        return 
Plugin_Handled;
    }
    
    
char playerid[20];
    
GetCmdArg(1playeridsizeof(playerid));
    
StripQuotes(playerid);
    if (
StrContains(playerid"STEAM_") != -1)
        
strcopy(playeridsizeof(playerid), playerid[8]);
    
    
deleteVip(playerid);
    
    if (
client != 0)
        
CPrintToChat(client"{green}Deleted {orange}%s{green} from the Database"playerid);
    else
        
PrintToServer("Deleted %s from the Database"playerid);
    
    return 
Plugin_Handled;
}

public 
Action cmdAddVip(int clientint args) {
    if (
args != 3) {
        if (
client != 0)
            
CPrintToChat(client"{olive}[-T-] {lightred}Invalid Params Usage: sm_addvip \"<SteamID>\" <Duration in Month> \"<Name>\"");
        else
            
PrintToServer("[-T-] Invalid Params Usage: sm_addvip \"<SteamID>\" <Duration in Month> \"<Name>\"");
        return 
Plugin_Handled;
    }
    
    
char input[22];
    
GetCmdArg(1inputsizeof(input));
    
StripQuotes(input);
    if (
StrContains(input"STEAM_") != -1)
        
strcopy(inputsizeof(input), input[8]);
    
    
char duration[8];
    
GetCmdArg(2durationsizeof(duration));
    
int d1 StringToInt(duration);
    
    
char input2[20];
    
strcopy(input2sizeof(input2), input);
    
StripQuotes(input2);
    
    
char name[MAX_NAME_LENGTH 8];
    
GetCmdArg(3namesizeof(name));
    
StripQuotes(name);
    
char clean_name[MAX_NAME_LENGTH 16];
    
SQL_EscapeString(g_DBnameclean_namesizeof(clean_name));
    
    
grantVipEx(clientinput2d1clean_name);
    return 
Plugin_Handled;
}

public 
Action cmdtVIP(int clientint args) {
    
Menu mainChooser CreateMenu(mainChooserHandler);
    
SetMenuTitle(mainChooser"[FZG] tVIP Control");
    
AddMenuItem(mainChooser"add""Add VIP");
    
AddMenuItem(mainChooser"remove""Remove VIP");
    
AddMenuItem(mainChooser"extend""Extend VIP");
    
AddMenuItem(mainChooser"list""List VIPs (Info)");
    
DisplayMenu(mainChooserclient60);
    return 
Plugin_Handled;
}

public 
Action cmdListVips(int clientint args) {
    
char showOffVIPQuery[1024];
    
Format(showOffVIPQuerysizeof(showOffVIPQuery), "SELECT playername,playerid FROM tVip WHERE NOW() < enddate;");
    
SQL_TQuery(g_DBSQLShowOffVipQueryshowOffVIPQueryclient);
}

public 
void SQLShowOffVipQuery(Handle ownerHandle hndl, const char[] errorany data) {
    
int client data;
    
Menu showOffMenu CreateMenu(noMenuHandler);
    
SetMenuTitle(showOffMenu"[FZG] VIPS");
    while (
SQL_FetchRow(hndl)) {
        
char playerid[20];
        
char playername[MAX_NAME_LENGTH 8];
        
SQL_FetchString(hndl0playernamesizeof(playername));
        
SQL_FetchString(hndl1playeridsizeof(playerid));
        
AddMenuItem(showOffMenuplayeridplayernameITEMDRAW_DISABLED);
    }
    
DisplayMenu(showOffMenuclient60);
}

public 
int noMenuHandler(Handle menuMenuAction actionint clientint item) {  }

public 
int mainChooserHandler(Handle menuMenuAction actionint clientint item) {
    
char cValue[32];
    
GetMenuItem(menuitemcValuesizeof(cValue));
    if (
action == MenuAction_Select) {
        if (
StrEqual(cValue"add")) {
            
showDurationSelect(client1);
        } else if (
StrEqual(cValue"remove")) {
            
showAllVIPsToAdmin(client);
        } else if (
StrEqual(cValue"extend")) {
            
extendSelect(client);
        } else if (
StrEqual(cValue"list")) {
            
listUsers(client);
        }
    }
}

int g_iReason[MAXPLAYERS 1];
public 
void showDurationSelect(int clientint reason) {
    
Menu selectDuration CreateMenu(selectDurationHandler);
    
SetMenuTitle(selectDuration"Select the Duration");
    
AddMenuItem(selectDuration"testVip""Test Vip");
    
AddMenuItem(selectDuration"1""1 Month");
    
AddMenuItem(selectDuration"2""2 Month");
    
AddMenuItem(selectDuration"3""3 Month");
    
AddMenuItem(selectDuration"4""4 Month");
    
AddMenuItem(selectDuration"5""5 Month");
    
AddMenuItem(selectDuration"6""6 Month");
    
AddMenuItem(selectDuration"9""9 Month");
    
AddMenuItem(selectDuration"12""12 Month");
    
g_iReason[client] = reason;
    
DisplayMenu(selectDurationclient60);
}

int g_iDurationSelected[MAXPLAYERS 1];
public 
int selectDurationHandler(Handle menuMenuAction actionint clientint item) {
    
char cValue[32];
    
GetMenuItem(menuitemcValuesizeof(cValue));
    if (
action == MenuAction_Select) {
        if (
StrEqual(cValue"testVip")) {
            
g_iDurationSelected[client] = g_iTestVipDuration;
            
g_iReason[client] = 3;
            
showPlayerSelectMenu(clientg_iReason[client]);
        } else {
            
g_iDurationSelected[client] = StringToInt(cValue);
            
showPlayerSelectMenu(clientg_iReason[client]);
        }
    }
}

public 
void showPlayerSelectMenu(int clientint reason) {
    
Handle menu;
    
char menuTitle[255];
    if (
reason == 1) {
        
menu CreateMenu(targetChooserMenuHandler);
        
Format(menuTitlesizeof(menuTitle), "Select a Player to grant %i Month"g_iDurationSelected[client]);
    } else if (
reason == 2) {
        
menu CreateMenu(extendChooserMenuHandler);
        
Format(menuTitlesizeof(menuTitle), "Select a Player to extend %i Month"g_iDurationSelected[client]);
    } else if (
reason == 3) {
        
menu CreateMenu(targetChooserMenuHandler);
        
Format(menuTitlesizeof(menuTitle), "Select a Player to grant Test Vip (%i Minutes)"g_iDurationSelected[client]);
    }
    if (
menu == INVALID_HANDLE)
        return;
    
SetMenuTitle(menumenuTitle);
    
int pAmount 0;
    for (
int i 1<= MAXPLAYERSi++) {
        if (
== client)
            continue;
        
        if (!
isValidClient(i))
            continue;
        
        if (
IsFakeClient(i))
            continue;
        
        if (
reason == 2) {
            if (!
g_bIsVip[i])
                continue;
        } else if (
reason == 1) {
            if (
g_bIsVip[i])
                continue;
        }
        
        
char Id[64];
        
IntToString(iIdsizeof(Id));
        
        
char targetName[MAX_NAME_LENGTH 1];
        
GetClientName(itargetNamesizeof(targetName));
        
        
AddMenuItem(menuIdtargetName);
        
pAmount++;
    }
    if (
pAmount == 0)
        
CPrintToChat(client"{red}No matching clients found (Noone there or everyone is already VIP/Admin)");
    
    
DisplayMenu(menuclient30);
}

public 
int targetChooserMenuHandler(Handle menuMenuAction actionint clientint item) {
    if (
action == MenuAction_Select) {
        
char info[64];
        
GetMenuItem(menuiteminfosizeof(info));
        
        
int target StringToInt(info);
        if (!
isValidClient(target) || !IsClientInGame(target)) {
            
CPrintToChat(client"{red}Invalid Target");
            return;
        }
        
        
grantVip(clienttargetg_iDurationSelected[client], g_iReason[client]);
    }
    if (
action == MenuAction_End) {
        
delete menu;
    }
}

public 
void grantVip(int adminint clientint durationint reason) {
    
char admin_playerid[20];
    
GetClientAuthId(adminAuthId_Steam2admin_playeridsizeof(admin_playerid));
    if (
StrContains(admin_playerid"STEAM_") != -1)
        
strcopy(admin_playeridsizeof(admin_playerid), admin_playerid[8]);
    
char admin_playername[MAX_NAME_LENGTH 8];
    if (
admin != 0)
        
GetClientName(adminadmin_playernamesizeof(admin_playername));
    else
        
strcopy(admin_playernamesizeof(admin_playername), "SERVER-CONSOLE");
    
char clean_admin_playername[MAX_NAME_LENGTH 16];
    
SQL_EscapeString(g_DBadmin_playernameclean_admin_playernamesizeof(clean_admin_playername));
    
    
    
char playerid[20];
    
GetClientAuthId(clientAuthId_Steam2playeridsizeof(playerid));
    if (
StrContains(playerid"STEAM_") != -1)
        
strcopy(playeridsizeof(playerid), playerid[8]);
    
char playername[MAX_NAME_LENGTH 8];
    
GetClientName(clientplayernamesizeof(playername));
    
char clean_playername[MAX_NAME_LENGTH 16];
    
SQL_EscapeString(g_DBplayernameclean_playernamesizeof(clean_playername));
    
    
    
char addVipQuery[4096];
    
Format(addVipQuerysizeof(addVipQuery), "INSERT IGNORE INTO `tVip` (`Id`, `timestamp`, `playername`, `playerid`, `enddate`, `admin_playername`, `admin_playerid`) VALUES (NULL, CURRENT_TIMESTAMP, '%s', '%s', CURRENT_TIMESTAMP, '%s', '%s');"clean_playernameplayeridclean_admin_playernameadmin_playerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackaddVipQuery);
    
    
char updateTime[1024];
    if (
reason != 3)
        
Format(updateTimesizeof(updateTime), "UPDATE tVip SET enddate = DATE_ADD(enddate, INTERVAL %i MONTH) WHERE playerid = '%s';"durationplayerid);
    else
        
Format(updateTimesizeof(updateTime), "UPDATE tVip SET enddate = DATE_ADD(enddate, INTERVAL %i MINUTE) WHERE playerid = '%s';"durationplayerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackupdateTime);
    
    
CPrintToChat(admin"{green}Added {orange}%s{green} as VIP for {orange}%i{green} %s"playernamedurationreason == "Minutes":"Month");
    
CPrintToChat(client"{green}You've been granted {orange}%i{green} %s of {orange}VIP{green} by {orange}%N"durationreason == "Minutes":"Month"admin);
    
setFlags(client);
}

public 
void grantVipEx(int adminchar playerid[20], int durationchar[] pname) {
    
char admin_playerid[20];
    if (
admin != 0) {
        
GetClientAuthId(adminAuthId_Steam2admin_playeridsizeof(admin_playerid));
        if (
StrContains(admin_playerid"STEAM_") != -1)
            
strcopy(admin_playeridsizeof(admin_playerid), admin_playerid[8]);
    } else
        
strcopy(admin_playeridsizeof(admin_playerid), "SERVER-CONSOLE");
    
char admin_playername[MAX_NAME_LENGTH 8];
    
    if (
admin != 0)
        
GetClientName(adminadmin_playernamesizeof(admin_playername));
    else
        
strcopy(admin_playernamesizeof(admin_playername), "SERVER-CONSOLE");
    
char clean_admin_playername[MAX_NAME_LENGTH 16];
    
SQL_EscapeString(g_DBadmin_playernameclean_admin_playernamesizeof(clean_admin_playername));
    
    
char addVipQuery[4096];
    
Format(addVipQuerysizeof(addVipQuery), "INSERT IGNORE INTO `tVip` (`Id`, `timestamp`, `playername`, `playerid`, `enddate`, `admin_playername`, `admin_playerid`) VALUES (NULL, CURRENT_TIMESTAMP, '%s', '%s', CURRENT_TIMESTAMP, '%s', '%s');"pnameplayeridclean_admin_playernameadmin_playerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackaddVipQuery);
    
    
char updateTime[1024];
    
Format(updateTimesizeof(updateTime), "UPDATE tVip SET enddate = DATE_ADD(enddate, INTERVAL %i MONTH) WHERE playerid = '%s';"durationplayerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackupdateTime);
    
    if (
admin != 0)
        
CPrintToChat(admin"{green}Added {orange}%s{green} as VIP for {orange}%i{green} Month"playeridduration);
    else
        
PrintToServer("Added %s as VIP for %i Month"playeridduration);
}

public 
void OnClientPostAdminCheck(int client) {
    
g_bIsVip[client] = false;
    
char cleanUp[256];
    
Format(cleanUpsizeof(cleanUp), "DELETE FROM tVip WHERE enddate < NOW();");
    
SQL_TQuery(g_DBSQLErrorCheckCallbackcleanUp);
    
    
loadVip(client);
}

public 
void loadVip(int client) {
    
char playerid[20];
    
GetClientAuthId(clientAuthId_Steam2playeridsizeof(playerid));
    if (
StrContains(playerid"STEAM_") != -1)
        
strcopy(playeridsizeof(playerid), playerid[8]);
    
char isVipQuery[1024];
    
Format(isVipQuerysizeof(isVipQuery), "SELECT * FROM tVip WHERE playerid = '%s' AND enddate > NOW();"playerid);
    
    
//Pass the userid to prevent assigning flags to a wrong client
    
SQL_TQuery(g_DBSQLCheckVIPQueryisVipQueryGetClientUserId(client));
}

public 
void SQLCheckVIPQuery(Handle ownerHandle hndl, const char[] errorany data) {
    
int client GetClientOfUserId(data);
    
    
//Check if the user is still ingame
    
if (isValidClient(client)) {
        while (
SQL_FetchRow(hndl)) {
            
setFlags(client);
        }
    }
}

public 
void setFlags(int client) {
    
g_bIsVip[client] = true;
    for (
int i 0g_iFlagCounti++)
    
SetUserFlagBits(clientGetUserFlagBits(client) | (<< g_iFlags[i]));
}

public 
void OnRebuildAdminCache(AdminCachePart part) {
    if (
part == AdminCache_Admins)
        
reloadVIPs();
}

public 
void reloadVIPs() {
    for (
int i 1MAXPLAYERSi++) {
        if (!
isValidClient(i))
            continue;
        
loadVip(i);
    }
}

public 
void showAllVIPsToAdmin(int client) {
    
char selectAllVIPs[1024];
    
Format(selectAllVIPssizeof(selectAllVIPs), "SELECT playername,playerid FROM tVip WHERE NOW() < enddate;");
    
SQL_TQuery(g_DBSQLListVIPsForRemovalselectAllVIPsclient);
}

public 
void SQLListVIPsForRemoval(Handle ownerHandle hndl, const char[] errorany data) {
    
int client data;
    
Menu menuToRemoveClients CreateMenu(menuToRemoveClientsHandler);
    
SetMenuTitle(menuToRemoveClients"Delete a VIP");
    while (
SQL_FetchRow(hndl)) {
        
char playerid[20];
        
char playername[MAX_NAME_LENGTH 8];
        
SQL_FetchString(hndl0playernamesizeof(playername));
        
SQL_FetchString(hndl1playeridsizeof(playerid));
        
AddMenuItem(menuToRemoveClientsplayeridplayername);
    }
    
DisplayMenu(menuToRemoveClientsclient60);
}

public 
int menuToRemoveClientsHandler(Handle menuMenuAction actionint clientint item) {
    if (
action == MenuAction_Select) {
        
char info[20];
        
char display[MAX_NAME_LENGTH 8];
        
int flags;
        
GetMenuItem(menuiteminfosizeof(info), flagsdisplaysizeof(display));
        
deleteVip(info);
        
showAllVIPsToAdmin(client);
        
CPrintToChat(client"{aqua}[FZG] {white}Removed {aqua}%ss{white} VIP {white}({aqua}%s{white})"displayinfo);
    }
}

public 
void deleteVip(char[] playerid) {
    
char deleteVipQuery[512];
    
Format(deleteVipQuerysizeof(deleteVipQuery), "DELETE FROM tVip WHERE playerid = '%s';"playerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackdeleteVipQuery);
}

public 
void extendSelect(int client) {
    
showDurationSelect(client2);
}

public 
int extendChooserMenuHandler(Handle menuMenuAction actionint clientint item) {
    if (
action == MenuAction_Select) {
        
char info[64];
        
GetMenuItem(menuiteminfosizeof(info));
        
        
int target StringToInt(info);
        if (!
isValidClient(target) || !IsClientInGame(target)) {
            
CPrintToChat(client"{aqua}[FZG] {white}Invalid Target");
            return;
        }
        
        
int userTarget GetClientUserId(target);
        
extendVip(clientuserTargetg_iDurationSelected[client]);
    }
    if (
action == MenuAction_End) {
        
delete menu;
    }
}

public 
void extendVip(int clientint userTargetint duration) {
    
int theUserTarget GetClientOfUserId(userTarget);
    
char playerid[20];
    
GetClientAuthId(theUserTargetAuthId_Steam2playeridsizeof(playerid));
    if (
StrContains(playerid"STEAM_") != -1)
        
strcopy(playeridsizeof(playerid), playerid[8]);
    
char playername[MAX_NAME_LENGTH 8];
    
GetClientName(theUserTargetplayernamesizeof(playername));
    
char clean_playername[MAX_NAME_LENGTH 16];
    
SQL_EscapeString(g_DBplayernameclean_playernamesizeof(clean_playername));
    
    
char updateQuery[1024];
    
Format(updateQuerysizeof(updateQuery), "UPDATE tVip SET enddate = DATE_ADD(enddate, INTERVAL %i MONTH) WHERE playerid = '%s';"durationplayerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackupdateQuery);
    
    
Format(updateQuerysizeof(updateQuery), "UPDATE tVip SET playername = '%s' WHERE playerid = '%s';"clean_playernameplayerid);
    
SQL_TQuery(g_DBSQLErrorCheckCallbackupdateQuery);
    
    
CPrintToChat(client"{green}Extended {orange}%s{green} VIP Status by {orange}%i{green} Month"playernameduration);
}

public 
void listUsers(int client) {
    
char listVipsQuery[1024];
    
Format(listVipsQuerysizeof(listVipsQuery), "SELECT playername,playerid FROM tVip WHERE enddate > NOW();");
    
SQL_TQuery(g_DBSQLListVIPsQuerylistVipsQueryclient);
}

public 
void SQLListVIPsQuery(Handle ownerHandle hndl, const char[] errorany data) {
    
int client data;
    
Menu menuToRemoveClients CreateMenu(listVipsMenuHandler);
    
SetMenuTitle(menuToRemoveClients"All VIPs");
    while (
SQL_FetchRow(hndl)) {
        
char playerid[20];
        
char playername[MAX_NAME_LENGTH 8];
        
SQL_FetchString(hndl0playernamesizeof(playername));
        
SQL_FetchString(hndl1playeridsizeof(playerid));
        
AddMenuItem(menuToRemoveClientsplayeridplayername);
    }
    
DisplayMenu(menuToRemoveClientsclient60);
}

public 
int listVipsMenuHandler(Handle menuMenuAction actionint clientint item) {
    if (
action == MenuAction_Select) {
        
char cValue[20];
        
GetMenuItem(menuitemcValuesizeof(cValue));
        
char detailsQuery[512];
        
Format(detailsQuerysizeof(detailsQuery), "SELECT playername,playerid,enddate,timestamp,admin_playername,admin_playerid FROM tVip WHERE playerid = '%s';"cValue);
        
SQL_TQuery(g_DBSQLDetailsQuerydetailsQueryclient);
    }
}

public 
void SQLDetailsQuery(Handle ownerHandle hndl, const char[] errorany data) {
    
int client data;
    
Menu detailsMenu CreateMenu(detailsMenuHandler);
    
bool hasData false;
    while (
SQL_FetchRow(hndl) && !hasData) {
        
char playerid[20];
        
char playername[MAX_NAME_LENGTH 8];
        
char startDate[128];
        
char endDate[128];
        
char adminname[MAX_NAME_LENGTH 8];
        
char adminplayerid[20];
        
SQL_FetchString(hndl0playernamesizeof(playername));
        
SQL_FetchString(hndl1playeridsizeof(playerid));
        
SQL_FetchString(hndl2endDatesizeof(endDate));
        
SQL_FetchString(hndl3startDatesizeof(startDate));
        
SQL_FetchString(hndl4adminnamesizeof(adminname));
        
SQL_FetchString(hndl5adminplayeridsizeof(adminplayerid));
        
        
char title[64];
        
Format(titlesizeof(title), "Details: %s"playername);
        
SetMenuTitle(detailsMenutitle);
        
        
char playeridItem[64];
        
Format(playeridItemsizeof(playeridItem), "STEAM_ID: %s"playerid);
        
AddMenuItem(detailsMenu"x"playeridItemITEMDRAW_DISABLED);
        
        
char endItem[64];
        
Format(endItemsizeof(endItem), "Ends: %s"endDate);
        
AddMenuItem(detailsMenu"x"endItemITEMDRAW_DISABLED);
        
        
char startItem[64];
        
Format(startItemsizeof(startItem), "Started: %s"startDate);
        
AddMenuItem(detailsMenu"x"startItemITEMDRAW_DISABLED);
        
        
char adminNItem[64];
        
Format(adminNItemsizeof(adminNItem), "By Admin: %s"adminname);
        
AddMenuItem(detailsMenu"x"adminNItemITEMDRAW_DISABLED);
        
        
char adminIItem[64];
        
Format(adminIItemsizeof(adminIItem), "Admin ID: %s"adminplayerid);
        
AddMenuItem(detailsMenu"x"adminIItemITEMDRAW_DISABLED);
        
        
hasData true;
    }
    
DisplayMenu(detailsMenuclient60);
}

public 
int detailsMenuHandler(Handle menuMenuAction actionint clientint item) {
    if (
action == MenuAction_Select) {
        
    } else if (
action == MenuAction_Cancel) {
        
listUsers(client);
    }
}

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

stock bool isVipCheck(int client) {
    return 
CheckCommandAccess(client"sm_amIVip", (<< g_iFlag), true);
}

public 
void SQLErrorCheckCallback(Handle ownerHandle hndl, const char[] errorany data) {
    if (!
StrEqual(error""))
        
LogError(error);
}



//Natives

public int NativeGrantVip(Handle mypluginint argc)
{
    
int client GetNativeCell(1);
    
int admin GetNativeCell(2);
    
int duration GetNativeCell(3);
    
int format GetNativeCell(4);
    if (
format == 1)
        
format 3;
    else if (
format == 0)
        
format 1;
    else
    {
        
ThrowNativeError(SP_ERROR_NATIVE"Invalid time format (%d)"format);
        return;
    }
    
    if (
admin == 0)
    {
        
grantVip(adminclientdurationformat);
        return;
    }
    if (
admin || admin MaxClients)
    {
        
ThrowNativeError(SP_ERROR_NATIVE"Invalid admin index (%d)"admin);
        return;
    }
    if (!
IsClientConnected(admin))
    {
        
ThrowNativeError(SP_ERROR_NATIVE"Admin %d is not connected"admin);
        return;
    }
    if (
client || client MaxClients)
    {
        
        
ThrowNativeError(SP_ERROR_NATIVE"Invalid client index (%d)"client);
        return;
    }
    if (!
IsClientConnected(client))
    {
        
ThrowNativeError(SP_ERROR_NATIVE"Client %d is not connected"client);
        return;
    }
    
grantVip(adminclientdurationformat);
}


public 
int NativeDeleteVip(Handle mypluginint argc)
{
    
char playerid[20];
    
GetNativeString(1playeridsizeof(playerid));
    
StripQuotes(playerid);
    if (
StrContains(playerid"STEAM_") != -1)
        
strcopy(playeridsizeof(playerid), playerid[8]);
    
    
deleteVip(playerid);

__________________
Looking To Start A TF2 Community
My Discord | My Steam

Last edited by ApoziX; 11-03-2018 at 12:50.
ApoziX is offline
 


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 07:59.


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