You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

207 lines
6.2 KiB

#include <sourcemod>
//#include <morecolors>
#pragma newdecls required
Handle hDatabase = INVALID_HANDLE;
enum struct PlayerStatus {
int time_remain;
int status;
}
PlayerStatus VipTimeLeft[MAXPLAYERS+1];
//SELECT `status`,UNIX_TIMESTAMP(`reg_date`), amount FROM `sm_admins` WHERE 1
/*CONNECTS*/
/*public bool OnClientConnect(int client, char[] rejectmsg, int maxlen)
{
PrintToServer("Get %d client permitions", client);
GetClientPermitions(client);
}*/
/*
public void OnClientAuthorized(int client)
{
GetClientPermitions(client);
}
*/
public void OnClientPostAdminCheck(int client) {
GetClientPermitions(client);
}
public void OnClientDisconnect(int client)
{
VipTimeLeft[client].time_remain = 0;
VipTimeLeft[client].status = 0;
}
/*CONNECTS*/
public Plugin myinfo =
{
name = "Facti13 VIP",
author = "gsd",
description = "Get user's SteamID",
version = "1.1",
url = "https://vk.com/facti13"
}
public bool DrawTime(int client, char[] time_string, int size_string){
if (VipTimeLeft[client].time_remain > 0) {
int day = VipTimeLeft[client].time_remain / (24 * 3600);
if (day == 0){
int n = VipTimeLeft[client].time_remain % (24 * 3600);
int hour = n / 3600;
Format(time_string, size_string, "%d часов", hour);
} else {
Format(time_string, size_string, "%d дней", day);
}
} else {
Format(time_string, size_string, "бесконечны");
}
}
/*SQL FUNCTIONS*/
public void GotDatabase(Handle owner, Handle hndl, const char[] error, any data) {
if (hndl == INVALID_HANDLE) {
LogError("Database Connection Error: %s", error);
} else {
hDatabase = hndl;
/*////////////////////////////////////////
for(int i = 1; i < MAXPLAYERS; i++){
if(IsClientInGame(i)){
GetClientPermitions(i);
}
}*/
}
}
int GetClientPermitions(int client){
char Query[512];
char SteamID[32];
GetClientAuthId(client, AuthId_Steam2, SteamID, sizeof(SteamID));
Format(Query, sizeof(Query), "SELECT status, extract(epoch from reg_date), amount FROM sm_admins WHERE identity LIKE '%s'", SteamID);
//LogMessage(Query);
SQL_TQuery(hDatabase, GetClientPermitionsCallback, Query, GetClientUserId(client));
return 0;
}
stock void GetClientPermitionsCallback(Handle owner, Handle hndl, char [] error, any data) {
int client;
if((client = GetClientOfUserId(data)) == 0)
{
return;
}
////////////////////////////////////////////
if(hndl == INVALID_HANDLE)
{
LogError("Query failure: %s", error);
return;
}
////////////////////////////////////////////
if (SQL_FetchRow(hndl)) {
char status[16];
SQL_FetchString(hndl, 0, status, sizeof(status));
if(StrEqual(status, "VIP")) VipTimeLeft[client].status = 1;
if(StrEqual(status, "MOD")) VipTimeLeft[client].status = 2;
if(StrEqual(status, "admin")) VipTimeLeft[client].status = 3;
/*
} else {
VipTimeLeft[client].status = 3;
}
*/
//////////////////////////////////////////////////
int TimeRemainig = SQL_FetchInt(hndl, 1) + SQL_FetchInt(hndl, 2) - GetTime();
if (TimeRemainig >= 0 && !SQL_FetchInt(hndl, 2) == 0){
VipTimeLeft[client].time_remain = TimeRemainig;
} else {
VipTimeLeft[client].time_remain = 0;
}
}
return;
}
stock void ConnectDB(){
SQL_TConnect(GotDatabase, "admins");
}
/*SQL FUNCTIONS*/
public void OnPluginStart(){
RegConsoleCmd("sm_vip", Command_newVIP);
ConnectDB();
for(int i = 1; i < MAXPLAYERS; i++){
VipTimeLeft[i].time_remain = 0;
VipTimeLeft[i].status = 0;
}
}
/*USER COMMANDS*/
public Action Command_MySID(int client, int args)
{
//char steamid[64];
//if(GetClientAuthId(client, AuthId_Steam2, steamid, 64))
//CPrintToChat(client, "\n{yellow}Твой SteamID: {magenta}%s\n{orangered}Проверь до конца ли ты его скопировал!\n{yellow}Купить ВИП можно по ссылке: https://vk.cc/bWaAMG\n",steamid);
//else
//CPrintToChat(client, "{fullred}Невозможно получить твой SteamID");
PrintToChat(client, "Как купить вип узнай на нашем сайте, еблан");
return Plugin_Handled;
}
public int Select_Panel(Handle panel, MenuAction action, int client, int option) {
switch (action){
case MenuAction_End:delete panel;
}
}
public Action Command_newVIP(int client, int args)
{
char steamid[64];
GetClientAuthId(client, AuthId_Steam2, steamid, 64);
Menu VipMenu = CreateMenu(BuyCB);
char PlayerInformation[256];
StrCat(PlayerInformation, sizeof(PlayerInformation), "Информация о тебе:\n");
/////////////////////////////////////
StrCat(PlayerInformation, sizeof(PlayerInformation), "Твой SteamID:\n");
StrCat(PlayerInformation, sizeof(PlayerInformation), steamid);
StrCat(PlayerInformation, sizeof(PlayerInformation), "\n");
/////////////////////////////////////
StrCat(PlayerInformation, sizeof(PlayerInformation), "Текущий статус:\n");
switch (VipTimeLeft[client].status){
case 0:StrCat(PlayerInformation, sizeof(PlayerInformation), "Обычный игрок");
case 1:StrCat(PlayerInformation, sizeof(PlayerInformation), "VIP игрок");
case 2:StrCat(PlayerInformation, sizeof(PlayerInformation), "Модератор");
case 3:StrCat(PlayerInformation, sizeof(PlayerInformation), "Администратор");
case 4:StrCat(PlayerInformation, sizeof(PlayerInformation), "Неизвестно");
}
StrCat(PlayerInformation, sizeof(PlayerInformation), "\n");
/////////////////////////////////////
if (VipTimeLeft[client].status > 0){
StrCat(PlayerInformation, sizeof(PlayerInformation), "Кончаются через:\n");
char time[32];
DrawTime(client, time, sizeof(time));
StrCat(PlayerInformation, sizeof(PlayerInformation), time);
} else {
StrCat(PlayerInformation, sizeof(PlayerInformation), "Купить VIP:\n");
StrCat(PlayerInformation, sizeof(PlayerInformation), "!buyvip");
}
StrCat(PlayerInformation, sizeof(PlayerInformation), "\n");
SetMenuTitle(VipMenu, PlayerInformation);
AddMenuItem(VipMenu, "buy", "Купить сразу");
DisplayMenu(VipMenu, client, 0);
SetMenuExitButton(VipMenu, true);
return Plugin_Handled;
}
public int BuyCB(Handle menuhandle, MenuAction action, int client, int pos){
switch(action){
case MenuAction_Select:{FakeClientCommand(client, "sm_buyvip");}
case MenuAction_End:{delete menuhandle;}
}
}