Raised This Month: $ Target: $400
 0% 

[HELP] I have a problem with regex in my plugin.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
unSeen
Member
Join Date: Sep 2008
Old 04-04-2009 , 17:48   [HELP] I have a problem with regex in my plugin.
Reply With Quote #1

Hey everyone..
I've made a plugin that censor a words that written in a text file.
The code compiles and everything is allright, but when i test it, and write in the chat for example: "i love my people" and it not doing nothing.

PHP 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 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]
new 
g_pcvFD
public plugin_init() {
 
// Register the plugin - name, version and author.
 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
// 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 0MAX_WORDSi++)
 {
  
g_arrszWords[i] = 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(cfgDirLEN_CFGDIR)
 
//server_print("%s", cfgDir)  // Debug line.
 
 // Adds the file name into the directory.
 
format(dirFileLEN_TOTAL"%s/%s"cfgDirTXT_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(fhfDataLEN_DATA)
 
   
// Write the word in the array.
   
formatex(g_arrszWords[nCount], MAX_WORDSfData)
 
   
// 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(szTextLEN_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 (0MAX_WORDSj++)
 {
  new 
nNumber
  
new nError[LEN_ERROR STRING_OFFSET]
  new 
Regex:rgxMatch
 
  
// If there is no more words, return false.
  
if (g_arrszWords[j] == NULL) {
   break
  }
  
rgxMatch regex_match(szCheckTextg_arrszWords[j], nNumbernErrorLEN_ERROR)
 
  
// If is match, return true.
  
if (nNumber >= 1) {
   
//server_print("regexok") // debug line
   
return true
  
}
 
  
// Free the regex memmory.
  
regex_free(rgxMatch)
 }
 return 
false 

if you prefer [ CODE ] format:
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 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]
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] = 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], MAX_WORDS, 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++)
 {
  new nNumber
  new nError[LEN_ERROR + STRING_OFFSET]
  new Regex:rgxMatch
  
  // If there is no more words, return false.
  if (g_arrszWords[j] == NULL) {
   break
  }
  rgxMatch = regex_match(szCheckText, g_arrszWords[j], nNumber, nError, LEN_ERROR)
  
  // If is match, return true.
  if (nNumber >= 1) {
   //server_print("regexok") // debug line
   return true
  }
  
  // Free the regex memmory.
  regex_free(rgxMatch)
 }
 return false 
}
The words.txt looks like that:
PHP Code:
/l[o0]ve/i
/f[ua]ck/i
/n[o0][o0]b/
i tried manyways to fix it, like remove the first "/" or remove them both and not using the i header that suppost to sensivity case.

Please help me!
You'rs,
Elad.
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)

Last edited by unSeen; 04-04-2009 at 17:51.
unSeen is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-04-2009 , 19:08   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #2

The biggest mistake is that g_arrszWords is an array of single cells when it needs to be an array of strings.

I've never had to use "/pattern/", I've only needed "pattern" and case insensitivity can be acheived using a flag on the regex_match function.

Also, take a look at this:

http://wiki.amxmodx.org/Advanced_Scr...ar_Expressions
__________________
fysiks is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 04-04-2009 , 20:02   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #3

PHP Code:
if (nNumber >= 1) {
   
//server_print("regexok") // debug line
   
return true
  
}
 
  
// Free the regex memmory.
  
regex_free(rgxMatch)
 }
 return 
false 
}

--->
 
  
// Free the regex memmory.
  // You must do this no matter what(I think, I don't know anything about regex)
  // and when you returned true it stopped the funcion without doing this.
  
regex_free(rgxMatch);
 }
 return 
nNumber true false;

__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
unSeen
Member
Join Date: Sep 2008
Old 04-05-2009 , 00:43   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #4

Thank you both.
I have to go work now so i'll test everything you said when I back.
But I have a question to fysiks ,
What you mean
Quote:
The biggest mistake is that g_arrszWords is an array of single cells when it needs to be an array of strings.
I couldn't understand.
Why I need to use [][] array? it will be like new array[32][1] and it's looks pretty stupid O_o.
Can you please explain you'r self?

Thank you alot again.
Elad.

