added support for spray hiding multiple people automatic on connection

This commit is contained in:
jenz 2022-06-06 23:41:31 +02:00
parent 16edc14753
commit ad3af6e817

View File

@ -84,7 +84,7 @@ public Plugin myinfo =
name = "Spray Manager",
description = "A plugin to help manage player sprays.",
author = "Obus",
version = "2.1.0",
version = "2.1.1",
url = ""
}
@ -246,39 +246,78 @@ public void CvarQueryFinished_SprayLifeTime(QueryCookie cookie, int client, ConV
g_iClientSprayLifetime[client] = iVal <= 0 ? 1 : iVal > 1000 ? 1000 : iVal;
}
public void select_sprays_to_hide(Handle hParent, Handle hChild, const char[] err, any client)
{
if (!IsValidClient(client))
return;
if (hChild == null)
{
LogError("failed selecting hidden sprays (%s)", err);
return;
}
while (SQL_FetchRow(hChild))
{
char sAuthID[32];
SQL_FetchString(hChild, 0, sAuthID, sizeof(sAuthID));
for (int i = 1; i <= MaxClients; i++)
{
if (!IsValidClient(i) || IsFakeClient(i))
continue;
char sAuthID_target[32];
GetClientAuthId(i, AuthId_Steam2, sAuthID_target, sizeof(sAuthID_target), false);
if (StrEqual(sAuthID, sAuthID_target))
{
g_bHasSprayHidden[client][i] = true;
PaintWorldDecalToOne(g_iHiddenDecalIndex, g_vecSprayOrigin[i], client);
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
}
}
}
}
public void OnClientPostAdminCheck(int client)
{
if (g_hDatabase != null)
{
ClearPlayerInfo(client);
GetPlayerDecalFile(client, g_sSprayHash[client], sizeof(g_sSprayHash[]));
UpdatePlayerInfo(client);
UpdateSprayHashInfo(client);
UpdateNSFWInfo(client);
}
if (g_hDatabase != null)
{
ClearPlayerInfo(client);
GetPlayerDecalFile(client, g_sSprayHash[client], sizeof(g_sSprayHash[]));
UpdatePlayerInfo(client);
UpdateSprayHashInfo(client);
UpdateNSFWInfo(client);
if (g_cvarSendSpraysToConnectingClients.BoolValue)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsValidClient(i) || IsFakeClient(i))
continue;
char sAuthID[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT `steamidtarget` FROM `sprayhidemanage` WHERE `steamidhider` = '%s';", sAuthID);
if (IsVectorZero(g_vecSprayOrigin[i]))
continue;
SQL_TQuery(g_hDatabase, select_sprays_to_hide, sQuery, client, DBPrio_High);
}
if (g_bHasNSFWSpray[i] && !g_bWantsToSeeNSFWSprays[client])
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[i], client);
continue;
}
if (g_cvarSendSpraysToConnectingClients.BoolValue)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsValidClient(i) || IsFakeClient(i))
continue;
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, g_iDecalEntity[i], g_vecSprayOrigin[i]);
g_iClientToClientSprayLifetime[client][i] = 0;
g_bSkipDecalHook = false;
}
}
if (IsVectorZero(g_vecSprayOrigin[i]))
continue;
if (g_bHasNSFWSpray[i] && !g_bWantsToSeeNSFWSprays[client])
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[i], client);
continue;
}
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, g_iDecalEntity[i], g_vecSprayOrigin[i]);
g_iClientToClientSprayLifetime[client][i] = 0;
g_bSkipDecalHook = false;
}
}
}
public void OnClientDisconnect(int client)
@ -1603,128 +1642,165 @@ public Action Command_NSFW(int client, int argc)
public Action Command_HideSpray(int client, int argc)
{
if (!client)
{
ReplyToCommand(client, "[SprayManager] Cannot use command from server console.");
return Plugin_Handled;
}
if (!client)
{
ReplyToCommand(client, "[SprayManager] Cannot use command from server console.");
return Plugin_Handled;
}
if (argc > 0)
{
int iTarget;
char sArg[64];
if (argc > 0)
{
int iTarget;
char sArg[64];
GetCmdArg(1, sArg, sizeof(sArg));
GetCmdArg(1, sArg, sizeof(sArg));
if ((iTarget = FindTarget(client, sArg, false, false)) <= 0)
return Plugin_Handled;
if ((iTarget = FindTarget(client, sArg, false, false)) <= 0)
return Plugin_Handled;
g_bHasSprayHidden[client][iTarget] = true;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", iTarget);
g_bHasSprayHidden[client][iTarget] = true;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", iTarget); //'
char sAuthID[32];
char sAuthID_target[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
GetClientAuthId(iTarget, AuthId_Steam2, sAuthID_target, sizeof(sAuthID_target), false);
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT IGNORE INTO `sprayhidemanage` (`steamidhider`, `steamidtarget`) VALUES ('%s', '%s');", sAuthID, sAuthID_target);
PaintWorldDecalToOne(g_iHiddenDecalIndex, g_vecSprayOrigin[iTarget], client);
g_bSkipDecalHook = true;
SprayClientDecalToOne(iTarget, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
SQL_TQuery(g_hDatabase, DummyCallback, sQuery);
return Plugin_Handled;
}
PaintWorldDecalToOne(g_iHiddenDecalIndex, g_vecSprayOrigin[iTarget], client);
g_bSkipDecalHook = true;
SprayClientDecalToOne(iTarget, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
float vecEndPos[3];
return Plugin_Handled;
}
if (TracePlayerAngles(client, vecEndPos))
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
float vecEndPos[3];
g_bHasSprayHidden[client][i] = true;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", i);
if (TracePlayerAngles(client, vecEndPos))
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
PaintWorldDecalToOne(g_iHiddenDecalIndex, g_vecSprayOrigin[i], client);
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
g_bHasSprayHidden[client][i] = true;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", i); //'
return Plugin_Handled;
}
}
char sAuthID[32];
char sAuthID_target[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
GetClientAuthId(i, AuthId_Steam2, sAuthID_target, sizeof(sAuthID_target), false);
PrintToChat(client, "\x01\x04[SprayManager]\x01 No spray could be found.");
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT IGNORE INTO `sprayhidemanage` (`steamidhider`, `steamidtarget`) VALUES ('%s', '%s');", sAuthID, i);
return Plugin_Handled;
SQL_TQuery(g_hDatabase, DummyCallback, sQuery);
PaintWorldDecalToOne(g_iHiddenDecalIndex, g_vecSprayOrigin[i], client);
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
return Plugin_Handled;
}
}
PrintToChat(client, "\x01\x04[SprayManager]\x01 No spray could be found.");
return Plugin_Handled;
}
public Action Command_UnhideSpray(int client, int argc)
{
if (!client)
{
ReplyToCommand(client, "[SprayManager] Cannot use command from server console.");
return Plugin_Handled;
}
if (!client)
{
ReplyToCommand(client, "[SprayManager] Cannot use command from server console.");
return Plugin_Handled;
}
if (argc > 0)
{
int iTarget;
char sArg[64];
if (argc > 0)
{
int iTarget;
char sArg[64];
GetCmdArg(1, sArg, sizeof(sArg));
GetCmdArg(1, sArg, sizeof(sArg));
if ((iTarget = FindTarget(client, sArg, false, false)) <= 0)
return Plugin_Handled;
if ((iTarget = FindTarget(client, sArg, false, false)) <= 0)
return Plugin_Handled;
g_bHasSprayHidden[client][iTarget] = false;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", iTarget);
g_bHasSprayHidden[client][iTarget] = false;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", iTarget); // '
PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[iTarget], client);
char sAuthID[32];
char sAuthID_target[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
GetClientAuthId(iTarget, AuthId_Steam2, sAuthID_target, sizeof(sAuthID_target), false);
char sQuery[512];
Format(sQuery, sizeof(sQuery), "DELETE FROM `sprayhidemanage` WHERE `steamidhider` = '%s' and `steamidtarget` = '%s';", sAuthID, sAuthID_target);
if (!g_bWantsToSeeNSFWSprays[client] && g_bHasNSFWSpray[iTarget])
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[iTarget], client);
return Plugin_Handled;
}
SQL_TQuery(g_hDatabase, DummyCallback, sQuery);
g_bSkipDecalHook = true;
SprayClientDecalToOne(iTarget, client, g_iDecalEntity[iTarget], g_vecSprayOrigin[iTarget]);
g_iClientToClientSprayLifetime[client][iTarget] = 0;
g_bSkipDecalHook = false;
PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[iTarget], client);
return Plugin_Handled;
}
if (!g_bWantsToSeeNSFWSprays[client] && g_bHasNSFWSpray[iTarget])
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[iTarget], client);
return Plugin_Handled;
}
float vecEndPos[3];
g_bSkipDecalHook = true;
SprayClientDecalToOne(iTarget, client, g_iDecalEntity[iTarget], g_vecSprayOrigin[iTarget]);
g_iClientToClientSprayLifetime[client][iTarget] = 0;
g_bSkipDecalHook = false;
if (TracePlayerAngles(client, vecEndPos))
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
return Plugin_Handled;
}
g_bHasSprayHidden[client][i] = false;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", i);
float vecEndPos[3];
PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[i], client);
if (TracePlayerAngles(client, vecEndPos))
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
if (!g_bWantsToSeeNSFWSprays[client] && g_bHasNSFWSpray[i])
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[i], client);
return Plugin_Handled;
}
g_bHasSprayHidden[client][i] = false;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", i); //'
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, g_iDecalEntity[i], g_vecSprayOrigin[i]);
g_iClientToClientSprayLifetime[client][i] = 0;
g_bSkipDecalHook = false;
char sAuthID[32];
char sAuthID_target[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
GetClientAuthId(i, AuthId_Steam2, sAuthID_target, sizeof(sAuthID_target), false);
char sQuery[512];
Format(sQuery, sizeof(sQuery), "DELETE FROM `sprayhidemanage` WHERE `steamidhider` = '%s' and `steamidtarget` = '%s';", sAuthID, sAuthID_target);
return Plugin_Handled;
}
}
SQL_TQuery(g_hDatabase, DummyCallback, sQuery);
PrintToChat(client, "\x01\x04[SprayManager]\x01 No spray could be found.");
PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[i], client);
return Plugin_Handled;
if (!g_bWantsToSeeNSFWSprays[client] && g_bHasNSFWSpray[i])
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[i], client);
return Plugin_Handled;
}
g_bSkipDecalHook = true;
SprayClientDecalToOne(i, client, g_iDecalEntity[i], g_vecSprayOrigin[i]);
g_iClientToClientSprayLifetime[client][i] = 0;
g_bSkipDecalHook = false;
return Plugin_Handled;
}
}
PrintToChat(client, "\x01\x04[SprayManager]\x01 No spray could be found.");
return Plugin_Handled;
}
public Action Command_AdminSpray(int client, int argc)
@ -2410,36 +2486,38 @@ void InitializeSQL()
public void OnSQLConnected(Handle hParent, Handle hChild, const char[] err, any data)
{
if (hChild == null)
{
LogError("Failed to connect to database, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, ReconnectSQL);
if (hChild == null)
{
LogError("Failed to connect to database, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, ReconnectSQL);
return;
}
return;
}
char sDriver[16];
g_hDatabase = CloneHandle(hChild);
SQL_GetDriverIdent(hParent, sDriver, sizeof(sDriver));
char sDriver[16];
g_hDatabase = CloneHandle(hChild);
SQL_GetDriverIdent(hParent, sDriver, sizeof(sDriver));
if (!strncmp(sDriver, "my", 2, false))
{
SQL_TQuery(g_hDatabase, DummyCallback, "SET NAMES \"UTF8\"");
if (!strncmp(sDriver, "my", 2, false))
{
SQL_TQuery(g_hDatabase, DummyCallback, "SET NAMES \"UTF8\"");
SQL_TQuery(g_hDatabase, OnSQLTableCreated, "CREATE TABLE IF NOT EXISTS `spraymanager` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `unbantime` INT, `issuersteamid` VARCHAR(32), `issuername` VARCHAR(32) NOT NULL, `issuedtime` INT, `issuedreason` VARCHAR(64) NOT NULL, PRIMARY KEY(steamid)) CHARACTER SET utf8 COLLATE utf8_general_ci;");
SQL_TQuery(g_hDatabase, OnSQLSprayBlacklistCreated, "CREATE TABLE IF NOT EXISTS `sprayblacklist` (`sprayhash` VARCHAR(16) NOT NULL, `sprayer` VARCHAR(32) NOT NULL, `sprayersteamid` VARCHAR(32), PRIMARY KEY(sprayhash)) CHARACTER SET utf8 COLLATE utf8_general_ci;");
SQL_TQuery(g_hDatabase, OnSQLNSFWListCreated, "CREATE TABLE IF NOT EXISTS `spraynsfwlist` (`sprayhash` VARCHAR(16) NOT NULL, `sprayersteamid` VARCHAR(32), `setbyadmin` TINYINT, PRIMARY KEY(sprayhash)) CHARACTER SET utf8 COLLATE utf8_general_ci");
SQL_TQuery(g_hDatabase, OnSQLTableCreated, "CREATE TABLE IF NOT EXISTS `spraymanager` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `unbantime` INT, `issuersteamid` VARCHAR(32), `issuername` VARCHAR(32) NOT NULL, `issuedtime` INT, `issuedreason` VARCHAR(64) NOT NULL, PRIMARY KEY(steamid)) CHARACTER SET utf8 COLLATE utf8_general_ci;");
SQL_TQuery(g_hDatabase, OnSQLSprayBlacklistCreated, "CREATE TABLE IF NOT EXISTS `sprayblacklist` (`sprayhash` VARCHAR(16) NOT NULL, `sprayer` VARCHAR(32) NOT NULL, `sprayersteamid` VARCHAR(32), PRIMARY KEY(sprayhash)) CHARACTER SET utf8 COLLATE utf8_general_ci;");
SQL_TQuery(g_hDatabase, OnSQLNSFWListCreated, "CREATE TABLE IF NOT EXISTS `spraynsfwlist` (`sprayhash` VARCHAR(16) NOT NULL, `sprayersteamid` VARCHAR(32), `setbyadmin` TINYINT, PRIMARY KEY(sprayhash)) CHARACTER SET utf8 COLLATE utf8_general_ci");
SQL_TQuery(g_hDatabase, DummyCallback, "CREATE TABLE IF NOT EXISTS `sprayhidemanage` (`steamidhider` varchar(32), `steamidtarget` varchar(32), PRIMARY KEY (`steamidhider`, `steamidtarget`))");
g_bSQLite = false;
}
else
{
SQL_TQuery(g_hDatabase, OnSQLTableCreated, "CREATE TABLE IF NOT EXISTS `spraymanager` (`steamid` TEXT NOT NULL, `name` TEXT DEFAULT 'unknown', `unbantime` INTEGER, `issuersteamid` TEXT, `issuername` TEXT DEFAULT 'unknown', `issuedtime` INTEGER NOT NULL, `issuedreason` TEXT DEFAULT 'none', PRIMARY KEY(steamid));");
SQL_TQuery(g_hDatabase, OnSQLSprayBlacklistCreated, "CREATE TABLE IF NOT EXISTS `sprayblacklist` (`sprayhash` TEXT NOT NULL, `sprayer` TEXT DEFAULT 'unknown', `sprayersteamid` TEXT, PRIMARY KEY(sprayhash));");
SQL_TQuery(g_hDatabase, OnSQLNSFWListCreated, "CREATE TABLE IF NOT EXISTS `spraynsfwlist` (`sprayhash` TEXT NOT NULL, `sprayersteamid` TEXT, `setbyadmin` INTEGER, PRIMARY KEY(sprayhash));");
g_bSQLite = false;
}
else
{
SQL_TQuery(g_hDatabase, OnSQLTableCreated, "CREATE TABLE IF NOT EXISTS `spraymanager` (`steamid` TEXT NOT NULL, `name` TEXT DEFAULT 'unknown', `unbantime` INTEGER, `issuersteamid` TEXT, `issuername` TEXT DEFAULT 'unknown', `issuedtime` INTEGER NOT NULL, `issuedreason` TEXT DEFAULT 'none', PRIMARY KEY(steamid));");
SQL_TQuery(g_hDatabase, OnSQLSprayBlacklistCreated, "CREATE TABLE IF NOT EXISTS `sprayblacklist` (`sprayhash` TEXT NOT NULL, `sprayer` TEXT DEFAULT 'unknown', `sprayersteamid` TEXT, PRIMARY KEY(sprayhash));");
SQL_TQuery(g_hDatabase, OnSQLNSFWListCreated, "CREATE TABLE IF NOT EXISTS `spraynsfwlist` (`sprayhash` TEXT NOT NULL, `sprayersteamid` TEXT, `setbyadmin` INTEGER, PRIMARY KEY(sprayhash));");
SQL_TQuery(g_hDatabase, DummyCallback, "CREATE TABLE IF NOT EXISTS `sprayhidemanage` (`steamidhider` TEXT, `steamidtarget` TEXT, PRIMARY KEY (`steamidhider`, `steamidtarget`))");
g_bSQLite = true;
}
g_bSQLite = true;
}
}
public Action ReconnectSQL(Handle hTimer)
@ -3243,4 +3321,4 @@ stock bool IsValidClient(int client)
return false;
return IsClientAuthorized(client);
}
}