From 993c311388d59209a849d5441d3e28f09d954719 Mon Sep 17 00:00:00 2001 From: jenz Date: Mon, 20 May 2024 17:17:36 +0200 Subject: [PATCH] first adaption of perm self mute, probably fine --- SelfMute/scripting/SelfMute.sp | 1179 ++++++++++++++++++++------------ 1 file changed, 755 insertions(+), 424 deletions(-) diff --git a/SelfMute/scripting/SelfMute.sp b/SelfMute/scripting/SelfMute.sp index 33e44fb..ce1d23b 100644 --- a/SelfMute/scripting/SelfMute.sp +++ b/SelfMute/scripting/SelfMute.sp @@ -28,8 +28,12 @@ bool g_bIsProtoBuf = false; Handle g_hCookieTorchMuted = null; -#define PLUGIN_VERSION "2.4" +bool g_bClientMuteTempOrPerm[MAXPLAYERS + 1]; +Database g_hDatabase; + +#define PLUGIN_VERSION "2.5" +//may 20th 2024 jenz edit to add option for perm sm, stored in database. public Plugin myinfo = { name = "SelfMute", @@ -58,37 +62,211 @@ int g_SpecialMutes[MAXPLAYERS + 1]; char g_PlayerNames[MAXPLAYERS+1][MAX_NAME_LENGTH]; +/* + CREATE TABLE SelfMute.unloze_selfmute ( + `client_name` varchar(64) NOT NULL, + `client_steamid` varchar(32) NOT NULL, + `target_name` varchar(64) NOT NULL, + `target_steamid` varchar(32) NOT NULL, + PRIMARY KEY (`client_steamid`, `target_steamid`) +) + +CREATE TABLE SelfMute.is_online ( + `client_name` varchar(64) NOT NULL, + `client_steamid` varchar(32) NOT NULL, + PRIMARY KEY (`client_steamid`) +) +*/ + +public void SQL_OnDatabaseConnect(Database db, const char[] error, any data) +{ + if(!db || strlen(error)) + { + LogError("Database error: %s", error); + return; + } + g_hDatabase = db; + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "truncate table `is_online`"); + g_hDatabase.Query(SQL_OnQueryCompletedTruncate, sQuery); +} + +public void SQL_OnQueryCompletedTruncate(Database db, DBResultSet results, const char[] error, int iSerial) +{ + if (!db || strlen(error)) + { + delete results; + LogError("Query error 3: %s", error); + return; + } + delete results; + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i)) + { + OnClientPostAdminCheck(i); + } + } +} + +public void ReadClientsToPermMuteForClient(int client) +{ + char csSID[64]; + GetClientAuthId(client, AuthId_Steam2, csSID, sizeof(csSID)); + char sQuery[512]; + //limits this way to only select online clients to apply self mute for. + Format(sQuery, sizeof(sQuery), "select target_steamid from `unloze_selfmute` where client_steamid = '%s' and target_steamid in (select client_steamid from `is_online`)", csSID); + g_hDatabase.Query(SQL_GetClientsToSelfMuteForClient, sQuery, GetClientSerial(client), DBPrio_Low); +} + +public void SQL_GetClientsToSelfMuteForClient(Database db, DBResultSet results, const char[] error, int iSerial) +{ + if (!db || strlen(error)) + { + delete results; + LogError("Query error 3: %s", error); + return; + } + int client; + if ((client = GetClientFromSerial(iSerial)) == 0) + { + delete results; + return; + } + + while (results.RowCount && results.FetchRow()) + { + char cSID[64]; + results.FetchString(0, cSID, sizeof(cSID)); + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i)) + { + char sAuth[64]; + GetClientAuthId(i, AuthId_Steam2, sAuth, sizeof(sAuth)); + if (StrEqual(cSID, sAuth) && !GetIgnored(client, i)) + { + Ignore(client, i); + PrintToChat(client, "Player you permanent muted connected: %N", i); + UpdateIgnored(); //no clue if it needs to update that often. + } + } + } + } + delete results; +} + +public void OnClientPostAdminCheck(int client) +{ + g_bClientMuteTempOrPerm[client] = false; + if(!IsValidClient(client) || IsFakeClient(client)) + return; + if (!g_hDatabase) + { + return; + } + if (!IsFakeClient(client)) + { + insert_client_as_online(client); + } +} + +public void delete_client_from_online(int client) +{ + char csSID[64]; + GetClientAuthId(client, AuthId_Steam2, csSID, sizeof(csSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "delete from `is_online` where client_steamid = '%s'", csSID); + g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Low); +} + +public void insert_client_as_online(int client) +{ + char csSID[64]; + GetClientAuthId(client, AuthId_Steam2, csSID, sizeof(csSID)); + char sName[MAX_NAME_LENGTH]; + GetClientName(client, sName, sizeof(sName)); + int size2 = 2 * strlen(sName) + 1; + char[] sEscapedName = new char[size2 + 1]; + g_hDatabase.Escape(sName, sEscapedName, size2 + 1); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT IGNORE INTO `is_online` (`client_name`, `client_steamid`) VALUES ('%s', '%s')", sEscapedName, csSID); + g_hDatabase.Query(SQL_FinishedQueryUpdateMutes, sQuery, _, DBPrio_Low); +} + +public void SQL_FinishedQueryUpdateMutes(Database db, DBResultSet results, const char[] error, any data) +{ + if (!db || strlen(error)) + { + LogError("Query error 3: %s", error); + } + delete results; + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i)) + { + ReadClientsToPermMuteForClient(i); + } + } +} + +public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, any data) +{ + if (!db || strlen(error)) + { + LogError("Query error 3: %s", error); + } + delete results; +} + public void OnPluginStart() { - LoadTranslations("common.phrases"); + if (!g_hDatabase) + { + Database.Connect(SQL_OnDatabaseConnect, "SelfMute"); + } + else + { + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i)) + { + OnClientPostAdminCheck(i); + } + } + + } + LoadTranslations("common.phrases"); - CreateConVar("sm_selfmute_version", PLUGIN_VERSION, "Version of Self-Mute", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY); + CreateConVar("sm_selfmute_version", PLUGIN_VERSION, "Version of Self-Mute", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY); - RegConsoleCmd("sm_sm", Command_SelfMute, "Mute player by typing !sm [playername]"); - RegConsoleCmd("sm_su", Command_SelfUnMute, "Unmute player by typing !su [playername]"); - RegConsoleCmd("sm_cm", Command_CheckMutes, "Check who you have self-muted"); - RegAdminCmd("sm_debugtorch", Command_CheckPermaTorchMutes, ADMFLAG_GENERIC, "Check who has permanently self-muted Torch"); + RegConsoleCmd("sm_sm", Command_SelfMute, "Mute player by typing !sm [playername]"); + RegConsoleCmd("sm_psm", Command_SelfMutePerm, "Mute player by typing !psm [playername] but permanently"); + RegConsoleCmd("sm_su", Command_SelfUnMute, "Unmute player by typing !su [playername]"); + RegConsoleCmd("sm_cm", Command_CheckMutes, "Check who you have self-muted"); + RegAdminCmd("sm_debugtorch", Command_CheckPermaTorchMutes, ADMFLAG_GENERIC, "Check who has permanently self-muted Torch"); - HookEvent("round_start", Event_Round); - HookEvent("round_end", Event_Round); - HookEvent("player_team", Event_TeamChange); + HookEvent("round_start", Event_Round); + HookEvent("round_end", Event_Round); + HookEvent("player_team", Event_TeamChange); - if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf) - g_bIsProtoBuf = true; + if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf) + g_bIsProtoBuf = true; - UserMsg RadioText = GetUserMessageId("RadioText"); - if(RadioText == INVALID_MESSAGE_ID) - SetFailState("This game doesn't support RadioText user messages."); + UserMsg RadioText = GetUserMessageId("RadioText"); + if(RadioText == INVALID_MESSAGE_ID) + SetFailState("This game doesn't support RadioText user messages."); - HookUserMessage(RadioText, Hook_UserMessageRadioText, true); + HookUserMessage(RadioText, Hook_UserMessageRadioText, true); - UserMsg SendAudio = GetUserMessageId("SendAudio"); - if(SendAudio == INVALID_MESSAGE_ID) - SetFailState("This game doesn't support SendAudio user messages."); + UserMsg SendAudio = GetUserMessageId("SendAudio"); + if(SendAudio == INVALID_MESSAGE_ID) + SetFailState("This game doesn't support SendAudio user messages."); - HookUserMessage(SendAudio, Hook_UserMessageSendAudio, true); + HookUserMessage(SendAudio, Hook_UserMessageSendAudio, true); - g_hCookieTorchMuted = RegClientCookie("torch_muted", "is torch muted", CookieAccess_Protected); + g_hCookieTorchMuted = RegClientCookie("torch_muted", "is torch muted", CookieAccess_Protected); } public void OnAllPluginsLoaded() @@ -144,22 +322,34 @@ public void OnClientPutInServer(int client) GetCookiesForTorch(client); } +public void OnMapEnd() +{ + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "truncate table `is_online`"); + g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Low); +} + public void OnClientDisconnect(int client) { - g_SpecialMutes[client] = MUTE_NONE; - for(int i = 1; i <= MaxClients; i++) - { - SetIgnored(client, i, false); - SetExempt(client, i, false); + g_bClientMuteTempOrPerm[client] = false; + if (!IsFakeClient(client)) + { + delete_client_from_online(client); + } + g_SpecialMutes[client] = MUTE_NONE; + for(int i = 1; i <= MaxClients; i++) + { + SetIgnored(client, i, false); + SetExempt(client, i, false); - SetIgnored(i, client, false); - SetExempt(i, client, false); + SetIgnored(i, client, false); + SetExempt(i, client, false); - if(IsClientInGame(i) && i != client) - SetListenOverride(i, client, Listen_Yes); - } + if(IsClientInGame(i) && i != client) + SetListenOverride(i, client, Listen_Yes); + } - UpdateIgnored(); + UpdateIgnored(); } public void GetCookiesForTorch(int client) @@ -489,177 +679,309 @@ public Action Command_CheckPermaTorchMutes(int client, int args) iPlayers++; } - ReplyToCommand(client, "[SM] There are currently %d out of %d Players who've got Torch permanently self-muted.", iTorchPermMuted, iPlayers); + ReplyToCommand(client, "[SM] There are currently %d out of %d Players whove got Torch permanently self-muted.", iTorchPermMuted, iPlayers); return Plugin_Handled; } +public Action Command_SelfMutePerm(int client, int args) +{ + if(client == 0) + { + PrintToServer("[SM] Cannot use command from server console."); + return Plugin_Handled; + } + g_bClientMuteTempOrPerm[client] = true; //true for perm + + if(args < 1) + { + PrintToChat(client, "\x04[Self-Mute]\x01 Permanent mutes are dangerous. You need to specify the name of the target to permanently self mute."); + return Plugin_Handled; + } + + char Argument[65]; + GetCmdArg(1, Argument, sizeof(Argument)); + + char Filtered[65]; + strcopy(Filtered, sizeof(Filtered), Argument); + StripQuotes(Filtered); + TrimString(Filtered); + + if(MuteSpecial(client, Filtered)) + return Plugin_Handled; + + char sTargetName[MAX_TARGET_LENGTH]; + int aTargetList[MAXPLAYERS]; + int TargetCount; + bool TnIsMl; + + if((TargetCount = ProcessTargetString( + Argument, + client, + aTargetList, + MAXPLAYERS, + COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_IMMUNITY, + sTargetName, + sizeof(sTargetName), + TnIsMl)) <= 0) + { + ReplyToTargetError(client, TargetCount); + return Plugin_Handled; + } + + if(TargetCount == 1) + { + if(aTargetList[0] == client) + { + PrintToChat(client, "\x04[Self-Mute]\x01 You can't mute yourself, don't be silly."); + return Plugin_Handled; + } + + if(IsClientSourceTV(aTargetList[0])) + { + Ignore(client, aTargetList[0]); + SetClientCookie(client, g_hCookieTorchMuted, "1"); + PrintToChat(client, "\x04[Self-Mute]\x01 You have permanently self-muted:\x04 %s", sTargetName); + return Plugin_Handled; + } + + if(GetExempt(client, aTargetList[0])) + { + UnExempt(client, aTargetList[0]); + + PrintToChat(client, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %s", sTargetName); + + return Plugin_Handled; + } + } + + for(int i = 0; i < TargetCount; i++) + { + if(aTargetList[i] == client) + continue; + + Ignore(client, aTargetList[i]); + if (!IsFakeClient(aTargetList[i])) + { + AddClientMutingClient(client, aTargetList[i]); + } + } + UpdateIgnored(); + + PrintToChat(client, "\x04[Self-Mute]\x01 You have permanently self-muted:\x04 %s. !su can revert this decision.", sTargetName); + + return Plugin_Handled; +} + +public void AddClientMutingClient(int client, int target) +{ + char csSID[64]; + GetClientAuthId(client, AuthId_Steam2, csSID, sizeof(csSID)); + char csSIDTarget[64]; + GetClientAuthId(target, AuthId_Steam2, csSIDTarget, sizeof(csSIDTarget)); + + char sName[MAX_NAME_LENGTH]; + GetClientName(client, sName, sizeof(sName)); + int size2 = 2 * strlen(sName) + 1; + char[] sEscapedName = new char[size2 + 1]; + g_hDatabase.Escape(sName, sEscapedName, size2 + 1); + + GetClientName(target, sName, sizeof(sName)); + size2 = 2 * strlen(sName) + 1; + char[] sEscapedNameTarget = new char[size2 + 1]; + g_hDatabase.Escape(sName, sEscapedNameTarget, size2 + 1); + + char sQuery[512]; + + Format(sQuery, sizeof(sQuery), "insert ignore into `unloze_selfmute` (`client_name`, `client_steamid`, `target_name`, `target_steamid`) VALUES ('%s', '%s', '%s', '%s')", sEscapedName, csSID, sEscapedNameTarget, csSIDTarget); + g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Low); +} + +public void delete_client_from_permMute(int client, int target) +{ + if (IsFakeClient(target)) + { + return; + } + char csSID[64]; + GetClientAuthId(client, AuthId_Steam2, csSID, sizeof(csSID)); + + char csSIDTarget[64]; + GetClientAuthId(target, AuthId_Steam2, csSIDTarget, sizeof(csSIDTarget)); + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "delete from `unloze_selfmute` where client_steamid = '%s' and target_steamid = '%s'", csSID, csSIDTarget); + g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Low); +} + public Action Command_SelfMute(int client, int args) { - if(client == 0) - { - PrintToServer("[SM] Cannot use command from server console."); - return Plugin_Handled; - } + if(client == 0) + { + PrintToServer("[SM] Cannot use command from server console."); + return Plugin_Handled; + } + g_bClientMuteTempOrPerm[client] = false; //false for temp - if(args < 1) - { - DisplayMuteMenu(client); - return Plugin_Handled; - } + if(args < 1) + { + DisplayMuteMenu(client); + return Plugin_Handled; + } - char Argument[65]; - GetCmdArg(1, Argument, sizeof(Argument)); + char Argument[65]; + GetCmdArg(1, Argument, sizeof(Argument)); - char Filtered[65]; - strcopy(Filtered, sizeof(Filtered), Argument); - StripQuotes(Filtered); - TrimString(Filtered); + char Filtered[65]; + strcopy(Filtered, sizeof(Filtered), Argument); + StripQuotes(Filtered); + TrimString(Filtered); - if(MuteSpecial(client, Filtered)) - return Plugin_Handled; + if(MuteSpecial(client, Filtered)) + return Plugin_Handled; - char sTargetName[MAX_TARGET_LENGTH]; - int aTargetList[MAXPLAYERS]; - int TargetCount; - bool TnIsMl; + char sTargetName[MAX_TARGET_LENGTH]; + int aTargetList[MAXPLAYERS]; + int TargetCount; + bool TnIsMl; - if((TargetCount = ProcessTargetString( - Argument, - client, - aTargetList, - MAXPLAYERS, - COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_IMMUNITY, - sTargetName, - sizeof(sTargetName), - TnIsMl)) <= 0) - { - ReplyToTargetError(client, TargetCount); - return Plugin_Handled; - } + if((TargetCount = ProcessTargetString( + Argument, + client, + aTargetList, + MAXPLAYERS, + COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_IMMUNITY, + sTargetName, + sizeof(sTargetName), + TnIsMl)) <= 0) + { + ReplyToTargetError(client, TargetCount); + return Plugin_Handled; + } - if(TargetCount == 1) - { - if(aTargetList[0] == client) - { - PrintToChat(client, "\x04[Self-Mute]\x01 You can't mute yourself, don't be silly."); - return Plugin_Handled; - } + if(TargetCount == 1) + { + if(aTargetList[0] == client) + { + PrintToChat(client, "\x04[Self-Mute]\x01 You can't mute yourself, don't be silly."); + return Plugin_Handled; + } - if(IsClientSourceTV(aTargetList[0])) - { - Ignore(client, aTargetList[0]); - SetClientCookie(client, g_hCookieTorchMuted, "1"); - PrintToChat(client, "\x04[Self-Mute]\x01 You have permanently self-muted:\x04 %s", sTargetName); - return Plugin_Handled; - } + if(IsClientSourceTV(aTargetList[0])) + { + Ignore(client, aTargetList[0]); + SetClientCookie(client, g_hCookieTorchMuted, "1"); + PrintToChat(client, "\x04[Self-Mute]\x01 You have permanently self-muted:\x04 %s", sTargetName); + return Plugin_Handled; + } - if(GetExempt(client, aTargetList[0])) - { - UnExempt(client, aTargetList[0]); + if(GetExempt(client, aTargetList[0])) + { + UnExempt(client, aTargetList[0]); - PrintToChat(client, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %s", sTargetName); + PrintToChat(client, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %s", sTargetName); - return Plugin_Handled; - } - } + return Plugin_Handled; + } + } - for(int i = 0; i < TargetCount; i++) - { - if(aTargetList[i] == client) - continue; + for(int i = 0; i < TargetCount; i++) + { + if(aTargetList[i] == client) + continue; - Ignore(client, aTargetList[i]); - } - UpdateIgnored(); + Ignore(client, aTargetList[i]); + } + UpdateIgnored(); - PrintToChat(client, "\x04[Self-Mute]\x01 You have self-muted:\x04 %s", sTargetName); + PrintToChat(client, "\x04[Self-Mute]\x01 You have self-muted:\x04 %s. \x01 You can use !psm for permanent self mute now.", sTargetName); - return Plugin_Handled; + return Plugin_Handled; } public Action Command_SelfUnMute(int client, int args) { - if(client == 0) - { - PrintToServer("[SM] Cannot use command from server console."); - return Plugin_Handled; - } + if(client == 0) + { + PrintToServer("[SM] Cannot use command from server console."); + return Plugin_Handled; + } - if(args < 1) - { - DisplayUnMuteMenu(client); - return Plugin_Handled; - } + if(args < 1) + { + DisplayUnMuteMenu(client); + return Plugin_Handled; + } - char Argument[65]; - GetCmdArg(1, Argument, sizeof(Argument)); + char Argument[65]; + GetCmdArg(1, Argument, sizeof(Argument)); - char Filtered[65]; - strcopy(Filtered, sizeof(Filtered), Argument); - StripQuotes(Filtered); - TrimString(Filtered); + char Filtered[65]; + strcopy(Filtered, sizeof(Filtered), Argument); + StripQuotes(Filtered); + TrimString(Filtered); - if(UnMuteSpecial(client, Filtered)) - return Plugin_Handled; + if(UnMuteSpecial(client, Filtered)) + return Plugin_Handled; - char sTargetName[MAX_TARGET_LENGTH]; - int aTargetList[MAXPLAYERS]; - int TargetCount; - bool TnIsMl; + char sTargetName[MAX_TARGET_LENGTH]; + int aTargetList[MAXPLAYERS]; + int TargetCount; + bool TnIsMl; - if((TargetCount = ProcessTargetString( - Argument, - client, - aTargetList, - MAXPLAYERS, - COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_IMMUNITY, - sTargetName, - sizeof(sTargetName), - TnIsMl)) <= 0) - { - ReplyToTargetError(client, TargetCount); - return Plugin_Handled; - } + if((TargetCount = ProcessTargetString( + Argument, + client, + aTargetList, + MAXPLAYERS, + COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_IMMUNITY, + sTargetName, + sizeof(sTargetName), + TnIsMl)) <= 0) + { + ReplyToTargetError(client, TargetCount); + return Plugin_Handled; + } - if(TargetCount == 1) - { - if(aTargetList[0] == client) - { - PrintToChat(client, "\x04[Self-Mute]\x01 Unmuting won't work either."); - return Plugin_Handled; - } + if(TargetCount == 1) + { + if(aTargetList[0] == client) + { + PrintToChat(client, "\x04[Self-Mute]\x01 Unmuting wont work either."); + return Plugin_Handled; + } - if(IsClientSourceTV(aTargetList[0])) - { - UnIgnore(client, aTargetList[0]); - SetClientCookie(client, g_hCookieTorchMuted, ""); - PrintToChat(client, "\x04[Self-Mute]\x01 You have permanently self-unmuted:\x04 %s", sTargetName); - return Plugin_Handled; - } + if(IsClientSourceTV(aTargetList[0])) + { + UnIgnore(client, aTargetList[0]); + SetClientCookie(client, g_hCookieTorchMuted, ""); + PrintToChat(client, "\x04[Self-Mute]\x01 You have permanently self-unmuted:\x04 %s", sTargetName); + return Plugin_Handled; + } - if(!GetIgnored(client, aTargetList[0])) - { - Exempt(client, aTargetList[0]); + if(!GetIgnored(client, aTargetList[0])) + { + Exempt(client, aTargetList[0]); - PrintToChat(client, "\x04[Self-Mute]\x01 You have exempted from self-mute:\x04 %s", sTargetName); + PrintToChat(client, "\x04[Self-Mute]\x01 You have exempted from self-mute:\x04 %s", sTargetName); - return Plugin_Handled; - } - } + return Plugin_Handled; + } + } - for(int i = 0; i < TargetCount; i++) - { - if(aTargetList[i] == client) - continue; + for(int i = 0; i < TargetCount; i++) + { + if(aTargetList[i] == client) + continue; - UnIgnore(client, aTargetList[i]); - } - UpdateIgnored(); + UnIgnore(client, aTargetList[i]); + delete_client_from_permMute(client, aTargetList[i]); + } + UpdateIgnored(); - PrintToChat(client, "\x04[Self-Mute]\x01 You have self-unmuted:\x04 %s", sTargetName); + PrintToChat(client, "\x04[Self-Mute]\x01 You have self-unmuted:\x04 %s", sTargetName); - return Plugin_Handled; + return Plugin_Handled; } public Action Command_CheckMutes(int client, int args) @@ -814,183 +1136,184 @@ void DisplayMuteMenu(int client) public int MenuHandler_MuteMenu(Menu menu, MenuAction action, int param1, int param2) { - switch(action) - { - case MenuAction_End: - { - if(param1 != MenuEnd_Selected) - CloseHandle(menu); - } - case MenuAction_Select: - { - int Style; - char aItem[32]; - char aDisp[MAX_NAME_LENGTH + 4]; - menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); + switch(action) + { + case MenuAction_End: + { + if(param1 != MenuEnd_Selected) + CloseHandle(menu); + } + case MenuAction_Select: + { + int Style; + char aItem[32]; + char aDisp[MAX_NAME_LENGTH + 4]; + menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); - if(Style != ITEMDRAW_DEFAULT || !aItem[0]) - { - PrintToChat(param1, "Internal error: aItem[0] -> %d | Style -> %d", aItem[0], Style); - return 0; - } + if(Style != ITEMDRAW_DEFAULT || !aItem[0]) + { + PrintToChat(param1, "Internal error: aItem[0] -> %d | Style -> %d", aItem[0], Style); + return 0; + } - if(aItem[0] == '@') - { - int Flag = GetSpecialMutesFlags(aItem); - if(Flag && g_SpecialMutes[param1] & Flag) - UnMuteSpecial(param1, aItem); - else - MuteSpecial(param1, aItem); + if(aItem[0] == '@') + { + int Flag = GetSpecialMutesFlags(aItem); + if(Flag && g_SpecialMutes[param1] & Flag) + UnMuteSpecial(param1, aItem); + else + MuteSpecial(param1, aItem); - menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } + menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } - int UserId = StringToInt(aItem); - int client = GetClientOfUserId(UserId); - if(!client) - { - PrintToChat(param1, "\x04[Self-Mute]\x01 Player no longer available."); - menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } + int UserId = StringToInt(aItem); + int client = GetClientOfUserId(UserId); + if(!client) + { + PrintToChat(param1, "\x04[Self-Mute]\x01 Player no longer available."); + menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } - if(GetIgnored(param1, client)) - { - if(IsClientSourceTV(client)) - { - UnIgnore(param1, client); - SetClientCookie(param1, g_hCookieTorchMuted, ""); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have permanently self-unmuted:\x04 %N", client); - } - else - { - UnIgnore(param1, client); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have self-unmuted:\x04 %N", client); - } - } - else if(GetExempt(param1, client)) - { - UnExempt(param1, client); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %N", client); - } - else - { - if(IsClientSourceTV(client)) - { - Ignore(param1, client); - SetClientCookie(param1, g_hCookieTorchMuted, "1"); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have permanently self-muted:\x04 %N", client); - } - else - { - Ignore(param1, client); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have self-muted:\x04 %N", client); - } - } - menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } - case MenuAction_DrawItem: - { - int Style; - char aItem[32]; - menu.GetItem(param2, aItem, sizeof(aItem), Style); + if(GetIgnored(param1, client)) + { + if(IsClientSourceTV(client)) + { + UnIgnore(param1, client); + SetClientCookie(param1, g_hCookieTorchMuted, ""); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have permanently self-unmuted:\x04 %N", client); + } + else + { + UnIgnore(param1, client); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have self-unmuted:\x04 %N", client); + delete_client_from_permMute(param1, client); + } + } + else if(GetExempt(param1, client)) + { + UnExempt(param1, client); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %N", client); + } + else + { + if(IsClientSourceTV(client)) + { + Ignore(param1, client); + SetClientCookie(param1, g_hCookieTorchMuted, "1"); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have permanently self-muted:\x04 %N", client); + } + else + { + Ignore(param1, client); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have self-muted:\x04 %N. \x01 You can now use !psm to permanent self mute a player.", client); + } + } + menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } + case MenuAction_DrawItem: + { + int Style; + char aItem[32]; + menu.GetItem(param2, aItem, sizeof(aItem), Style); - if(!aItem[0]) - return ITEMDRAW_DISABLED; + if(!aItem[0]) + return ITEMDRAW_DISABLED; - if(aItem[0] == '@') - { - int Flag = GetSpecialMutesFlags(aItem); - if(Flag & MUTE_ALL) - return Style; - else if(g_SpecialMutes[param1] & MUTE_ALL) - return ITEMDRAW_DISABLED; + if(aItem[0] == '@') + { + int Flag = GetSpecialMutesFlags(aItem); + if(Flag & MUTE_ALL) + return Style; + else if(g_SpecialMutes[param1] & MUTE_ALL) + return ITEMDRAW_DISABLED; - return Style; - } + return Style; + } - int UserId = StringToInt(aItem); - int client = GetClientOfUserId(UserId); - if(!client) // Player disconnected - return ITEMDRAW_DISABLED; + int UserId = StringToInt(aItem); + int client = GetClientOfUserId(UserId); + if(!client) // Player disconnected + return ITEMDRAW_DISABLED; - return Style; - } - case MenuAction_DisplayItem: - { - int Style; - char aItem[32]; - char aDisp[MAX_NAME_LENGTH + 4]; - menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); + return Style; + } + case MenuAction_DisplayItem: + { + int Style; + char aItem[32]; + char aDisp[MAX_NAME_LENGTH + 4]; + menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); - // Start of current page - if((param2 + 1) % 7 == 1) - { - if(aItem[0] == '@') - menu.SetTitle("[Self-Mute] Groups"); - else if(param2 == 0) - menu.SetTitle("[Self-Mute] Talking players"); - else - menu.SetTitle("[Self-Mute] All players"); - } + // Start of current page + if((param2 + 1) % 7 == 1) + { + if(aItem[0] == '@') + menu.SetTitle("[Self-Mute] Groups"); + else if(param2 == 0) + menu.SetTitle("[Self-Mute] Talking players"); + else + menu.SetTitle("[Self-Mute] All players"); + } - if(!aItem[0]) - return 0; + if(!aItem[0]) + return 0; - if(aItem[0] == '@') - { - int Flag = GetSpecialMutesFlags(aItem); - if(Flag && g_SpecialMutes[param1] & Flag) - { - char aBuf[32] = "[M] "; - FormatSpecialMutes(Flag, aBuf, sizeof(aBuf)); - if(!StrEqual(aDisp, aBuf)) - return RedrawMenuItem(aBuf); - } + if(aItem[0] == '@') + { + int Flag = GetSpecialMutesFlags(aItem); + if(Flag && g_SpecialMutes[param1] & Flag) + { + char aBuf[32] = "[M] "; + FormatSpecialMutes(Flag, aBuf, sizeof(aBuf)); + if(!StrEqual(aDisp, aBuf)) + return RedrawMenuItem(aBuf); + } - return 0; - } + return 0; + } - int UserId = StringToInt(aItem); - int client = GetClientOfUserId(UserId); - if(!client) // Player disconnected - { - char aBuf[MAX_NAME_LENGTH + 4] = "[D] "; - StrCat(aBuf, sizeof(aBuf), aDisp); - if(!StrEqual(aDisp, aBuf)) - return RedrawMenuItem(aBuf); - } + int UserId = StringToInt(aItem); + int client = GetClientOfUserId(UserId); + if(!client) // Player disconnected + { + char aBuf[MAX_NAME_LENGTH + 4] = "[D] "; + StrCat(aBuf, sizeof(aBuf), aDisp); + if(!StrEqual(aDisp, aBuf)) + return RedrawMenuItem(aBuf); + } - if(GetIgnored(param1, client)) - { - char aBuf[MAX_NAME_LENGTH + 4] = "[M] "; - GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); - StrCat(aBuf, sizeof(aBuf), g_PlayerNames[client]); - if(!StrEqual(aDisp, aBuf)) - return RedrawMenuItem(aBuf); - } - else if(GetExempt(param1, client)) - { - char aBuf[MAX_NAME_LENGTH + 4] = "[E] "; - GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); - StrCat(aBuf, sizeof(aBuf), g_PlayerNames[client]); - if(!StrEqual(aDisp, aBuf)) - return RedrawMenuItem(aBuf); - } - else - { - GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); - if(!StrEqual(aDisp, g_PlayerNames[client])) - return RedrawMenuItem(g_PlayerNames[client]); - } + if(GetIgnored(param1, client)) + { + char aBuf[MAX_NAME_LENGTH + 4] = "[M] "; + GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); + StrCat(aBuf, sizeof(aBuf), g_PlayerNames[client]); + if(!StrEqual(aDisp, aBuf)) + return RedrawMenuItem(aBuf); + } + else if(GetExempt(param1, client)) + { + char aBuf[MAX_NAME_LENGTH + 4] = "[E] "; + GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); + StrCat(aBuf, sizeof(aBuf), g_PlayerNames[client]); + if(!StrEqual(aDisp, aBuf)) + return RedrawMenuItem(aBuf); + } + else + { + GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); + if(!StrEqual(aDisp, g_PlayerNames[client])) + return RedrawMenuItem(g_PlayerNames[client]); + } - return 0; - } - } + return 0; + } + } - return 0; + return 0; } void DisplayUnMuteMenu(int client) @@ -1056,123 +1379,124 @@ void DisplayUnMuteMenu(int client) public int MenuHandler_UnMuteMenu(Menu menu, MenuAction action, int param1, int param2) { - switch(action) - { - case MenuAction_End: - { - if(param1 != MenuEnd_Selected) - CloseHandle(menu); - } - case MenuAction_Select: - { - int Style; - char aItem[32]; - char aDisp[MAX_NAME_LENGTH + 4]; - menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); + switch(action) + { + case MenuAction_End: + { + if(param1 != MenuEnd_Selected) + CloseHandle(menu); + } + case MenuAction_Select: + { + int Style; + char aItem[32]; + char aDisp[MAX_NAME_LENGTH + 4]; + menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); - if(Style != ITEMDRAW_DEFAULT || !aItem[0]) - { - PrintToChat(param1, "Internal error: aItem[0] -> %d | Style -> %d", aItem[0], Style); - return 0; - } + if(Style != ITEMDRAW_DEFAULT || !aItem[0]) + { + PrintToChat(param1, "Internal error: aItem[0] -> %d | Style -> %d", aItem[0], Style); + return 0; + } - if(aItem[0] == '@') - { - int Flag = GetSpecialMutesFlags(aItem); - if(Flag && g_SpecialMutes[param1] & Flag) - UnMuteSpecial(param1, aItem); + if(aItem[0] == '@') + { + int Flag = GetSpecialMutesFlags(aItem); + if(Flag && g_SpecialMutes[param1] & Flag) + UnMuteSpecial(param1, aItem); - menu.RemoveItem(GetMenuSelectionPosition()); - menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } + menu.RemoveItem(GetMenuSelectionPosition()); + menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } - int UserId = StringToInt(aItem); - int client = GetClientOfUserId(UserId); - if(!client) - { - PrintToChat(param1, "\x04[Self-Mute]\x01 Player no longer available."); - menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } + int UserId = StringToInt(aItem); + int client = GetClientOfUserId(UserId); + if(!client) + { + PrintToChat(param1, "\x04[Self-Mute]\x01 Player no longer available."); + menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } - if(GetIgnored(param1, client)) - { - if(IsClientSourceTV(client)) - { - UnIgnore(param1, client); - SetClientCookie(param1, g_hCookieTorchMuted, ""); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have permanently self-unmuted:\x04 %N", client); - } - else - { - UnIgnore(param1, client); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have self-unmuted:\x04 %N", client); - } - } - else if(GetExempt(param1, client)) - { - UnExempt(param1, client); - PrintToChat(param1, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %N", client); - } + if(GetIgnored(param1, client)) + { + if(IsClientSourceTV(client)) + { + UnIgnore(param1, client); + SetClientCookie(param1, g_hCookieTorchMuted, ""); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have permanently self-unmuted:\x04 %N", client); + } + else + { + UnIgnore(param1, client); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have self-unmuted:\x04 %N", client); + delete_client_from_permMute(param1, client); + } + } + else if(GetExempt(param1, client)) + { + UnExempt(param1, client); + PrintToChat(param1, "\x04[Self-Mute]\x01 You have removed exempt from self-mute:\x04 %N", client); + } - menu.RemoveItem(GetMenuSelectionPosition()); - menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } - case MenuAction_DrawItem: - { - int Style; - char aItem[32]; - menu.GetItem(param2, aItem, sizeof(aItem), Style); + menu.RemoveItem(GetMenuSelectionPosition()); + menu.DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } + case MenuAction_DrawItem: + { + int Style; + char aItem[32]; + menu.GetItem(param2, aItem, sizeof(aItem), Style); - if(!aItem[0]) - return ITEMDRAW_DISABLED; + if(!aItem[0]) + return ITEMDRAW_DISABLED; - if(aItem[0] == '@') - return Style; + if(aItem[0] == '@') + return Style; - int UserId = StringToInt(aItem); - int client = GetClientOfUserId(UserId); - if(!client) // Player disconnected - return ITEMDRAW_DISABLED; + int UserId = StringToInt(aItem); + int client = GetClientOfUserId(UserId); + if(!client) // Player disconnected + return ITEMDRAW_DISABLED; - return Style; - } - case MenuAction_DisplayItem: - { - int Style; - char aItem[32]; - char aDisp[MAX_NAME_LENGTH + 4]; - menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); + return Style; + } + case MenuAction_DisplayItem: + { + int Style; + char aItem[32]; + char aDisp[MAX_NAME_LENGTH + 4]; + menu.GetItem(param2, aItem, sizeof(aItem), Style, aDisp, sizeof(aDisp)); - if(!aItem[0]) - return 0; + if(!aItem[0]) + return 0; - int UserId = StringToInt(aItem); - int client = GetClientOfUserId(UserId); - if(!client) // Player disconnected - { - char aBuf[MAX_NAME_LENGTH + 4] = "[D] "; - StrCat(aBuf, sizeof(aBuf), aDisp); - if(!StrEqual(aDisp, aBuf)) - return RedrawMenuItem(aBuf); - } + int UserId = StringToInt(aItem); + int client = GetClientOfUserId(UserId); + if(!client) // Player disconnected + { + char aBuf[MAX_NAME_LENGTH + 4] = "[D] "; + StrCat(aBuf, sizeof(aBuf), aDisp); + if(!StrEqual(aDisp, aBuf)) + return RedrawMenuItem(aBuf); + } - if(GetExempt(param1, client)) - { - char aBuf[MAX_NAME_LENGTH + 4] = "[E] "; - GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); - StrCat(aBuf, sizeof(aBuf), g_PlayerNames[client]); - if(!StrEqual(aDisp, aBuf)) - return RedrawMenuItem(aBuf); - } + if(GetExempt(param1, client)) + { + char aBuf[MAX_NAME_LENGTH + 4] = "[E] "; + GetClientName(client, g_PlayerNames[client], sizeof(g_PlayerNames[])); + StrCat(aBuf, sizeof(aBuf), g_PlayerNames[client]); + if(!StrEqual(aDisp, aBuf)) + return RedrawMenuItem(aBuf); + } - return 0; - } - } + return 0; + } + } - return 0; + return 0; } /* @@ -1356,3 +1680,10 @@ void SetExempt(int client, int target, bool exempt) { g_Exempt[client][target] = exempt; } + +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) + return true; + return false; +}