Altta yazdığı şekilde istediğin yasaklı kelimeyi ekleyebilirisn.
Kod: Tümünü seç
#include <amxmodx>
#include <amxmisc>
#include <regex>
// Comment out this line to only block the messages from chat
#define GAG_PLAYER
#if defined GAG_PLAYER
#include <nvault>
#include <unixtime>
#endif
// max length of the pattern
// if it seems that it cuts off when loading, increase this value appropriately
#define MAX_PATTERN_LEN 128
enum _:FilterData {
Filter_IsRegex,
Filter_Pattern,
Filter_String[MAX_PATTERN_LEN + 1],
Filter_MatchIndex,
Filter_HideOnly
};
new Array:gFilterData;
new gNumFilters;
new Array:gWhiteLists;
new gNumWhiteLists;
new gReturnFromRegex;
#if defined GAG_PLAYER
new Array:gGagTimes;
new gNumTimes;
new const gDefaultTimes[] = {
5, 10, 15
};
new gCvarWarning;
new gVault;
#endif
new gCvarLog;
new gLogDir[64];
new gCvarHideHard;
public plugin_init() {
new const VERSION[] = "0.0.6";
#if defined GAG_PLAYER
register_plugin("Swear Filter [+Gag]", VERSION, "Exolent");
#else
register_plugin("Swear Filter", VERSION, "Exolent");
#endif
// load the swear pattern before anything
// so we can stop the plugin in case there are no words
LoadPattern();
// load white lists
LoadWhiteLists();
#if defined GAG_PLAYER
register_srvcmd("swear_filter_times", "CmdSetTimes");
#endif
register_clcmd("say", "CmdSay");
register_clcmd("say_team", "CmdSay");
#if defined GAG_PLAYER
gCvarWarning = register_cvar("swear_filter_warning", "* WARNING! You will be gagged next time you swear!");
gGagTimes = ArrayCreate();
// default times
for(new i = 0; i < sizeof(gDefaultTimes); i++) {
ArrayPushCell(gGagTimes, gDefaultTimes[i]);
}
gNumTimes = sizeof(gDefaultTimes);
// prepare our vault
gVault = nvault_open("swear_filter");
// grab this time's info
new year, month, day, hour, minute, second;
UnixToTime(get_systime(), year, month, day, hour, minute, second);
// prune from the beginning of time to the start of the day
nvault_prune(gVault, 0, TimeToUnix(year, month, day, 0, 0, 0));
#endif
gCvarLog = register_cvar("swear_filter_log", "1");
gCvarHideHard = register_cvar("swear_filter_hide_hard", "0");
get_localinfo("amxx_logs", gLogDir, charsmax(gLogDir));
add(gLogDir, charsmax(gLogDir), "/swear_filter");
if(!dir_exists(gLogDir)) {
mkdir(gLogDir);
}
}
public plugin_end() {
new filterData[FilterData];
for(new i = 0; i < gNumFilters; i++) {
ArrayGetArray(gFilterData, i, filterData);
if(filterData[Filter_IsRegex]) {
regex_free(Regex:filterData[Filter_Pattern]);
}
}
ArrayDestroy(gFilterData);
#if defined GAG_PLAYER
ArrayDestroy(gGagTimes);
nvault_close(gVault);
#endif
new Regex:pattern;
for(new i = 0; i < gNumWhiteLists; i++) {
pattern = ArrayGetCell(gWhiteLists, i);
regex_free(pattern);
}
ArrayDestroy(gWhiteLists);
}
#if defined GAG_PLAYER
public CmdSetTimes() {
new numArgs = read_argc() - 1;
if(numArgs < 1) {
log_amx("No times provided to swear_filter_times command.");
return PLUGIN_HANDLED;
}
new arg[12];
for(new i = 1; i <= numArgs; i++) {
read_argv(i, arg, charsmax(arg));
ArrayPushCell(gGagTimes, str_to_num(arg));
}
gNumTimes = numArgs;
log_amx("Gag times set.");
return PLUGIN_HANDLED;
}
#endif
public CmdSay(id) {
new args[194];
read_args(args, charsmax(args));
remove_quotes(args);
new filterData[FilterData], match[192], bool:matched;
for(new i = 0, j, Regex:pattern; i < gNumFilters; i++) {
ArrayGetArray(gFilterData, i, filterData);
// check if this matched a swear filter or contained a bad word
if(filterData[Filter_IsRegex] ? (regex_match_c(args, Regex:filterData[Filter_Pattern], gReturnFromRegex) > 0) : (containi(args, filterData[Filter_String]) >= 0)) {
// if we matched a swear filter and we need to check for white list
if(filterData[Filter_IsRegex] && filterData[Filter_MatchIndex] >= 0) {
// make sure we have valid match index
if(filterData[Filter_MatchIndex] >= gReturnFromRegex) {
log_amx("Could not check white list for this pattern ^"%s^" because the match index is too high.");
} else {
// let's check for white lists
regex_substr(Regex:filterData[Filter_Pattern], filterData[Filter_MatchIndex], match, charsmax(match));
matched = false;
for(j = 0; j < gNumWhiteLists; j++) {
pattern = ArrayGetCell(gWhiteLists, j);
if(regex_match_c(match, pattern, gReturnFromRegex) > 0) {
matched = true;
break;
}
}
if(matched) {
continue;
}
}
}
// if this is just to hide from chat
if(filterData[Filter_HideOnly]) {
return get_pcvar_num(gCvarHideHard) ? PLUGIN_HANDLED : PLUGIN_HANDLED_MAIN;
}
if(get_pcvar_num(gCvarLog)) {
new dateString[11];
get_time("%Y-%m-%d", dateString, charsmax(dateString));
new fileName[128];
formatex(fileName, charsmax(fileName), "%s/%s.log", gLogDir, dateString);
new f = fopen(fileName, "a+");
if(f) {
new timeString[9];
get_time("%H:%M:%S", timeString, charsmax(timeString));
new name[32], steamID[35];
get_user_name(id, name, charsmax(name));
get_user_authid(id, steamID, charsmax(steamID));
fprintf(f, "Player: %s <%s>^n", name, steamID);
fprintf(f, "Time: %s^n", timeString);
fprintf(f, "Message: ^"%s^"^n", args);
if(filterData[Filter_IsRegex]) {
fprintf(f, "Matched pattern: ^"%s^"^n", filterData[Filter_String]);
fputs(f, "Matches:^n");
for(new i = 0; i < gReturnFromRegex; i++) {
regex_substr(Regex:filterData[Filter_Pattern], i, args, charsmax(args));
fprintf(f, "- ^"%s^"^n", args);
}
} else {
fprintf(f, "Contained string: ^"%s^"^n", filterData[Filter_String]);
}
fputs(f, "^n=======================================^n^n");
fclose(f);
} else {
log_amx("Failed to open log file for writing: %s", fileName);
}
}
#if defined GAG_PLAYER
new steamID[35];
get_user_authid(id, steamID, charsmax(steamID));
new gagIndex = nvault_get(gVault, steamID);
if(gagIndex) {
server_cmd("amx_gag #%d %d", get_user_userid(id), ArrayGetCell(gGagTimes, min(gagIndex, gNumTimes) - 1));
} else {
get_pcvar_string(gCvarWarning, args, charsmax(args));
client_print(id, print_chat, "%s", args);
}
num_to_str(gagIndex + 1, args, charsmax(args));
nvault_set(gVault, steamID, args);
#else
client_print(id, print_chat, "* Your message was caught by the swear filter!");
#endif
return PLUGIN_HANDLED;
}
}
return PLUGIN_CONTINUE;
}
LoadPattern() {
new fileName[64];
get_configsdir(fileName, charsmax(fileName));
add(fileName, charsmax(fileName), "/swear_filters.ini");
new f = fopen(fileName, "rt");
if(f) {
gFilterData = ArrayCreate(FilterData);
new data[64 + MAX_PATTERN_LEN], type[8], filterData[FilterData], indexString[12], hideString[12];
new quoteIndex, i;
new const quoteReplacements[][] = {
""", "\'", "%'", "!qu'"
};
while(!feof(f)) {
fgets(f, data, charsmax(data));
trim(data);
quoteIndex = -1;
if(contain(data, "\^"") >= 0) {
for(i = 0; i < sizeof(quoteReplacements); i++) {
if(contain(data, quoteReplacements[i]) == -1) {
quoteIndex = i;
replace_all(data, charsmax(data), "\^"", quoteReplacements[i]);
break;
}
}
}
if(!data[0] || data[0] == ';' || data[0] == '/' && data[1] == '/'
|| parse(data, type, charsmax(type), filterData[Filter_String], charsmax(filterData[Filter_String]), indexString, charsmax(indexString), hideString, charsmax(hideString)) < 2) {
continue;
}
strtolower(type);
if(!equal(type, "regex") && !equal(type, "string")) {
continue;
}
if(quoteIndex != -1) {
replace_all(filterData[Filter_String], charsmax(filterData[Filter_String]), quoteReplacements[quoteIndex], "^"");
}
if((filterData[Filter_IsRegex] = (type[0] == 'r'))) {
if(!indexString[0] || !is_str_num(indexString) || (filterData[Filter_MatchIndex] = str_to_num(indexString)) < 0) {
filterData[Filter_MatchIndex] = -1;
}
filterData[Filter_Pattern] = _:regex_compile(filterData[Filter_String], gReturnFromRegex, data, charsmax(data), "i");
if(Regex:filterData[Filter_Pattern] < REGEX_OK) {
log_amx("Error with Regex pattern ^"%s^": %d %s", filterData[Filter_String], gReturnFromRegex, data);
continue;
}
}
filterData[Filter_HideOnly] = _:(equali(indexString, "hide") || equali(hideString, "hide"));
ArrayPushArray(gFilterData, filterData);
gNumFilters++;
}
fclose(f);
if(!gNumFilters) {
ArrayDestroy(gFilterData);
set_fail_state("No swear words to block. Disabling plugin");
}
} else {
log_amx("Unable to open %s", fileName);
set_fail_state("No swear filter file found.");
}
}
LoadWhiteLists() {
gWhiteLists = ArrayCreate();
new fileName[64];
get_configsdir(fileName, charsmax(fileName));
add(fileName, charsmax(fileName), "/swear_whitelist.ini");
new f = fopen(fileName, "rt");
if(f) {
new data[MAX_PATTERN_LEN + 8], Regex:pattern, patternString[MAX_PATTERN_LEN + 1], len;
new Regex:patternForPatterns = regex_compile("^^\/.+\/$", gReturnFromRegex, data, charsmax(data));
if(patternForPatterns < REGEX_OK) {
log_amx("Could not create pattern to find white lists: (%d) %s", gReturnFromRegex, data);
fclose(f);
return;
}
while(!feof(f)) {
len = fgets(f, data, charsmax(data)) - trim(data);
if(regex_match_c(data, patternForPatterns, gReturnFromRegex) <= 0) {
continue;
}
copy(patternString, min(charsmax(patternString), len - 2), data[1]);
pattern = regex_compile(patternString, gReturnFromRegex, data, charsmax(data), "i");
if(pattern < REGEX_OK) {
log_amx("Could not create pattern for ^"%s^": (%d) %s", patternString, gReturnFromRegex, data);
continue;
}
ArrayPushCell(gWhiteLists, pattern);
gNumWhiteLists++;
}
fclose(f);
} else {
log_amx("Unable to open %s", fileName);
}
}
Öncelikle yabancı bir kaynaktan baktığım için belki hata yapmış olabilirim şimdiden affola. Eğer olumlu,olumsuz pluginin çalışmasıyla ilgili sorun olursa burdan bilgilendirirsen elimden geleni yaparım.