SA-MP Forums Archive
Anti-IP Advertisement - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Anti-IP Advertisement (/showthread.php?tid=653418)



Anti-IP Advertisement - TadePoleMG - 04.05.2018

Hi all Guys again

Can anyone help me to check if player types a IP Address. // OnPlayerText
if yes then he get warning and after 5 warnings reached, he will be kicked.

how to make it, Please help me.

Thank you
Helper must receives rep++.


Re: Anti-IP Advertisement - JesterlJoker - 04.05.2018

search the '.' for each octet.


Re: Anti-IP Advertisement - Zeth - 04.05.2018

You can use regex checks in pawn using some plugins available such as Pawn.Regex, so make a regex check for IP and you will have your own Anti-IP Advertisement or you can use Anti advertisement include made by Kar - https://sampforum.blast.hk/showthread.php?tid=604064


Re: Anti-IP Advertisement - jasperschellekens - 04.05.2018

Here you go:

antiadvertising.inc
PHP код:
/*
    Copyright 2016 Kar
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    stringContainsIP(const szStr[], bool:ignoreNegatives = false);
    This include accurately detects if an IP is in a string.
    Created by Kar on Wednesday, November 13th, 2017.
*/
#if defined _INC_ANTI_ADVERTISING
    #endinput
#endif
#define _INC_ANTI_ADVERTISING
stock stringContainsIP(const szStr[], bool:fixedSeparation falsebool:ignoreNegatives falsebool:ranges true// bool:ipMustHavePort = true
{
    new 
        
0chlastChlen strlen(szStr), trueIPInts 0bool:isNumNegative falsebool:numIsValid true// Invalid numbers are 1-1
        
numberFound = -1numLen 0numStr[5], numSize sizeof(numStr),
        
lastSpacingPos = -1numSpacingDiffnumLastSpacingDiffnumSpacingDiffCount // -225\0 (4 len)
    
;
    while(
<= len)
    {
        
lastCh ch;
        
ch szStr[i];
        if(
ch >= '0' && ch <= '9' || (ranges == true && ch == '*')) {
            if(
numIsValid && numLen numSize) {
                if(
lastCh == '-') {
                    if(
numLen == && ignoreNegatives == false) {
                        
isNumNegative true;
                    }
                    else if(
numLen 0) {
                        
numIsValid false;
                    }
                }
                
numberFound strval(numStr);
                if(
numLen == (_:isNumNegative) && !(numberFound >= -255 && numberFound <= 255)) { // IP Num is valid up to 4 characters.. -255
                    
for(numLen 3numLen 0numLen--) {
                        
numStr[numLen] = EOS;
                    }
                }
                else if(
lastCh == '-' && ignoreNegatives) {
                    
i++;
                    continue;
                } else {
                    if(
numLen == && numIsValid == true && isNumNegative == true && lastCh == '-') {
                        
numStr[numLen++] = lastCh;
                    }
                    
numStr[numLen++] = ch;
                }
            }
        } else {
            if(
numLen && numIsValid) {
                
numberFound strval(numStr);
                if(
numberFound >= -255 && numberFound <= 255) {
                    if(
fixedSeparation) {
                        if(
lastSpacingPos != -1) {
                            
numLastSpacingDiff numSpacingDiff;
                            
numSpacingDiff lastSpacingPos numLen;
                            if(
trueIPInts == || numSpacingDiff == numLastSpacingDiff) {
                                ++
numSpacingDiffCount;
                            }
                        }
                        
lastSpacingPos i;
                    }
                    if(++
trueIPInts >= 4) {
                        break;
                    }
                }
                for(
numLen 3numLen 0numLen--) {
                    
numStr[numLen] = EOS;
                }
                
isNumNegative false;
            } else {
                
numIsValid true;
            }
        }
        
i++;
    }
    if(
fixedSeparation == true && numSpacingDiffCount 3) {
        return 
0;
    }
    return (
trueIPInts >= 4);

pawn:
PHP код:
#include <antiadvertising>
new PlayerAdvertisementCount[MAX_PLAYERS];
public 
OnPlayerText(playerid,text[])
{
    if(
stringContainsIP(text))
    {
        if(
PlayerAdvertisementCount[playerid] > 5)
        {
            
// kick the player 
        
} else {
            
PlayerAdvertisementCount[playerid] ++;
// send a warning to the playte
        
}
    }
    return 
1;




Re: Anti-IP Advertisement - CrystalGamer - 04.05.2018

PHP код:
stock AntiAdv(playeridtext[])
{
    
// Anti Adv
    
new strR[255], is1=0r=0;
     while(
strlen(text[is1]))
     {
          if(
'0'<=text[is1]<='9')
          {
             new 
is2=is1+1p=0;
               while(
p==0)
              {
                   if(
'0'<=text[is2]<='9'&&strlen(text[is2]))
                   {
                   
is2++;
                }
                 else
                  {
                       
strmid(strR[r],text,is1,is2,255);
                       if(
strval(strR[r])<255r++;
                    
is1=is2;
                    
p=1;
                }
            }
        }
        
is1++;
     }
     if(
r>=4)
     {
           new 
pr2;
          for(new 
z=0;z<r;z++)
          {

               while((
pr2=strfind(text,strR[z],true))!=-1)
            {
                for(new 
i=pr2,j=pr2+strlen(strR[z]);i<j;i++)
                {
                    
text[i]='*';
                }
            }
          }
          return 
1;
     }
     return 
0;

Код:
public OnPlayerText(playerid, text[])
{
    if(AntiAdv(playerid, text)) return 0;
   return 0;
}
maybe i helped you


Re: Anti-IP Advertisement - TadePoleMG - 04.05.2018

It won't works for me is it need any plugin or what help me.


Re: Anti-IP Advertisement - jasperschellekens - 04.05.2018

Quote:
Originally Posted by TadePoleMG
Посмотреть сообщение
It won't works for me is it need any plugin or what help me.
The one i posted works 100 percent.