Raised This Month: $ Target: $400
 0% 

conaini counts


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Schwabba
Senior Member
Join Date: Apr 2008
Old 06-23-2011 , 09:50   conaini counts
Reply With Quote #1

Someone knows how to count how many time string A is in string B?

Example:

I made a anti-swear-plugin and added words like "low" or "affe (german for ape)", but now it blocks words like "glow" and "waffe (german for weapon)" too, so i added an ignore list looks like:

PHP Code:
            new 0
            
while ( g_swearNum_high )
            {
                if ( 
containi messagebadword_high[i++] ) != -)
                {
                    
b_found++
                }
            }
            
0
            
while ( g_swearNum_ignore )
            {
                if ( 
containi messagebadword_ignore[i++] ) != -)
                {
                    
b_ignore++
                }
            }
            if(
b_found != b_ignore)
            {
                ... 
// there is a badword found
            

But if you say the same badword more times, you can still insult like "glow you low", because it sets the variable b_found only +1 (it checks if the word "low" is inside the string and not how many times it's inside).

Someone understand that and knows how to fix it? xD
Schwabba is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-23-2011 , 10:13   Re: conaini counts
Reply With Quote #2

PHP Code:
            new iposold
            
for ( 0g_swearNum_highi++ )
            {
                
pos 0
                old 
= -1
                
while ( ( pos += containi messagepos ], badword_high[i] ) ) > old )
                {
                    
b_found++
                    
old pos
                
}
            }
            for ( 
0g_swearNum_ignorei++ )
            {
                
pos 0
                old 
= -1
                
while ( ( pos += containi messagepos ], badword_ignore[i] ) ) > old )
                {
                    
b_ignore++
                    
old pos
                
}
            }
            if(
b_found != b_ignore)
            {
                ... 
// there is a badword found
            

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Schwabba
Senior Member
Join Date: Apr 2008
Old 06-23-2011 , 11:30   Re: conaini counts
Reply With Quote #3

Mhh it's still the same problem, now i got this code:

PHP Code:
            new iposoldb_foundb_ignore
            
for ( 0g_swearNum_highi++ )
            {
                
pos 0
                old 
= -1
                
while ( ( pos += containi messagepos ], badword_high[i] ) ) > old )
                {
                    
b_found++
                    
old pos
                
}
            }
            for ( 
0g_swearNum_midi++ )
            {
                
pos 0
                old 
= -1
                
while ( ( pos += containi messagepos ], badword_mid[i] ) ) > old )
                {
                    
b_found++
                    
old pos
                
}
            }
            for ( 
0g_swearNum_warni++ )
            {
                
pos 0
                old 
= -1
                
while ( ( pos += containi messagepos ], badword_warn[i] ) ) > old )
                {
                    
b_found++
                    
old pos
                
}
            } 
            for ( 
0g_swearNum_ignorei++ )
            {
                
pos 0
                old 
= -1
                
while ( ( pos += containi messagepos ], badword_ignore[i] ) ) > old )
                {
                    
b_ignore++
                     
old pos
                
}
            } 
            if(
b_found == b_ignore)
            {
                
badword_found true
            

I got 4 configs there, low mid and high with insults in it and one with the words to ignore.

warn = just block (not that hard insults)
mid = gag for 1 hour (mid insults)
high = gag for 1 day (hard insults)
Schwabba is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-23-2011 , 15:40   Re: conaini counts
Reply With Quote #4

Instead of doing an "ignore" list, you should properly check for bad words that aren't inside of other words.

Here's some example code, which you'll have to translate to your own variables and such.

Code:
checkSaid(said[]) {     new pos, len;     for(new i = 0; i < sizeof(g_badWords); i++)     {         pos = containi(said, g_badWords[i]);                 // bad word found         if(pos >= 0)         {             // if there is nothing before it so it's the start of the word             if(pos == 0 || !isalpha(said[pos - 1]))             {                 // if there is nothing after it, so then the bad word is singled out                 if(!isalpha(said[pos + strlen(g_badWords[i])]))                 {                     // bad word found                     return 1;                 }             }         }     }         // no bad words found     return 0; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Schwabba
Senior Member
Join Date: Apr 2008
Old 06-24-2011 , 06:43   Re: conaini counts
Reply With Quote #5

That's not better, because there are badwords like:

Hure (whore)
Hurensohn (son of a whore)
Hurenkind (child of a whore)

etc. hundrets more

Or the people start to insult with "!" behind the badwords or something.



Now i made it like that:

PHP Code:
        new len strlen(message)
        new 
asc 0num 0
        
for (new 0;<= len;i++)
        {
            if (
message[i] == 32)
            {
                
asc++
                
num 0
            
}
            else
            {
                
token[asc][num] = message[i]
                
num++
            }
        }
        new 
b_foundb_ignore
        
for (new 0;<= len;i++)
        {
            if(
token[i][0])
            {
                new 
b_word 0
                
while ( b_word g_swearNum_high )
                {
                    if ( 
containi token[i], badword_high[b_word++] ) != -)
                    {
                        
b_found++
                    }
                }
                
b_word 0
                
while ( b_word g_swearNum_mid )
                {
                    if ( 
containi token[i], badword_mid[b_word++] ) != -)
                    {
                        
b_found++
                    }
                }
                
b_word 0
                
while ( b_word g_swearNum_warn )
                {
                    if ( 
containi token[i], badword_warn[b_word++] ) != -)
                    {
                        
b_found++
                    }
                }
                
b_word 0
                
while ( b_word g_swearNum_ignore )
                {
                    if ( 
containi token[i], badword_ignore[b_word++] ) != -)
                    {
                        
b_ignore++
                    }
                }
                
copy(token[i], 511"0")
            }
        }
        if(
b_found <= b_ignore)
        {
            
badword_found true
        

It's a weird way, but it works better than everything else.

Last edited by Schwabba; 06-24-2011 at 08:42.
Schwabba is offline
Reply


Thread Tools
Display Modes

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 23:23.


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