Skip to content

Commit

Permalink
Refactor BeQuiet plugin: streamline CVar handling, improve command li…
Browse files Browse the repository at this point in the history
…steners, and update plugin metadata
  • Loading branch information
altair-sossai committed Dec 16, 2024
1 parent fc7a5a8 commit e34e4a8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 181 deletions.
244 changes: 96 additions & 148 deletions addons/sourcemod/scripting/bequiet.sp
Original file line number Diff line number Diff line change
@@ -1,176 +1,124 @@
#pragma semicolon 1
#pragma newdecls required

#include <colors>
#pragma newdecls required
#include <sourcemod>

#define PLUGIN_VERSION "2.0.2"

ConVar hCvarCvarChange, hCvarNameChange, hCvarSpecNameChange, hCvarSpecSeeChat;
bool bCvarChange, bNameChange, bSpecNameChange, bSpecSeeChat;

public Plugin myinfo =
{
name = "[L4D & 2] BeQuiet",
author = "Sir, Forgetest",
description = "Please be Quiet! (Spec hearing chat, name/cvar change supress)",
version = PLUGIN_VERSION,
url = "https://github.com/Target5150/MoYu_Server_Stupid_Plugins"
name = "BeQuiet",
author = "Sir",
description = "Please be Quiet!",
version = "1.33.7",
url = "https://github.com/SirPlease/SirCoding"
}

ConVar hCvarCvarChange, hCvarNameChange, hCvarSpecNameChange, hCvarSpecSeeChat;

public void OnPluginStart()
{
//Player name change
HookUserMessage(GetUserMessageId("SayText2"), UserMsg_OnSayText2, true);

//Server CVar
HookEvent("server_cvar", Event_ServerConVar, EventHookMode_Pre);

//Cvars
hCvarCvarChange = CreateConVar("bq_cvar_change_suppress", "1", "Silence Server Cvars being changed, this makes for a clean chat with no disturbances.", FCVAR_SPONLY, true, 0.0, true, 1.0);
hCvarNameChange = CreateConVar("bq_name_change_suppress", "0", "Silence Player name Changes.", FCVAR_SPONLY, true, 0.0, true, 1.0);
hCvarSpecNameChange = CreateConVar("bq_name_change_spec_suppress", "0", "Silence Spectating Player name Changes.", FCVAR_SPONLY, true, 0.0, true, 1.0);
hCvarSpecSeeChat = CreateConVar("bq_show_player_team_chat_spec", "1", "Show Spectators Survivors and Infected Team chat?", FCVAR_SPONLY, true, 0.0, true, 1.0);

AutoExecConfig(true);
AddCommandListener(Say_Callback, "say");
AddCommandListener(TeamSay_Callback, "say_team");

//Server CVar
HookEvent("server_cvar", Event_ServerConVar, EventHookMode_Pre);
HookEvent("player_changename", Event_NameChange, EventHookMode_Pre);

//Cvars
hCvarCvarChange = CreateConVar("bq_cvar_change_suppress", "1", "Silence Server Cvars being changed, this makes for a clean chat with no disturbances.");
hCvarNameChange = CreateConVar("bq_name_change_suppress", "1", "Silence Player name Changes.");
hCvarSpecNameChange = CreateConVar("bq_name_change_spec_suppress", "1", "Silence Spectating Player name Changes.");
hCvarSpecSeeChat = CreateConVar("bq_show_player_team_chat_spec", "1", "Show Spectators Survivors and Infected Team chat?");

bCvarChange = GetConVarBool(hCvarCvarChange);
bNameChange = GetConVarBool(hCvarNameChange);
bSpecNameChange = GetConVarBool(hCvarSpecNameChange);
bSpecSeeChat = GetConVarBool(hCvarSpecSeeChat);

hCvarCvarChange.AddChangeHook(cvarChanged);
hCvarNameChange.AddChangeHook(cvarChanged);
hCvarSpecNameChange.AddChangeHook(cvarChanged);
hCvarSpecSeeChat.AddChangeHook(cvarChanged);

AutoExecConfig(true);
LoadTranslations("bequiet.phrases");
}

