Max 8 numbers in one chat.
#1

Hey all. So I have a function which detects if the player is trying to advertise a server, but I want to make it to max 8 numbers only and remove the dots and colons, like only 7 numbers allowed in chat. Here is the function:
pawn Код:
stock IsAnIP(const str[])
{
    new i;
    new colon;
    new dots;
    new numbers;
    new len = strlen(str);
    while (i < len)
    {
        if (str[i] == ':') colon++;
        else if (str[i] == '.') dots++;
        else if (str[i] >= '0' || str[i] <= '9') numbers++;
        i++;
    }
    if (colon > 0 && dots > 2 && numbers > 4) return 1;
    return 0;
}
Thanks for helping.
Reply
#2

Find a way to use this :
pawn Код:
for( new i = 0; i < len; i++)
{
          if(str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' ... to 9 )
          {
              if( count >= 7 )
              {
                   strdel(str, i,i);
                   strins(str, "x", i);
              }
              count++;
          }
}
I think this may work, I hope it works, good luck
Reply
#3

Any other ideas?
Reply
#4

Did it work or not ?b
Reply
#5

Bump. I made something, but the problem is, when it detects 8 characters, any of them, it says advertising. Here is the script. Can someone make it with numbers only?
pawn Код:
stock IsAnIP(const str[])
{
    new i;
    new numbers;
    new len = strlen(str);
    while (i < len)
    {
        if (str[i] >= '0' || str[i] <= '9') numbers++;
        i++;
    }
    if (numbers > 7) return 1;
    return 0;
}
Reply
#6

Dude, did what I gave work or not
Reply
#7

Quote:
Originally Posted by Necip
Посмотреть сообщение
Bump. I made something, but the problem is, when it detects 8 characters, any of them, it says advertising. Here is the script. Can someone make it with numbers only?
pawn Код:
stock IsAnIP(const str[])
{
    new i;
    new numbers;
    new len = strlen(str);
    while (i < len)
    {
        if (str[i] >= '0' || str[i] <= '9') numbers++;
        i++;
    }
    if (numbers > 7) return 1;
    return 0;
}
there's just one small mistake you've made
instead of using OR, you have to use AND
cuz that control structure should only result in true when the char is within the range you defined by '0' and '9'
c++ example checking for uppercase chars and replacing them with lower case ones:
Код:
void strKlein(char *c)
{
	for (short i = 0; c[i] != '\0'; i++)
		c[i] = (c[i] > 64 && c[i] < 91) ? (c[i]+32) : (c[i]);
}
replace this line
Код:
if (str[i] >= '0' || str[i] <= '9') numbers++;
with this
Код:
if (str[i] >= '0' && str[i] <= '9') numbers++;
and it'll be fine
Reply
#8

That looks just like my old "IsAnIP" function that I made about ~3 years ago .

Try this, using sscanf:

pawn Код:
stock IsAnIP(ip[])
{
    static
        num[4];

    if (sscanf(ip, "p<.>dddd", num[0], num[1], num[2], num[3]))
    {
        return 0;
    }
    return 1;
}
Reply
#9

Use regex.
Reply
#10

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
Use regex.
Actually - I exactly did that, and almost replied - but I tried compiling the code, and it returned "invalid character constant."

I tried other regex methods however they were not as accurate.

Could you mind posting one that compiles?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)