Yey! you were right! ;-)
But still it ain't working! and I can't get it! why?! i loop my eyes over the code thousend times and I don't see something wrong.
From what I see, you are geniuess ;> Maybe you will find something?
The code looks like that.
The problem?
in badwords.txt there is only one pattern that looks like this: z[o0]na
And let's say that the cvar now is on "1" (blocks the message if the word in the sentence),
i write "zona" or "z0na" and it not blocking it. the same in the other cvars.
Please help!
Code:
#include <amxmodx>
#include <amxmisc>
#include <regex>
#define PLUGIN "Flame Detector"
#define VERSION "1.0"
#define AUTHOR "unSeen"
#define STRING_OFFSET 1 // Define the len of the offset string.
#define LEN_CFGDIR 127 // Define the len of the configs folder path.
#define LEN_TOTAL 255 // Define the total len of the configs path + filename path.
#define LEN_DATA 127 // Define the len of the TXT file data.
#define LEN_TEXT 192 // Define the user text len in chat.
#define LEN_ERROR 127 // Define the error max len.
#define LEN_PATTERN 32 // Define the regex pattern len.
#define TXT_FILENAME "badwords.txt" // Define the words list TXT file name.
#define MAX_WORDS 32 // Define the max bad words wich can be in the file.
#define WORDS_OFFSET 1 // Define the bad words offset.
#define NULL 0 // Define the null char.
#define CVAR_IGNORE 0 // Define the ignore cvar.
#define CVAR_CEN 1 // Define the censor cvar.
#define CVAR_KICK 2 // Define the kick cvar.
new g_arrszWords[MAX_WORDS + WORDS_OFFSET][LEN_PATTERN + STRING_OFFSET]
new g_pcvFD
public plugin_init() {
// Register the plugin - name, version and author.
register_plugin(PLUGIN, VERSION, AUTHOR)
// Register cvar num. 0|1|2. (0 nothing, 1 censor the message, 2 kick the player)
g_pcvFD = register_cvar("fd_cvar", "1")
// When some one say something in the server-Chat.
register_clcmd("say", "FlameHandler")
// When some one say something in the server-teamChat.
register_clcmd("say_team", "FlameHandler")
// Loads the blocked words from a TXT file.
LoadWords()
}
LoadWords()
{
// Reset the array.
for (new i = 0; i < MAX_WORDS; i++)
{
g_arrszWords[i][0] = NULL
}
// Variable definize
new cfgDir[LEN_CFGDIR + STRING_OFFSET]
new dirFile[LEN_TOTAL + STRING_OFFSET]
new fh
// Code section.
// Gets the CFG directory.
get_configsdir(cfgDir, LEN_CFGDIR)
//server_print("%s", cfgDir) // Debug line.
// Adds the file name into the directory.
format(dirFile, LEN_TOTAL, "%s/%s", cfgDir, TXT_FILENAME)
//server_print("%s", dirFile) // Debug line.
// Opens the file, and read it.
fh = fopen(dirFile, "r")
// If file exist.
if (fh)
{
// Variable section
new nCount = 0
// While it's not the end of the TXT file.
while (!feof(fh))
{
// If the is more than 32 words breaks the loop.
if (nCount > MAX_WORDS)
break
// Variable section.
new fData[LEN_DATA + STRING_OFFSET]
// Get the data of the line.
fgets(fh, fData, LEN_DATA)
// Write the word in the array.
formatex(g_arrszWords[nCount], LEN_PATTERN, fData)
// Increase the counter.
nCount++
}
}
return PLUGIN_CONTINUE
}
public FlameHandler(id)
{
// If the cvar forced as off, not doing nothing.
if (get_pcvar_num(g_pcvFD) == CVAR_IGNORE)
return PLUGIN_CONTINUE
// Variable definize.
new szText[LEN_TEXT + STRING_OFFSET]
// Read the user message.
read_args(szText, LEN_TEXT)
// Remove the quotes.
remove_quotes(szText)
// If there is a flame in the text.
if (isFound(szText))
{
// If the cvar is "1", it censor the message.
if (get_pcvar_num(g_pcvFD) == CVAR_CEN) {
return PLUGIN_HANDLED
}
// If the cvar is "2", it kicks the player.
else if (get_pcvar_num(g_pcvFD) == CVAR_KICK) {
new nUserID = get_user_userid(id)
server_cmd("kick #%d You used a bad word! don't repeat you'r self!", nUserID)
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
stock bool:isFound(const szCheckText[])
{
// Variable definize.
new j
// Code section.
// Looping the badwords array.
for (j = 0; j < MAX_WORDS; j++)
{
// If there is no more words, return false.
if (g_arrszWords[j][0] == NULL) {
break
}
new nNumber
new nError[LEN_ERROR + STRING_OFFSET]
new Regex:rgxMatch
rgxMatch = regex_match(szCheckText, g_arrszWords[j], nNumber, nError, LEN_ERROR, "i")
// If is match, return true.
if (rgxMatch >= REGEX_OK) {
//server_print("regexok") // debug line
// Free the regex memmory.
regex_free(rgxMatch)
return true
}
// Free the regex memmory.
//regex_free(rgxMatch)
}
return false
}
__________________