Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/VIP_Core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <clientprefs>

#if !defined VIP_VERSION
#define VIP_VERSION "3.1.5 R"
#define VIP_VERSION "3.1.6 R"
#endif


Expand Down
39 changes: 30 additions & 9 deletions addons/sourcemod/scripting/vip/API.sp
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,16 @@ public int Native_SetClientVIPGroup(Handle hPlugin, int iNumParams)
if (view_as<bool>(GetNativeCell(3)))
{
int iClientID;
if (g_hFeatures[iClient].GetValue(KEY_CID, iClientID) && iClientID != -1)
if (g_hFeatures[iClient].GetValue(KEY_CID, iClientID) && iClientID != -1 && g_hDatabase)
{
char szQuery[256];
FormatEx(SZF(szQuery), "UPDATE `vip_users` SET `group` = '%s' WHERE `account_id` = %d%s;", szGroup, iClientID, g_szSID);
g_hDatabase.Format(SZF(szQuery), "UPDATE `vip_users` SET `group` = '%s' WHERE `account_id` = %d%s;", szGroup, iClientID, g_szSID);
DBG_SQL_Query(szQuery);
g_hDatabase.Query(SQL_Callback_ChangeClientSettings, szQuery, UID(iClient));

DataPack hPack = new DataPack();
hPack.WriteCell(UID(iClient));
hPack.WriteCell(iClientID);
g_hDatabase.Query(SQL_Callback_ChangeClientSettings, szQuery, hPack);

if (g_CVAR_bLogsEnable)
{
Expand Down Expand Up @@ -483,12 +487,16 @@ public int Native_SetClientAccessTime(Handle hPlugin, int iNumParams)
if (view_as<bool>(GetNativeCell(3)))
{
int iClientID;
if (g_hFeatures[iClient].GetValue(KEY_CID, iClientID) && iClientID != -1)
if (g_hFeatures[iClient].GetValue(KEY_CID, iClientID) && iClientID != -1 && g_hDatabase)
{
char szQuery[256];
FormatEx(SZF(szQuery), "UPDATE `vip_users` SET `expires` = %d WHERE `account_id` = %d%s;", iTime, iClientID, g_szSID);
DBG_SQL_Query(szQuery);
g_hDatabase.Query(SQL_Callback_ChangeClientSettings, szQuery, UID(iClient));

DataPack hPack = new DataPack();
hPack.WriteCell(UID(iClient));
hPack.WriteCell(iClientID);
g_hDatabase.Query(SQL_Callback_ChangeClientSettings, szQuery, hPack);
}
}

Expand All @@ -499,19 +507,32 @@ public int Native_SetClientAccessTime(Handle hPlugin, int iNumParams)
return false;
}

public void SQL_Callback_ChangeClientSettings(Database hOwner, DBResultSet hResult, const char[] szError, any iClient)
public void SQL_Callback_ChangeClientSettings(Database hOwner, DBResultSet hResult, const char[] szError, DataPack hPack)
{
DBG_SQL_Response("SQL_Callback_SelectVipClientInfo");
if (szError[0])

hPack.Reset();
int iClient = CID(hPack.ReadCell());
int iClientID = hPack.ReadCell();
delete hPack;

if (hResult == null || szError[0])
{
LogError("SQL_Callback_ChangeClientSettings: %s", szError);
return;
}

DBG_SQL_Response("hResult.AffectedRows = %d", hResult.AffectedRows);

if ((iClient = CID(iClient)) && hResult.AffectedRows)
if (hResult.AffectedRows)
{
Clients_CheckVipAccess(iClient, false);
// The row changed: drop the cached copy so the reload reads it from the database
DB_RemoveVIPFromCache(iClientID);

if (iClient)
{
Clients_CheckVipAccess(iClient, false);
}
}
}

Expand Down
94 changes: 60 additions & 34 deletions addons/sourcemod/scripting/vip/AdminMenu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,13 @@ public int MenuHandler_TimeMenu(Menu hMenu, MenuAction action, int iClient, int
g_hClientData[iClient].GetValue(DATA_KEY_TargetID, iTarget);
g_hClientData[iClient].SetValue(DATA_KEY_Time, iExpires);

char szQuery[512];
FormatEx(SZF(szQuery), "UPDATE `vip_users` SET `expires` = '%d' WHERE `account_id` = '%d'%s;", iExpires, iTarget, g_szSID);
DBG_SQL_Query(szQuery);
g_hDatabase.Query(SQL_Callback_ChangeTime, szQuery, UID(iClient));
if (g_hDatabase)
{
char szQuery[512];
FormatEx(SZF(szQuery), "UPDATE `vip_users` SET `expires` = '%d' WHERE `account_id` = '%d'%s;", iExpires, iTarget, g_szSID);
DBG_SQL_Query(szQuery);
g_hDatabase.Query(SQL_Callback_ChangeTime, szQuery, iTarget);
}

ShowTargetInfoMenu(iClient);
}
Expand Down Expand Up @@ -561,25 +564,24 @@ public int MenuHandler_GroupsList(Menu hMenu, MenuAction action, int iClient, in
g_hClientData[iClient].GetString(DATA_KEY_Name, SZF(szName));
g_hClientData[iClient].GetString(DATA_KEY_Group, SZF(szOldGroup));

FormatEx(SZF(szQuery), "UPDATE `vip_users` SET `group` = '%s' WHERE `account_id` = %d%s;", szGroup, iTargetID, g_szSID);
if (!g_hDatabase)
{
return 0;
}

DBG_SQL_Query(szQuery);
g_hDatabase.Query(SQL_Callback_ErrorCheck, szQuery);
g_hDatabase.Format(SZF(szQuery), "UPDATE `vip_users` SET `group` = '%s' WHERE `account_id` = %d%s;", szGroup, iTargetID, g_szSID);

int iTarget = 0;
g_hClientData[iClient].GetValue(DATA_KEY_TargetUID, iTarget);
iTarget = CID(iTarget);
if (!iTarget)
{
iTarget = IsClientOnline(iTargetID);
}

if (iTarget)
{
ResetClient(iTarget);
CreateForward_OnVIPClientRemoved(iTarget, "VIP-Group Changed", iClient);
Clients_CheckVipAccess(iTarget, false);
}
// Reload the target once the UPDATE is done, not before
DataPack hPack = new DataPack();
hPack.WriteCell(UID(iClient));
hPack.WriteCell(iTarget);
hPack.WriteCell(iTargetID);

DBG_SQL_Query(szQuery);
g_hDatabase.Query(SQL_Callback_ChangeGroup, szQuery, hPack);

VIP_PrintToChatClient(iClient, "%t", "ADMIN_SET_GROUP", szName, szGroup);
if (g_CVAR_bLogsEnable)
Expand All @@ -599,7 +601,39 @@ public int MenuHandler_GroupsList(Menu hMenu, MenuAction action, int iClient, in
return 0;
}

public void SQL_Callback_ChangeTime(Database hOwner, DBResultSet hResult, const char[] szError, any UserID)
public void SQL_Callback_ChangeGroup(Database hOwner, DBResultSet hResult, const char[] szError, DataPack hPack)
{
DBG_SQL_Response("SQL_Callback_ChangeGroup")

hPack.Reset();
int iClient = CID(hPack.ReadCell());
int iTarget = CID(hPack.ReadCell());
int iTargetID = hPack.ReadCell();
delete hPack;

if (szError[0])
{
LogError("SQL_Callback_ChangeGroup: %s", szError);
return;
}

// The row changed: drop the cached copy so the reload reads it from the database
DB_RemoveVIPFromCache(iTargetID);

if (!iTarget)
{
iTarget = IsClientOnline(iTargetID);
}

if (iTarget)
{
ResetClient(iTarget);
CreateForward_OnVIPClientRemoved(iTarget, "VIP-Group Changed", iClient);
Clients_CheckVipAccess(iTarget, false);
}
}

public void SQL_Callback_ChangeTime(Database hOwner, DBResultSet hResult, const char[] szError, any iTargetID)
{
DBG_SQL_Response("SQL_Callback_ChangeTime")
if (szError[0])
Expand All @@ -612,22 +646,14 @@ public void SQL_Callback_ChangeTime(Database hOwner, DBResultSet hResult, const

if (hResult.AffectedRows)
{
int iClient = CID(UserID);
if (iClient)
{
int iTarget;
g_hClientData[iClient].GetValue(DATA_KEY_TargetUID, iTarget);
iTarget = CID(iTarget);
if(!iTarget)
{
g_hClientData[iClient].GetValue(DATA_KEY_TargetID, iTarget);
iTarget = IsClientOnline(iTarget);
}
// The row changed: drop the cached copy so the reload reads it from the database
DB_RemoveVIPFromCache(iTargetID);

if (iTarget)
{
Clients_CheckVipAccess(iTarget, true);
}
// Resolve the target by account id: the admin may have left or opened another player since
int iTarget = IsClientOnline(iTargetID);
if (iTarget)
{
Clients_CheckVipAccess(iTarget, true);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/vip/CMD.sp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public void SQL_Callback_OnSelectRemoveClient(Database hOwner, DBResultSet hResu
if (hResult == null || szError[0])
{
LogError("SQL_Callback_OnSelectRemoveClient: %s", szError);
return;
}

if (iClient)
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/vip/Clients.sp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void Clients_LoadClient(int iClient, bool bNotify)
return;
}

// If not in cache, query database
Clients_LoadClientFromDB(iClient, iAccountID, bNotify, false);
// If not in cache, query database (and cache the row it returns)
Clients_LoadClientFromDB(iClient, iAccountID, bNotify, true);
}

void Clients_LoadClientFromDB(int iClient, int iAccountID, bool bNotify, bool bUpdateCache)
Expand Down
Loading
Loading