sm-plugins/spamguard.sp

82 lines
2.0 KiB
SourcePawn

/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
new String:badwords[300][100];
new clientpunkte[MAXPLAYERS+1];
new wordcount = 0;
new Handle:cv_limit, var_limit;
public Plugin:myinfo =
{
name = "SpamProtect",
author = "Chefe",
description = "<- Description ->",
version = "1.0",
url = "<- URL ->"
}
public OnPluginStart()
{
HookEvent("player_say", Event_PlayerChat, EventHookMode_Pre);
cv_limit = CreateConVar("sm_sg_limit", "3", "Set Inslut-limit");
HookConVarChange(cv_limit, OnLimitChange);
new String:path[500];
BuildPath(Path_SM, path, sizeof(path), "configs/badwords.txt");
ReadTextFile(path);
var_limit = GetConVarInt(cv_limit);
AutoExecConfig(true);
}
public OnLimitChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
var_limit = StringToInt(newVal);
}
public Event_PlayerChat(Handle:event, const String:name[], bool:dontBroadcast)
{
new uid = GetEventInt(event, "userid");
new client = GetClientOfUserId(uid);
new String:text[200];
GetEventString(event, "text", text, sizeof(text));
new String:splitedtext[150][100];
new sdsize = ExplodeString(text, " ", splitedtext, 150, 100);
for (new i = 0; i < sdsize; i++)
{
for (new k = 0; k < wordcount; k++)
{
if (ReplaceString(splitedtext[i], 100, badwords[k], "*******", false) > 0)
{
clientpunkte[client]++;
PrintToChat(client, "\x04Insults are disallowed on this server! Waring %i/%i", clientpunkte[client], var_limit);
if (clientpunkte[client] >= 3)
{
KickClient(client, "Insults are not allowed -> limit reached (%i)", var_limit);
}
}
}
}
}
ReadTextFile(String:file[])
{
new Handle:filehandle = OpenFile(file, "r");
new String:firstline[500];
ReadFileString(filehandle, firstline, sizeof(firstline));
CloseHandle(filehandle);
new String:splitedfirstline[50][100];
wordcount = ExplodeString(firstline, ",", splitedfirstline, 50, 100);
new i = 0;
while (i != wordcount)
{
badwords[i] = splitedfirstline[i];
i++;
}
}