Range IP - 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: Range IP (
/showthread.php?tid=416041)
[Solved]Range IP -
S0n1COwnsYou - 15.02.2013
PHP код:
stock PlayerRangeIP(TargetID)
{
new String[256];
new IPCoordinates[4][3];
split(PlayerIP(TargetID), IPCoordinates, '.');
format(String, 256, "banip %s.%s.*.*", IPCoordinates[0], IPCoordinates[1]);
return String;
}
the split function:
PHP код:
stock split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc))
{
if(strsrc[i] == delimiter || i == strlen(strsrc))
{
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
Output: 1921681.1681.*.*
What i'm doing wrong ??
Re: Range IP -
Vince - 15.02.2013
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]);
Re: Range IP -
S0n1COwnsYou - 15.02.2013
its now 0.0.*.*
Re: Range IP -
Jefff - 15.02.2013
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;
}
Re: Range IP -
S0n1COwnsYou - 16.02.2013
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