initial commit
This commit is contained in:
parent
f195d01f7e
commit
009e3f3d48
222
VIP_Test/scripting/VIP_Test.sp
Normal file
222
VIP_Test/scripting/VIP_Test.sp
Normal file
@ -0,0 +1,222 @@
|
||||
#include <sourcemod>
|
||||
|
||||
char g_sAdmGroup[32] = "Game-Donator";
|
||||
|
||||
ConVar g_cvFreeVIPDuration;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Unloze_VIP_Test",
|
||||
author = "Neon",
|
||||
description = "",
|
||||
version = "1.0",
|
||||
url = "https://steamcommunity.com/id/n3ontm"
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_cvFreeVIPDuration = CreateConVar("sm_unloze_vip_test_duration", "1440", "", FCVAR_NONE);
|
||||
|
||||
RegConsoleCmd("sm_viptest", Command_VIP, "Activate free VIP period");
|
||||
RegConsoleCmd("sm_testvip", Command_VIP, "Activate free VIP period");
|
||||
RegConsoleCmd("sm_vip", Command_VIP, "Activate free VIP period");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_VIP(int iClient, int iArgs)
|
||||
{
|
||||
if (!IsValidClient(iClient))
|
||||
return Plugin_Handled;
|
||||
|
||||
CheckMYSQL(iClient, true);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnRebuildAdminCache(AdminCachePart part)
|
||||
{
|
||||
if (part != AdminCache_Admins)
|
||||
return;
|
||||
|
||||
CreateTimer(1.0, OnRebuildAdminCachePost, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientPostAdminFilter(int client)
|
||||
{
|
||||
CheckMYSQL(client);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool CheckMYSQL(int client, bool add = false)
|
||||
{
|
||||
if (client == 0)
|
||||
return false;
|
||||
|
||||
char error[255];
|
||||
Database db;
|
||||
|
||||
if (SQL_CheckConfig("testvip"))
|
||||
{
|
||||
db = SQL_Connect("testvip", true, error, sizeof(error));
|
||||
}
|
||||
|
||||
if (db == null)
|
||||
{
|
||||
LogError("Could not connect to database: %s", error);
|
||||
delete db;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsFakeClient(client) && !IsClientSourceTV(client))
|
||||
{
|
||||
char sSID[64];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
|
||||
char sQuery[255];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSID);
|
||||
DBResultSet rs;
|
||||
if ((rs = SQL_Query(db, sQuery)) == null)
|
||||
{
|
||||
delete db;
|
||||
delete rs;
|
||||
LogError("Database Error: %s", error);
|
||||
return false;
|
||||
}
|
||||
int iTimestamp = GetTime();
|
||||
int iTimestampActivated = GetTime();
|
||||
bool bFound = false;
|
||||
|
||||
if (!(rs.RowCount > 0))
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
bool bHasVIP = false;
|
||||
AdminId AdmID;
|
||||
|
||||
if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID)
|
||||
bHasVIP = false;
|
||||
else
|
||||
{
|
||||
for (int i = 0; i <= GetAdminGroupCount(AdmID); i++)
|
||||
{
|
||||
char sGroup[32];
|
||||
if ((GetAdminGroup(AdmID, i, sGroup, sizeof(sGroup)) != INVALID_GROUP_ID))
|
||||
{
|
||||
if (StrEqual(sGroup, g_sAdmGroup))
|
||||
bHasVIP = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bHasVIP)
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO testvip_table (steam_auth, activated) VALUES ('%s', '%d')", sSID, iTimestamp);
|
||||
SQL_FastQuery(db, sQuery);
|
||||
|
||||
ApplyGroupFlags(client);
|
||||
PrintToChat(client, "[Unloze] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60);
|
||||
PrintToChat(client, "[Unloze] You have now access to !zclass, !tag and !glow.");
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintToChat(client, "[Unloze] You already have VIP activated!");
|
||||
delete db;
|
||||
delete rs;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int iField;
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("activated", iField);
|
||||
iTimestampActivated = rs.FetchInt(iField);
|
||||
bFound = true;
|
||||
}
|
||||
delete rs;
|
||||
|
||||
if (bFound)
|
||||
{
|
||||
if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60)
|
||||
{
|
||||
ApplyGroupFlags(client);
|
||||
PrintToChat(client, "[Unloze] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (add)
|
||||
PrintToChat(client, "[Unloze] Your TEST VIP expired already!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete db;
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock void ApplyGroupFlags(int client)
|
||||
{
|
||||
AdminId AdmID;
|
||||
GroupId GrpID;
|
||||
|
||||
if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID)
|
||||
{
|
||||
LogMessage("Creating new admin for %L", client);
|
||||
|
||||
AdmID = CreateAdmin("");
|
||||
SetUserAdmin(client, AdmID, true);
|
||||
}
|
||||
|
||||
if ((GrpID = FindAdmGroup(g_sAdmGroup)) != INVALID_GROUP_ID)
|
||||
{
|
||||
if (AdminInheritGroup(AdmID, GrpID))
|
||||
LogMessage("%L added to group %s", client, g_sAdmGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage("%L group not found %s", client, g_sAdmGroup);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action OnRebuildAdminCachePost(Handle hTimer)
|
||||
{
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if (IsValidClient(client))
|
||||
CheckMYSQL(client);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock int IsValidClient(int client, bool nobots = true)
|
||||
{
|
||||
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return IsClientInGame(client);
|
||||
}
|
Loading…
Reference in New Issue
Block a user