Quote:
Originally Posted by vvhy
Stock function that will find if a string contains an IP address. Useful for anti advertising.
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; }
Example:
pawn Code:
public OnPlayerText(playerid, text[]) { if(ContainsIP(text)) { BanEx(playerid,"Advertising"); return 0; } return 0; }
|
A more proper name for that function is
IsServerAdvertisement or something along those lines.