Edit:
I read in the link wich you gave me (this) and nothing is written there about Sensivity case.
also in the AMXx.org functions -> regex_match there is nothing about Sensivity Case.
btw, In every language regex pattern is between two "/" and after the second one comes the header flags, 'i' is the one that tells the regex to ignore sensivity case.
I really stack now and I don't know what to do.
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)

Last edited by unSeen; 04-05-2009 at 06:37.
unSeen is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-05-2009 , 08:48   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #5

Quote:
Originally Posted by unSeen View Post
What you mean
I couldn't understand.
Why I need to use [][] array? it will be like new array[32][1] and it's looks pretty stupid O_o.
Can you please explain you'r self?
A string is an array of characters.
Therefore an array of strings is an array of arrays.
Therefore it is a two dimensional array.

Line 21: new g_arrszWords[MAX_WORDS + WORDS_OFFSET][LEN_WORDS+1]
Line 44: g_arrszWords[i][0] = NULL
Line 84: formatex(g_arrszWords[nCount], LEN_WORDS, fData)
Line 141: if (g_arrszWords[j][0] == NULL) {

Line 134: I'd think it would be more efficient to loop over only nCount and not MAX_WORDS everytime. You could get rid of anything with NULL.


Quote:
Originally Posted by unSeen View Post
I read in the link wich you gave me (this) and nothing is written there about Sensivity case.
also in the AMXx.org functions -> regex_match there is nothing about Sensivity Case.
That link was just to show you how they suggest you use regex. The case insensitivity flag is in the comment in regex.inc:

Code:
/**
 * Matches a string against a regular expression pattern.
 *
 * @note                If you intend on using the same regular expression pattern
 *                        multiple times, consider using regex_compile and regex_match_c 
 *                        instead of making this function reparse the expression each time.
 *
 * @param string       The string to check.
 * @param pattern      The regular expression pattern.
 * @param ret          Error code, or result state of the match.
 * @param error        Error message, if applicable.
 * @param maxLen       Maximum length of the error buffer.
 * @param flags        General flags for the regular expression.
 *                        i = Ignore case
 *                        m = Multilines (affects ^ and $ so that they match 
 *                            the start/end of a line rather than matching the 
 *                            start/end of the string).
 *                        s = Single line (affects . so that it matches any character, 
 *                            even new line characters).
 *                        x = Pattern extension (ignore whitespace and # comments).
 *
 * @return                -2 = Matching error (error code is stored in ret)
 *                        -1 = Error in pattern (error message and offset # in error and ret)
 *                         0 = No match.
 *                        >1 = Handle for getting more information (via regex_substr)
 *
 * @note                Flags only exist in amxmodx 1.8 and later.
 * @note                You should free the returned handle (with regex_free())
 *                        when you are done extracting all of the substrings.
 */
native Regex:regex_match(const string[], const pattern[], &ret, error[], maxLen, const flags[] = "");


Quote:
Originally Posted by unSeen View Post
btw, In every language regex pattern is between two "/" and after the second one comes the header flags, 'i' is the one that tells the regex to ignore sensivity case.
Not true. They don't use delimiters in the example and I've never used them when using POSIX ERE.

Maybe it will work after you get strings in your array. But I don't know why they would add that flag if you could just use what you describe there.
__________________
fysiks is offline
unSeen
Member
Join Date: Sep 2008
Old 04-05-2009 , 09:51   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #6

I tried what you said, and when I looked at it again, it's the same. but your idea is more effectivity.
It still returns me the same error in the server runtime plugin debug. (-debug)

I copied it:

Code:
L 04/05/2009 - 16:43:15: [AMXX] Plugin file open error (plugin "commands")
L 04/05/2009 - 16:44:43: [REGEX] Invalid regex handle -1
L 04/05/2009 - 16:44:43: [AMXX] Displaying debug trace (plugin "flame_detector.amxx")
L 04/05/2009 - 16:44:43: [AMXX] Run time error 10: native error (native "regex_free")
L 04/05/2009 - 16:44:43: [AMXX]    [0] flame_detector.sma::isFound (line 165)
L 04/05/2009 - 16:44:43: [AMXX]    [1] flame_detector.sma::FlameHandler (line 117)

Any suggestions?


(btw if i didn't say that, i appreaciate you'r help! thank!)
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)
unSeen is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-05-2009 , 10:57   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #7

