Anti-IP Advertisement
#4

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...5.50323128
    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;

Reply


Messages In This Thread
Anti-IP Advertisement - by TadePoleMG - 04.05.2018, 12:13
Re: Anti-IP Advertisement - by JesterlJoker - 04.05.2018, 12:19
Re: Anti-IP Advertisement - by Zeth - 04.05.2018, 12:30
Re: Anti-IP Advertisement - by jasperschellekens - 04.05.2018, 13:39
Re: Anti-IP Advertisement - by CrystalGamer - 04.05.2018, 13:59
Re: Anti-IP Advertisement - by TadePoleMG - 04.05.2018, 15:22
Re: Anti-IP Advertisement - by jasperschellekens - 04.05.2018, 18:57

Forum Jump:


Users browsing this thread: 1 Guest(s)