Posts: 1,504
Threads: 109
Joined: Jan 2012
Quote:
Originally Posted by RyDeR`
Info
Just a simple piece of code which you can to detect IP adresses.
It returns true/1 if it detects a ip otherwise false/0.
Code
pawn Код:
stock stringContainsIP(const szStr[]) { new iDots, i ; while(szStr[i] != EOS) { if('0' <= szStr[i] <= '9') { do { if(szStr[i] == '.') iDots++; i++; } while(('0' <= szStr[i] <= '9') || szStr[i] == '.' || szStr[i] == ':'); } if(iDots > 2) return 1; else iDots = 0; i++; } return 0; }
Usage
Block advertisements:
Under OnPlayerText:
pawn Код:
if(stringContainsIP(text)) { new szMsg[128] ; GetPlayerName(playerid, szMsg, MAX_PLAYER_NAME); format(szMsg, sizeof(szMsg), "%s has been banned due advertising!", szMsg); SendClientMessageToAll(0xFF0000FF, szMsg); Ban(playerid); return 0; }
This will ban the player if he writes an IP adress like 78.22.66.22:7777 (doesn't matter which IP)
|
This is pretty old, but just want to point out that using that stock under OnPlayerText has a minor bug.
Try typing three words, the first word with
1 character, the second word with
3 characters, and the last word with
1 character and
a number. If you are sending texts with the playerid, the ID of the player won't be sent. Also if you try printing those 3 words in the console they won't print neither.