Split IP
#1

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)
Reply
#2

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.
pawn Код:
new cip[4][4];
3. Use a ban system implementation similar to the one of Slice's here. It makes scanning for range bans much more simple!
Reply
#3

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.
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)