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", name = "Spray Manager",
description = "A plugin to help manage player sprays.", description = "A plugin to help manage player sprays.",
author = "Obus", author = "Obus",
version = "2.1.0", version = "2.1.1",
url = "" url = ""
} }
@ -246,39 +246,78 @@ public void CvarQueryFinished_SprayLifeTime(QueryCookie cookie, int client, ConV
g_iClientSprayLifetime[client] = iVal <= 0 ? 1 : iVal > 1000 ? 1000 : iVal; 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) public void OnClientPostAdminCheck(int client)
{ {
if (g_hDatabase != null) if (g_hDatabase != null)
{ {
ClearPlayerInfo(client); ClearPlayerInfo(client);
GetPlayerDecalFile(client, g_sSprayHash[client], sizeof(g_sSprayHash[])); GetPlayerDecalFile(client, g_sSprayHash[client], sizeof(g_sSprayHash[]));
UpdatePlayerInfo(client); UpdatePlayerInfo(client);
UpdateSprayHashInfo(client); UpdateSprayHashInfo(client);
UpdateNSFWInfo(client); UpdateNSFWInfo(client);
}
if (g_cvarSendSpraysToConnectingClients.BoolValue) char sAuthID[32];
{ GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
for (int i = 1; i <= MaxClients; i++) char sQuery[512];
{ Format(sQuery, sizeof(sQuery), "SELECT `steamidtarget` FROM `sprayhidemanage` WHERE `steamidhider` = '%s';", sAuthID);
if (!IsValidClient(i) || IsFakeClient(i))
continue;
if (IsVectorZero(g_vecSprayOrigin[i])) SQL_TQuery(g_hDatabase, select_sprays_to_hide, sQuery, client, DBPrio_High);
continue; }
if (g_bHasNSFWSpray[i] && !g_bWantsToSeeNSFWSprays[client]) if (g_cvarSendSpraysToConnectingClients.BoolValue)
{ {
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[i], client); for (int i = 1; i <= MaxClients; i++)
continue; {
} if (!IsValidClient(i) || IsFakeClient(i))
continue;
g_bSkipDecalHook = true; if (IsVectorZero(g_vecSprayOrigin[i]))
SprayClientDecalToOne(i, client, g_iDecalEntity[i], g_vecSprayOrigin[i]); continue;
g_iClientToClientSprayLifetime[client][i] = 0;
g_bSkipDecalHook = false; 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) 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) public Action Command_HideSpray(int client, int argc)
{ {
if (!client) if (!client)
{ {
ReplyToCommand(client, "[SprayManager] Cannot use command from server console."); ReplyToCommand(client, "[SprayManager] Cannot use command from server console.");
return Plugin_Handled; return Plugin_Handled;
} }
if (argc > 0) if (argc > 0)
{ {
int iTarget; int iTarget;
char sArg[64]; char sArg[64];
GetCmdArg(1, sArg, sizeof(sArg)); GetCmdArg(1, sArg, sizeof(sArg));
if ((iTarget = FindTarget(client, sArg, false, false)) <= 0) if ((iTarget = FindTarget(client, sArg, false, false)) <= 0)
return Plugin_Handled; return Plugin_Handled;
g_bHasSprayHidden[client][iTarget] = true; g_bHasSprayHidden[client][iTarget] = true;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", iTarget); 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); SQL_TQuery(g_hDatabase, DummyCallback, sQuery);
g_bSkipDecalHook = true;
SprayClientDecalToOne(iTarget, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
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)) float vecEndPos[3];
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
g_bHasSprayHidden[client][i] = true; if (TracePlayerAngles(client, vecEndPos))
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", i); {
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
PaintWorldDecalToOne(g_iHiddenDecalIndex, g_vecSprayOrigin[i], client); g_bHasSprayHidden[client][i] = true;
g_bSkipDecalHook = true; PrintToChat(client, "\x01\x04[SprayManager]\x01 You have hidden \x04%N\x01's spray.", i); //'
SprayClientDecalToOne(i, client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false;
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) public Action Command_UnhideSpray(int client, int argc)
{ {
if (!client) if (!client)
{ {
ReplyToCommand(client, "[SprayManager] Cannot use command from server console."); ReplyToCommand(client, "[SprayManager] Cannot use command from server console.");
return Plugin_Handled; return Plugin_Handled;
} }
if (argc > 0) if (argc > 0)
{ {
int iTarget; int iTarget;
char sArg[64]; char sArg[64];
GetCmdArg(1, sArg, sizeof(sArg)); GetCmdArg(1, sArg, sizeof(sArg));
if ((iTarget = FindTarget(client, sArg, false, false)) <= 0) if ((iTarget = FindTarget(client, sArg, false, false)) <= 0)
return Plugin_Handled; return Plugin_Handled;
g_bHasSprayHidden[client][iTarget] = false; g_bHasSprayHidden[client][iTarget] = false;
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", iTarget); 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]) SQL_TQuery(g_hDatabase, DummyCallback, sQuery);
{
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[iTarget], client);
return Plugin_Handled;
}
g_bSkipDecalHook = true; PaintWorldDecalToOne(g_iTransparentDecalIndex, g_vecSprayOrigin[iTarget], client);
SprayClientDecalToOne(iTarget, client, g_iDecalEntity[iTarget], g_vecSprayOrigin[iTarget]);
g_iClientToClientSprayLifetime[client][iTarget] = 0;
g_bSkipDecalHook = false;
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)) return Plugin_Handled;
{ }
for (int i = 1; i <= MaxClients; i++)
{
if (!IsPointInsideAABB(vecEndPos, g_SprayAABB[i]))
continue;
g_bHasSprayHidden[client][i] = false; float vecEndPos[3];
PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", i);
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]) g_bHasSprayHidden[client][i] = false;
{ PrintToChat(client, "\x01\x04[SprayManager]\x01 You have unhidden \x04%N\x01's spray.", i); //'
PaintWorldDecalToOne(g_iNSFWDecalIndex, g_vecSprayOrigin[i], client);
return Plugin_Handled;
}
g_bSkipDecalHook = true; char sAuthID[32];
SprayClientDecalToOne(i, client, g_iDecalEntity[i], g_vecSprayOrigin[i]); char sAuthID_target[32];
g_iClientToClientSprayLifetime[client][i] = 0; GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
g_bSkipDecalHook = 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) 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) public void OnSQLConnected(Handle hParent, Handle hChild, const char[] err, any data)
{ {
if (hChild == null) if (hChild == null)
{ {
LogError("Failed to connect to database, retrying in 10 seconds. (%s)", err); LogError("Failed to connect to database, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, ReconnectSQL); CreateTimer(10.0, ReconnectSQL);
return; return;
} }
char sDriver[16]; char sDriver[16];
g_hDatabase = CloneHandle(hChild); g_hDatabase = CloneHandle(hChild);
SQL_GetDriverIdent(hParent, sDriver, sizeof(sDriver)); SQL_GetDriverIdent(hParent, sDriver, sizeof(sDriver));
if (!strncmp(sDriver, "my", 2, false)) if (!strncmp(sDriver, "my", 2, false))
{ {
SQL_TQuery(g_hDatabase, DummyCallback, "SET NAMES \"UTF8\""); 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, 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, 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, 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; g_bSQLite = false;
} }
else 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, 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, 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, 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) public Action ReconnectSQL(Handle hTimer)
@ -3243,4 +3321,4 @@ stock bool IsValidClient(int client)
return false; return false;
return IsClientAuthorized(client); return IsClientAuthorized(client);
} }