sm-plugins/ChatFilter/scripting/ChatFilter.sp
2018-07-23 17:18:51 +02:00

129 lines
3.4 KiB
SourcePawn

#pragma newdecls required
#include <sourcemod>
#include <regex>
#include <ccc>
ArrayList g_aClientFilters[MAXPLAYERS+1];
ArrayList g_aGroupFilters[MAXPLAYERS+1];
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "ChatFilter",
author = "zaCade",
description = "Allows users to filter their chat messages",
version = "1.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
RegConsoleCmd("sm_cf", Command_ChatFilter);
RegConsoleCmd("sm_cfg", Command_ChatFilterGroup);
for (int client = 1; client <= MAXPLAYERS; client++)
{
g_aClientFilters[client] = new ArrayList(512);
g_aGroupFilters[client] = new ArrayList(512);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientConnected(int client)
{
g_aClientFilters[client].Clear();
g_aGroupFilters[client].Clear();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_ChatFilter(int client, int args)
{
// g_aClientFilters[client].PushString(filter);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_ChatFilterGroup(int client, int args)
{
// ArrayList filters = new ArrayList(128);
// filters.PushString(filter);
// g_aGroupFilters[client].Push(filters);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action CCC_OnChatMessage(int client, int author, const char[] message)
{
bool bBlockMessage = false;
// Check the clients own filter list.
if (!bBlockMessage && g_aClientFilters[client].Length)
{
for (int filterID; filterID < g_aClientFilters[client].Length; filterID++)
{
char filter[128];
g_aClientFilters[client].GetString(filterID, filter, sizeof(filter));
if (StrContains(message, filter, false))
{
bBlockMessage = true;
break;
}
}
}
// Check the clients group filter lists.
if (!bBlockMessage && g_aGroupFilters[client].Length)
{
for (int groupID; groupID < g_aGroupFilters[client].Length; groupID++)
{
ArrayList filters = g_aGroupFilters[client].Get(groupID);
if (filters.Length)
{
for (int filterID; filterID < filters.Length; filterID++)
{
char filter[128];
filters.GetString(filterID, filter, sizeof(filter));
if (StrContains(message, filter, false))
{
bBlockMessage = true;
break;
}
}
}
}
}
return (bBlockMessage) ? Plugin_Handled : Plugin_Continue;
}