Range IP
#1

PHP код:
stock PlayerRangeIP(TargetID)
{
    new 
String[256];
    new 
IPCoordinates[4][3];
    
split(PlayerIP(TargetID), IPCoordinates'.');
    
format(String256"banip %s.%s.*.*"IPCoordinates[0], IPCoordinates[1]);
    return 
String;

the split function:
PHP код:
stock split(const strsrc[], strdest[][], delimiter)
{
    new 
ili;
    new 
aNum;
    new 
len;
    while(
<= strlen(strsrc))
    {
        if(
strsrc[i] == delimiter || == strlen(strsrc))
        {
            
len strmid(strdest[aNum], strsrclii128);
            
strdest[aNum][len] = 0;
            
li i+1;
            
aNum++;
        }
        
i++;
    }
    return 
1;

Output: 1921681.1681.*.*

What i'm doing wrong ??
Reply
#2

I suggest you use sscanf. For all your string splitting needs.
pawn Код:
new ipParts[4];
sscanf(ip, "p<.>a<i>[4]", ipParts);

new range[20];
format(range, sizeof(range), "banip %d.%d.*.*", ipParts[0], ipParts[1]);
Reply
#3

its now 0.0.*.*
Reply
#4

pawn Код:
stock split(const src[], dest[][], delimiter = '.', src_size = sizeof(dest), s_size = sizeof(dest[]))
{
    new i,num,pos,len = strlen(src);

    while(i != len+1)
    {
        if(num >= src_size) return;
        if(src[i] == delimiter || i == len)
        {
            strmid(dest[num++], src, pos, i, s_size);
            pos = i+1;
        }
        i++;
    }
    return;
}

stock PlayerRangeIP(TargetID)
{
    new String[20],IPCoordinates[2][4];
    split(PlayerIP(TargetID), IPCoordinates);
    format(String, sizeof(String), "banip %s.%s.*.*", IPCoordinates[0], IPCoordinates[1]);
    return String;
}
Reply
#5

solved using:
pawn Код:
stock PlayerRangeIP(PlayerID)
{
    new RangeIP[16];
    new NormalIP[16];
    GetPlayerIp(PlayerID, NormalIP, 16);
    new Count;
    for(new i = 0; i < 16; i++)
    {
        if(NormalIP[i] == '.')
        {
            Count++;
        }
        if(Count == 2)
        {
            i++;
            strdel(NormalIP, i, 16);
            format(RangeIP,16,"%s*.*",NormalIP);
        }
    }
    return RangeIP;
}
thanks guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)