public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
Action Say_Callback(int client, char[] command, int args)
{
static char s_sPubChatTrigger[8] = "!", s_sPrivChatTrigger[8] = "/";
static int s_iPubTriggerLen = 1, s_iPrivTriggerLen = 1;

// 1.12.0.6944
// https://github.com/alliedmodders/sourcemod/commit/3b4a343274286b31a9b3cf33c64f7ef
#if SOURCEMOD_V_MAJOR > 1
|| (SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR >= 12 && SOURCEMOD_V_REV >= 6944)
static bool bInit = false;
if (!bInit)
{
s_iPubTriggerLen = GetPublicChatTriggers(s_sPubChatTrigger, sizeof(s_sPubChatTrigger));
s_iPrivTriggerLen = GetSilentChatTriggers(s_sPrivChatTrigger, sizeof(s_sPrivChatTrigger));

if (!s_iPubTriggerLen)
s_iPubTriggerLen = strcopy(s_sPubChatTrigger, sizeof(s_sPubChatTrigger), "!");
if (!s_iPrivTriggerLen)
s_iPrivTriggerLen = strcopy(s_sPrivChatTrigger, sizeof(s_sPrivChatTrigger), "/");

bInit = true;
}
#endif

if (strncmp(sArgs, s_sPubChatTrigger, s_iPubTriggerLen) == 0
|| strncmp(sArgs, s_sPrivChatTrigger, s_iPrivTriggerLen) == 0)
return Plugin_Handled;

return Plugin_Continue;
char sayWord[MAX_NAME_LENGTH];
GetCmdArg(1, sayWord, sizeof(sayWord));

if(sayWord[0] == '!' || sayWord[0] == '/')
{
return Plugin_Handled;
}
return Plugin_Continue;
}

public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
Action TeamSay_Callback(int client, char[] command, int args)
{
if (!IsValidClient(client))
return;

if (!hCvarSpecSeeChat.BoolValue || strcmp(command, "say_team") != 0)
return;

// TODO: Formats for dead players? Not really seen much.
static const char s_ChatFormats[][] = {
"L4D_Chat_Survivor",
"L4D_Chat_Infected",
/* "L4D_Chat_Survivor_Dead",
"L4D_Chat_Infected_Dead",*/
};

int idxTeam = GetClientTeam(client) - 2;
if (idxTeam != 0 && idxTeam != 1)
return;

/*if (!IsPlayerAlive(client))
idxTeam += 2;*/

// collect all spectators + SourceTV
int[] clients = new int[MaxClients];
int numClients = 0;
for (int i = 1; i <= MaxClients; ++i)
{
if (IsClientInGame(i) && GetClientTeam(i) == 1 && (!IsFakeClient(i) || IsClientSourceTV(i)))
clients[numClients++] = i;
}

if (numClients <= 0)
return;

char name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
UTIL_SayText2Filter(client, clients, numClients, true, s_ChatFormats[idxTeam], name, sArgs);
char sayWord[MAX_NAME_LENGTH];
GetCmdArg(1, sayWord, sizeof(sayWord));

if(sayWord[0] == '!' || sayWord[0] == '/')
{
return Plugin_Handled;
}

if (bSpecSeeChat && GetClientTeam(client) != 1)
{
char sChat[256];
GetCmdArgString(sChat, 256);
StripQuotes(sChat);
int i = 1;
while (i <= 65)
{
if (IsValidClient(i) && GetClientTeam(i) == 1)
{
if (GetClientTeam(client) == 2)
{
CPrintToChat(i, "%t", "SurvivorSay", client, sChat);
}
else CPrintToChat(i, "%t", "InfectedSay", client, sChat);
}
i++;
}
}
return Plugin_Continue;
}

Action Event_ServerConVar(Event event, const char[] name, bool dontBroadcast)
{
return hCvarCvarChange.BoolValue ? Plugin_Handled : Plugin_Continue;
if (bCvarChange) return Plugin_Handled;
return Plugin_Continue;
}

// Thanks for help from HarryPotter (@fbef0102) IIRC
Action UserMsg_OnSayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init)
Action Event_NameChange(Event event, const char[] name, bool dontBroadcast)
{
int client = msg.ReadByte();
if (!IsValidClient(client))
return Plugin_Continue;

msg.ReadByte(); // Skip the second byte

// Read the message
static char sMessage[128];
msg.ReadString(sMessage, sizeof(sMessage), true);

if (GetClientTeam(client) == 1)
{
if (!hCvarSpecNameChange.BoolValue)
return Plugin_Continue;
}
else if (!hCvarNameChange.BoolValue)
return Plugin_Continue;

if (strcmp(sMessage, "#Cstrike_Name_Change") != 0)
return Plugin_Continue;

return Plugin_Handled;
}
int clientid = event.GetInt("userid");
int client = GetClientOfUserId(clientid);

