Raised This Month: $ Target: $400
 0% 

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


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 02:21.


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