mirror of
https://codeberg.org/spire/nochat.git
synced 2026-11-30 02:00:46 +01:00
134 lines
3.5 KiB
SourcePawn
134 lines
3.5 KiB
SourcePawn
#pragma semicolon 1
|
|
#include <sourcemod>
|
|
|
|
ConVar noChatBlockListHandle;
|
|
char loadedBlockList[32][32];
|
|
int blockListCount = 0;
|
|
|
|
public Plugin:myinfo = {
|
|
name = "nochat",
|
|
author = "Icewind",
|
|
description = "Prevent specific users from chatting",
|
|
version = "0.1",
|
|
url = "https://spire.tf"
|
|
};
|
|
|
|
public OnPluginStart() {
|
|
noChatBlockListHandle = CreateConVar("sm_nochat_blocklist", "", "comma seperated list of steamid64", FCVAR_PROTECTED);
|
|
if (noChatBlockListHandle != null) {
|
|
noChatBlockListHandle.AddChangeHook(onBlockList);
|
|
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);
|
|
}
|
|
|
|
public Action:Command_SayChat(client, args) {
|
|
if (client == 0) {
|
|
return Plugin_Continue;
|
|
}
|
|
new String:steam_id[32];
|
|
GetClientAuthId(client, AuthId_SteamID64, steam_id, sizeof(steam_id));
|
|
|
|
for (int x = 0; x < sizeof(loadedBlockList); x++) {
|
|
if (StrEqual(steam_id, loadedBlockList[x])) {
|
|
return Plugin_Handled;
|
|
}
|
|
}
|
|
|
|
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 <player>");
|
|
|
|
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 <player>");
|
|
|
|
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);
|
|
}
|
|
|
|
public void LoadBlockList(const char[] value) {
|
|
for (int x = 0; x < sizeof(loadedBlockList); x++) {
|
|
loadedBlockList[x][0] = EOS;
|
|
}
|
|
blockListCount = ExplodeString(value, ",", loadedBlockList, sizeof(loadedBlockList), sizeof(loadedBlockList[]), false);
|
|
}
|