stock bool IsValidClient(int client)
{
return client > 0 && client <= MaxClients && IsClientInGame(client);
if (IsValidClient(client))
{
if (GetClientTeam(client) == 1 && bSpecNameChange) return Plugin_Handled;
else if (bNameChange) return Plugin_Handled;
}
return Plugin_Continue;
}

stock void UTIL_SayText2Filter( int entity, const int[] recipients, int numRecipient, bool bChat, const char[] msg_name, const char[] param1 = NULL_STRING, const char[] param2 = NULL_STRING, const char[] param3 = NULL_STRING, const char[] param4 = NULL_STRING )
void cvarChanged(Handle convar, const char[] oldValue, const char[] newValue)
{
BfWrite bf = UserMessageToBfWrite(StartMessage( "SayText2", recipients, numRecipient, USERMSG_RELIABLE ));

if ( entity < 0 )
entity = 0; // world, dedicated server says

bf.WriteByte( entity );
bf.WriteByte( bChat );
bf.WriteString( msg_name );

if ( !IsNullString(param1) )
bf.WriteString( param1 );
else
bf.WriteString( "" );

if ( !IsNullString(param2) )
bf.WriteString( param2 );
else
bf.WriteString( "" );

if ( !IsNullString(param3) )
bf.WriteString( param3 );
else
bf.WriteString( "" );

if ( !IsNullString(param4) )
bf.WriteString( param4 );
else
bf.WriteString( "" );

EndMessage();
}
bCvarChange = hCvarCvarChange.BoolValue;
bNameChange = hCvarNameChange.BoolValue;
bSpecNameChange = hCvarSpecNameChange.BoolValue;
bSpecSeeChat = hCvarSpecSeeChat.BoolValue;
}

bool IsValidClient(int client)
{
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client)) return false;
return true;
}
3 changes: 0 additions & 3 deletions addons/sourcemod/scripting/l4d2_tank_props_glow.sp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,6 @@ void CreateTankPropGlow(int iTarget)

SDKHook(iEntity, SDKHook_SetTransmit, OnTransmit);
g_iEntityList[iTarget] = EntIndexToEntRef(iEntity);

// Fix PVS glow issues while inside walls (by Mart)
SetEdictFlags(iTarget, GetEdictFlags(iTarget) | FL_EDICT_ALWAYS);
}

Action OnTransmit(int iEntity, int iClient)
Expand Down
29 changes: 0 additions & 29 deletions addons/sourcemod/scripting/l4d_tank_control_eq.sp
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,6 @@ void chooseTank(any data)
nextTankIndex = PeekNextTankIndexInTheQueue();
}

if (nextTankIndex == -1)
{
RequeueInfecteds(h_whosHadTank);
nextTankIndex = PeekNextTankIndexInTheQueue();
}

if (nextTankIndex == -1)
{
RemoveAllInfectedFrom(h_tankQueue);
Expand Down Expand Up @@ -690,29 +684,6 @@ void EnqueueNewInfectedPlayers()
ShuffleArray(h_tankQueue, start, end);
}

void RequeueInfecteds(ArrayList arrayList)
{
if (arrayList.Length == 0)
return;

char steamId[64];

for(int i = 0; i < arrayList.Length; i++)
{
arrayList.GetString(i, steamId, sizeof(steamId));

int client = getInfectedPlayerBySteamId(steamId);
if (client == -1 || h_tankQueue.FindString(steamId) != -1)
continue;

h_tankQueue.PushString(steamId);

int index = h_whosHadTank.FindString(steamId);
if (index != -1)
h_whosHadTank.Erase(index);
}
}

void RemoveAllInfectedFrom(ArrayList arrayList)
{
char steamId[64];
Expand Down
2 changes: 1 addition & 1 deletion cfg/cfgogl/zonemod/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ confogl_addcvar vs_tank_pound_damage 36
confogl_addcvar vs_tank_rock_damage 24

// [l4d2_pickup.smx]
confogl_addcvar pickup_switch_flags 3
confogl_addcvar pickup_switch_flags 2
confogl_addcvar pickup_incap_flags 2

// [l4d2_car_alarm_hittable_fix.smx]
Expand Down

0 comments on commit e34e4a8

Please sign in to comment.