mirror of
https://codeberg.org/spire/nochat.git
synced 2026-11-30 10:10:47 +01:00
add commands to add/remove players from blocklist
This commit is contained in:
parent
bbc940cdfe
commit
014ea363d5
2 changed files with 85 additions and 2 deletions
|
|
@ -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 <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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue