diff --git a/README.md b/README.md index b68407a..8d1b3e1 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,5 @@ Stop specific people from talking - Enable the plugin - Set the users to block: `rcon sm_nochat_blocklist 76561198024494988,76561198076020012` +- Add players to the blocklist with `rcon nochat_block ` +- Remove players to the blocklist with `rcon nochat_unblock ` diff --git a/plugin/nochat.sp b/plugin/nochat.sp index 571bf45..e68e397 100644 --- a/plugin/nochat.sp +++ b/plugin/nochat.sp @@ -3,6 +3,7 @@ ConVar noChatBlockListHandle; char loadedBlockList[32][32]; +int blockListCount = 0; public Plugin:myinfo = { name = "nochat", @@ -16,11 +17,14 @@ public OnPluginStart() { noChatBlockListHandle = CreateConVar("sm_nochat_blocklist", "", "comma seperated list of steamid64", FCVAR_PROTECTED); if (noChatBlockListHandle != null) { noChatBlockListHandle.AddChangeHook(onBlockList); - decl String:blockList[512]; + decl String:blockList[1024]; GetConVarString(noChatBlockListHandle, blockList, sizeof(blockList)); LoadBlockList(blockList); } + RegServerCmd("sm_nochat_block", AddBlock, "Add a player to the blocklist"); + RegServerCmd("sm_nochat_unblock", RemoveBlock, "Remove a player to the blocklist"); + RegConsoleCmd("say", Command_SayChat); RegConsoleCmd("say_team", Command_SayChat); } @@ -41,6 +45,83 @@ public Action:Command_SayChat(client, args) { return Plugin_Continue; } +int findPlayer(const char[] player) { + int client = StringToInt(player); + + if (client <= 0) { + client = FindTarget(0, player, false, true); + } else { + client -= 1; // status starts client ids with + } + + return client; +} + +public Action:AddBlock(args) { + if (args != 1) { + PrintToServer("Usage: sm_nochat_block "); + + return Plugin_Handled; + } + + char player[128]; + GetCmdArg(1, player, sizeof(player)); + int client = findPlayer(player); + + if (client <= 0) { + PrintToServer("Player '%s' not found", player); + + return Plugin_Handled; + } + + new String:steam_id[32]; + GetClientAuthId(client, AuthId_SteamID64, steam_id, sizeof(steam_id)); + loadedBlockList[blockListCount] = steam_id; + blockListCount = blockListCount + 1; + + new String:joined[1024]; + ImplodeStrings(loadedBlockList, blockListCount, ",", joined, sizeof(joined)); + SetConVarString(noChatBlockListHandle, joined); + + return Plugin_Handled; +} + +public Action:RemoveBlock(args) { + if (args != 1) { + PrintToServer("Usage: sm_nochat_block "); + + return Plugin_Handled; + } + + char player[128]; + GetCmdArg(1, player, sizeof(player)); + int client = findPlayer(player); + + if (client <= 0) { + PrintToServer("Player '%s' not found", player); + + return Plugin_Handled; + } + + new String:steam_id[32]; + GetClientAuthId(client, AuthId_SteamID64, steam_id, sizeof(steam_id)); + + char filteredBlacklist[32][32]; + int filteredCount = 0; + for (int i = 0; i < blockListCount; i++) { + if (strcmp(loadedBlockList[i], steam_id) != 0) { + filteredBlacklist[filteredCount] = loadedBlockList[i]; + filteredCount = filteredCount + 1; + } + } + + new String:joined[1024]; + ImplodeStrings(filteredBlacklist, filteredCount, ",", joined, sizeof(joined)); + SetConVarString(noChatBlockListHandle, joined); + + return Plugin_Handled; +} + public void onBlockList(ConVar convar, const char[] oldValue, const char[] newValue) { LoadBlockList(newValue); } @@ -49,5 +130,5 @@ public void LoadBlockList(const char[] value) { for (int x = 0; x < sizeof(loadedBlockList); x++) { loadedBlockList[x][0] = EOS; } - ExplodeString(value, ",", loadedBlockList, sizeof(loadedBlockList), sizeof(loadedBlockList[]), false); + blockListCount = ExplodeString(value, ",", loadedBlockList, sizeof(loadedBlockList), sizeof(loadedBlockList[]), false); }