Anti advertisement not working?
#1

PHP код:
stock AdvertisementCheck(string[])
{
    if(
string[0])
    {
        if(!
strfind(string,"www.",false) || !strfind(string,"http://",false)
        || !
strfind(string,".com",false) || !strfind(string,".net",false)
        || !
strfind(string,".de",false)  || !strfind(string,".org",false))
          return 
true;
          
        new 
c=1,idx,tmp[32],ip[4];
        for(new 
i=0;i<strlen(string);i++)
          if(
string[i]==' ')
          
c++;
        for(new 
i=0;i<c;i++)
        {
            
idx=0;
            
tmp L_strtok(string,idx);
            
idx=0;
            
tmp L_strtok(tmp,idx,':');
            
ip=SplitIP(tmp);
            if(
ip[0] && ip[1] && ip[2] && ip[3]) // We have found and IP :o
               
return true;
        }
    }
    return 
false;
}
stock L_strtok(const string[], &index,seperator=' ')
{
    new 
length strlen(string);
    new 
offset index;
    new 
result[32];
    while ((
index length) && (string[index] != seperator) && ((index offset) < (sizeof(result) - 1)))
    {
        
result[index offset] = string[index];
        
index++;
    }
    
result[index offset] = EOS;
    if ((
index length) && (string[index] == seperator))
    {
        
index++;
    }
    return 
result;
}
stock SplitIP(ip_string[])
{
    new 
ip[4],string[16];
    
format(string,sizeof(string),ip_string);
    for(new 
i=0;i<strlen(string);i++)
        if(
string[i]=='.')
            
string[i]=' ';
    new 
idx,tmp[32];
    for(new 
i=0;i<4;i++)
    {
        
tmp=L_strtok(string,idx);
        if(
tmp[0]=='*')
            
ip[i]=-1;
        else
            
ip[i]=strval(tmp);
    }
    return 
ip;

PHP код:
if(AdvertisementCheck(text))
    {
        
AccInfo[playerid][MaxAdv]++;
        new 
string[128];
        
format(string,sizeof(string),"|- Warning! Suspected ads in your message! (Warnings: %d/%d)",AccInfo[playerid][MaxAdv], MAX_ADV_WARNINGS);
        
SendClientMessage(playeridCOLOR_RED,string);    
        if(
AccInfo[playerid][MaxAdv] == MAX_ADV_WARNINGS)
        {
            
KickExMsg(playerid,"Advertising",INVALID_PLAYER_ID);
        }
        return 
0;
    } 
Yeah as title says, it doesn't work, When i use ip ex: 127.0.0.1:5415 it doesn't work
also if i used www.website.com or any website/ip it doesn't work
any idea/
PHP код:
    enum pInfo MaxAdv 
PHP код:
 new AccInfo[MAX_PLAYERS][pInfo]; 
Reply
#2

Check the documentation for strfind because you are using it incorrectly. You need to check that it is "not -1" rather than "equal to 0" because strfind returns the position the substring was found at and not just true or false.

Edit: for cleaner code and more efficient maintenance you should add all search keywords into an array and loop over it. To verify an IP address you can also use sscanf:
PHP код:
sscanf(input"{p<.>dddd}"
Reply
#3

I need a tutorial :P, I'm a newbie with strings :S
also
PHP код:
new ip[16];
if(
sscanf(text"{p<.>dddd}",ip)) return 1;
else return 
0
You mean like this?
Reply
#4

BUMP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)