From that link:
PHP Code:
if (re >= REGEX_OK)
{
    new 
str2[64]
    new 
i
    
//since it returned REGEX_OK, num has
    // the number of substrings matched by the pattern.
    //the first substring (0) seems to match the whole string.
    
for (i=0i<numi++)
    {
        
regex_substr(reistr263)
        
server_print("Substring %d: %s"istr2)
    }
    
//the regular expression matcher uses memory.
    //you must free it if you get REGEX_OK
    //This will also set re to 0.
    
regex_free(re)

You can only free the regex handle if you found a match (i.e. handle >= REGEX_OK). I would use the above if() statement instead of if( nNumber >= 1).

Problem fixed .
__________________
fysiks is offline
unSeen
Member
Join Date: Sep 2008
Old 04-05-2009 , 11:22   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #8

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 
}
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)
unSeen is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-05-2009 , 12:54   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #9

I can't tell. I just took your plugin and change it a bit. This works:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <regex>

#define PLUGIN "Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"

#define FILENAME  "badwords.ini" // Define the words list TXT file name.
#define MAX_WORDS 32  // Define the max bad words wich can be in the file.
#define LEN_WORDS 32  // Define the max length of words
#define LEN_CHAT 127 // Define the max length of retrieved chat message
#define CVAR_CENSOR 1  // Define the censor cvar.
#define CVAR_KICK 2  // Define the kick cvar.


new g_arrszWords[MAX_WORDS][LEN_WORDS+1]
new 
g_iWordCount
new g_pcvFD

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_pcvFD register_cvar("fd_cvar""1")
    
register_clcmd("say""FlameHandler")
    
register_clcmd("say_team""FlameHandler")
    
g_iWordCount LoadWords()
}

LoadWords()
{
    new 
wordsfile[64], count 0
    get_configsdir
(wordsfilesizeof(wordsfile) - 1)
    
format(wordsfilesizeof(wordsfile) - 1"%s/%s"wordsfileFILENAME)
    
    if( !
file_exists(wordsfile) ) return 0
    
    
new fopen(wordsfile"rt")
    
    new 
data[128]
    while( !
feof(f) && count MAX_WORDS
    { 
        
fgets(fdatasizeof(data) - 1)
        
        
// Trim must be before !data[0] check :)
        
trim(data// Trim newline and carriage return

        
if( !data[0] || data[0] == ';'
           
|| data[0] == '/' && data[1] == '/' ) continue; // Skip line if comment or blank
        
        
copy(g_arrszWords[count], LEN_WORDSdata// Put word into global array
        // console_print(0,"Word(%d): %s", count, g_arrszWords[count]) // debug
        
count++
    }
    
    
fclose(f)
    return 
count
}
public 
FlameHandler(id)
{
    static 
cvar
    cvar 
get_pcvar_num(g_pcvFD)
    
// If the cvar forced as off, not doing nothing.
    
if (!cvar || !g_iWordCount)
        return 
PLUGIN_CONTINUE
    
    
// Variable definize.
    
new szText[LEN_CHAT+1]
    
    
// Read the user message.
    
read_args(szTextLEN_CHAT)
    
    
// If there is a flame in the text.
    
if (isFound(szText))
    {
        
// If the cvar is "1", it censor the message.
        
switch(cvar)
        {
            case 
CVAR_CENSOR: return PLUGIN_HANDLED
            
case 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[])
{
    
// Code section.
    // Looping the badwords array.
    
new Regex:rgxMatch
    
new nNumbernError[128]

    for (new 
0g_iWordCountj++)
    {
        
rgxMatch regex_match(szCheckTextg_arrszWords[j], nNumbernError127"i")
        
        
// If is match, return true.
        
if (rgxMatch >= REGEX_OK)
        {
            
//server_print("regexok") // debug line
            // Free the regex memmory.
            
regex_free(rgxMatch)
            
            return 
true
        
}
    }
    return 
false 

I don't understand why you are trying to use an offsetsfor max words.
__________________
fysiks is offline
unSeen
Member
Join Date: Sep 2008
Old 04-05-2009 , 13:33   Re: [HELP] I have a problem with regex in my plugin.
Reply With Quote #10

Wow! thanks alot!
i really appricaite you'r help!

Thanks in addition,
Elad.
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)
unSeen is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode