Split 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: Split IP (
/showthread.php?tid=299177)
Split IP -
Mr.Momo - 24.11.2011
Hello All,
Today, I want to make a ban system with time and range ban.
I want to separate the numbers to compare in the banlist with numbers or * for each part of the IP.
Example: ip=
199.188.177.166
==> ip1="
199"; ip2="
188"; ip3="
177"; ip4="
166";
Код:
new jip[16], cip[4][3];
GetPlayerIp(playerid, jip, sizeof(jip));
split(jip, cip, '.');
But, with this script, I have:
ip1="
199"; ip2="
188177166"; ip3="
177166"; ip4="
166";
it's strange, I don't understand the function split
Quote:
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, 12 ;
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
|
What's the solution ?
thank you in advance

(sorry for my bad english)
Re: Split IP -
AndreT - 24.11.2011
I really don't want to go over the split function. It takes time for me to properly understand how it works and so on, but I have some suggestions for you:
1. Why not use sscanf to split up your IPs?
pawn Код:
sscanf(IP, "p<.>s[4]s[4]s[4]s[4]", IP[0], IP[1], IP[2], IP[3]);
2. The string size for one part of the IP needs to be 4, not 3 due to the null character in the end.
3. Use a ban system implementation similar to the one of Slice's
here. It makes scanning for range bans much more simple!
Re : Split IP -
Mr.Momo - 24.11.2011
I must include de sscanf on my script.
I want to make my own ban system because I don't need very much functions.
Thanks.
Re: Re : Split IP -
Steven82 - 24.11.2011
Quote:
Originally Posted by Mr.Momo
I must include de sscanf on my script.
I want to make my own ban system because I don't need very much functions.
Thanks.
|
Just use sscanf. It will be easier for you.