06.09.2014, 18:07
Although I have been developing the same gamemode since 2007, I am actually terrible at maths. This has got me stumped. I need to check if a string contains an IP address. How would I do this? I have found the following:
Should I use that, or does anyone have a better method?
pawn Code:
#define MAX_NUM 10
#define MY_SERVER_IP "255.255.255.255:7777"
stock ContainsIP(const string[])
{
new num[MAX_NUM][128];
new numpos[MAX_NUM];
new dotcount,i;
if(strfind(string,MY_SERVER_IP)!=-1)return 0;
for(new npos=0;npos<=MAX_NUM;npos++)
{
new c;
for(c=0;i<strlen(string);i++)
{
new ch = string[i];
if((string[i] == '.' || string[i] == ':') && ((i>0 && '0' <= string[i-1] <= '9') || (i>1 && '0' <= string[i-2] <= '9') ))
{
dotcount++;
i++;
break;
}
if ((npos==0 || i - numpos[npos - 1] < strlen(num[npos-1])+4) && '0' <= ch <= '9' || (c == 0 && ch == '-'))
{
num[npos][c] = string[i];
numpos[npos] = i;
c++;
}
}
}
new found=0;
for(new npos=0;npos<MAX_NUM;npos++)
{
if( strlen(num[npos]) > 0 && 0 < strval(num[npos]) <= 225)
{
found++;
}
}
if(found >= 3 && dotcount >= 3)return 1;
return 0;
}