Raised This Month: $106 Target: $400
 26% 

[Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager


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

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 13:50.
ApoziX is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 11-03-2018 , 15:47   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #122

Ok great you posted my whole plugin.
This doesn't even help a bit.
__________________
Developer of the German Games Community
My Website

Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch is offline
ApoziX
Member
Join Date: Sep 2018
Old 11-03-2018 , 16:31   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #123

Quote:
Originally Posted by Totenfluch View Post
Ok great you posted my whole plugin.
This doesn't even help a bit.
When I do !tvip then I choose 1 month It add 1 year instead of 1 month
__________________
Looking To Start A TF2 Community
My Discord | My Steam
ApoziX is offline
gildevanaraujo
Member
Join Date: Oct 2018
Location: Brazil
Old 11-15-2018 , 15:31   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #124

Hello Totenfluch! I have a question regarding the VIP system.
The plugin is running 100%, with no errors. But when I add a vip to a person, it does not take the tag that has been selected for the "VIP".
Example: I configured so that the 15 (Custom1), flag "o" is the VIP, and in the tag system too, but I add the vip to the person, it reconnects to the server but does not change at all. Not even the commands that were pre-set for the VIP.
Can you help me?
gildevanaraujo is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 11-15-2018 , 15:43   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #125

Quote:
Originally Posted by gildevanaraujo View Post
Hello Totenfluch! I have a question regarding the VIP system.
The plugin is running 100%, with no errors. But when I add a vip to a person, it does not take the tag that has been selected for the "VIP".
Example: I configured so that the 15 (Custom1), flag "o" is the VIP, and in the tag system too, but I add the vip to the person, it reconnects to the server but does not change at all. Not even the commands that were pre-set for the VIP.
Can you help me?
Ask in the Plugin thread of the Tag-Plugin/Vip-Plugin developer for tVip Support. There is nothing I can do here.
__________________
Developer of the German Games Community
My Website

Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...

Last edited by Totenfluch; 11-15-2018 at 15:44.
Totenfluch is offline
gildevanaraujo
Member
Join Date: Oct 2018
Location: Brazil
Old 11-15-2018 , 16:18   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #126

Quote:
Originally Posted by Totenfluch View Post
Ask in the Plugin thread of the Tag-Plugin/Vip-Plugin developer for tVip Support. There is nothing I can do here.
I understand, but even adding user vip to ADMFLAG_CUSTOM1 (15 / o), it will not go to the user. Thus, making it impossible to use "vip commands".
gildevanaraujo is offline
Notifications
AlliedModders Donor
Join Date: Oct 2015
Old 11-15-2018 , 22:43   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #127

@Totenfluch, just to confirm with this plugin - Tag A (Generic_Reserved) would be 0 or 1 when inputting it into the TVIP cfg?
The link you provided shows
#define ADMFLAG_RESERVATION (1<<0) /**< Convenience macro for Admin_Reservation as a FlagBit */
but it's still a bit over my head lmao
Notifications is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 11-16-2018 , 09:21   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #128

Quote:
Originally Posted by Notifications View Post
@Totenfluch, just to confirm with this plugin - Tag A (Generic_Reserved) would be 0 or 1 when inputting it into the TVIP cfg?
The link you provided shows
#define ADMFLAG_RESERVATION (1<<0) /**< Convenience macro for Admin_Reservation as a FlagBit */
but it's still a bit over my head lmao

Reservation Flag is 0 hence the macro
__________________
Developer of the German Games Community
My Website

Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 11-16-2018 , 09:22   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #129

Quote:
Originally Posted by gildevanaraujo View Post
I understand, but even adding user vip to ADMFLAG_CUSTOM1 (15 / o), it will not go to the user. Thus, making it impossible to use "vip commands".
If the user has the flag with "sm_who" after adding him to the vips and he can't use the command it's the other plugin.
__________________
Developer of the German Games Community
My Website

Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch is offline
nephh
New Member
Join Date: Nov 2018
Old 11-16-2018 , 23:30   Re: [Any][MySQL] tVip (2.1 | 27-06-17) - The simplest to use Vip Manager
Reply With Quote #130

So I've got the plugin installed no problems. I can pull up the menu and add and remove people from the database, at least, the console is telling me that they are being added to the database, with zero errors. Problem is I don't have a tVip table in my database for some reason. When I connect to the server I get [tVip.smx] Table '5bef012bff716a695cb608d1.tVip' doesn't exist.

I read that there was a script to create the table but I'm still pretty new to all of this so I'm not sure where or what that script would be.

Here is my databases.cfg:
Code:
"Databases"
{
	"driver_default"		"mysql"
	
	// When specifying "host", you may use an IP address, a hostname, or a socket file path
	
	"default"
	{
		"driver"			"default"
		"host"				"localhost"
		"database"			"sourcemod"
		"user"				"root"
		"pass"				""
		//"timeout"			"0"
		//"port"			"0"
	}
	
	"storage-local"
	{
		"driver"			"sqlite"
		"database"			"sourcemod-local"
	}

	"clientprefs"
	{
		"driver"			"sqlite"
		"host"				"localhost"
		"database"			"clientprefs-sqlite"
		"user"				"root"
		"pass"				""
		//"timeout"			"0"
		//"port"			"0"
	}

	"retakes"
	{
	        "driver"            "sqlite"
	        "host"                "localhost"
	        "database"            "retakes-sqlite"
	        "user"                "root"
	        "pass"                ""
	}

	"kztimer"
	{
	  "driver"         "sqlite"
	  "host"           "localhost"
	  "database"       "kztimer-sqlite"
	  "user"           "root"
	  "pass"           ""
	}

	"cksurf"
	{
		"driver"    "sqlite"
		"host"  	"localhost"
		"database"  "cksurf-sqlite"
		"user"  	"root"
		"pass"  	""
	}

    "executes"
    {
        "driver"              "sqlite"
        "host"                "localhost"
        "database"        "executes-sqlite"
        "user"                "root"
        "pass"                ""
    }
	
	"tVip"
	{
		"driver" "mysql"
		"host" "mysql.local"
		"database" "5bef012bff716a695cb608d1"
		"user" "W-8BK_9xamlctgjR"
		"pass" "****"
		//"timeout" "0"
		"port" "3306"
	}

	"mostactive"
	{
	"driver" "mysql"
	"host" "mysql.local"
	"database" "5bef012bff716a695cb608d1"
	"user" "W-8BK_9xamlctgjR"
	"pass" "****"
	"port" "3306"
	}
}
Thanks for the help in advance
__________________
24/7 hostage maps @ hostagelovers.game.nfoservers.com:27015

Last edited by nephh; 11-16-2018 at 23:31.
nephh 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 13:46.


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