GetPlayerIp - Getting it with strcmp?
#1

I have a total blackout in GetPlayerIp. I wrote this:


pawn Код:
new ip[16];
  GetPlayerIp(playerid, ip, sizeof(ip));
  if(!strcmp(ip, "85.76.*.*")) {
  Kick(playerid);
  }

Somehow, it doesn't take effect. Maybe I have a wrong syntax with the IP or something?
Reply
#2

shouldn't it be Kick(playerid); ?
Reply
#3

Quote:
Originally Posted by DJDhan
shouldn't it be Kick(playerid); ?
Sorry, I wrote it wrong to this example. But this ain't my problem.
Reply
#4

pawn Код:
new ip[16];
  GetPlayerIp(playerid, ip, sizeof(ip));
  if(!strcmp(ip, "85.76.*.*")) {
  Kick(playerid);
  }
You cannot use '*' with GetPlayerIp, try this:

pawn Код:
new ip[16];
  GetPlayerIp(playerid, ip, sizeof(ip));
  if(!strcmp(ip, "85.76.", true, strlen(ip))) {
  Kick(playerid);
  }
Reply
#5

Quote:
Originally Posted by Jakku
I have a total blackout in GetPlayerIp. I wrote this:


pawn Код:
new ip[16];
 GetPlayerIp(playerid, ip, sizeof(ip));
 if(!strcmp(ip, "85.76.*.*")) {
 Kick();
 }

Somehow, it doesn't take effect. Maybe I have a wrong syntax with the IP or something?
You can't use wildcards in strcmp().

pawn Код:
new ip[32];
    GetPlayerIp(playerid, ip, sizeof(ip));
    if( strfind( ip, "85.76", true, 0 ) != -1 )
    {
      // They're on the 85.76.*.* range (we're checking the string (ip) from cell 0 to the last cell used in the substring.
        Kick( playerid );
    }
Reply
#6

Try this:

pawn Код:
if (strcmp(ip, "85.76", false, 5) == 0) // 5 means that strcmp compares only first 5 characters which are "85.76"
{
  Kick(playerid);
}
Quote:
Originally Posted by Freddo [BINMAN
]
pawn Код:
new ip[32];
    GetPlayerIp(playerid, ip, sizeof(ip));
    if( strfind( ip, "85.76", true, 0 ) != -1 )
    {
      // They're on the 85.76.*.* range (we're checking the string (ip) from cell 0 to the last cell used in the substring.
        Kick( playerid );
    }
Then *.*.85.76 will also match, and *.85.76.* too

Reply
#7

Quote:
Originally Posted by Zeex
Try this:

pawn Код:
if (strcmp(ip, "85.76", false, 5) == 0) // 5 means that strcmp compares only first 5 characters which are "85.76"
{
 Kick(playerid);
}
Quote:
Originally Posted by Freddo [BINMAN
]
pawn Код:
new ip[32];
    GetPlayerIp(playerid, ip, sizeof(ip));
    if( strfind( ip, "85.76", true, 0 ) != -1 )
    {
      // They're on the 85.76.*.* range (we're checking the string (ip) from cell 0 to the last cell used in the substring.
        Kick( playerid );
    }
Then *.*.85.76 will also match, and *.85.76.* too

Position (optional) The offset to start searching from.

for strfind, it's starting from 0.
Reply
#8

OMG, lames! Freddo was first, who posted working code!
Reply
#9

Quote:
Originally Posted by Freddo [BINMAN
]
Position (optional) The offset to start searching from.

for strfind, it's starting from 0.
And what?

OK, then run this test function if you still don't believe me:

pawn Код:
test()
{
    new ip1[] = "85.76.255.255";
    new ip2[] = "255.85.76.255";
    new ip3[] = "255.255.85.76";

    if (strfind(ip1, "85.76", true, 0) != -1)
        print("ip1 matched");
    if (strfind(ip2, "85.76", true, 0) != -1)
        print("ip2 matched");
    if (strfind(ip3, "85.76", true, 0) != -1)
        print("ip3 matched");
}
the output is:

Код:
[23:32:02] ip1 matched
[23:32:02] ip2 matched
[23:32:02] ip3 matched
Reply
#10

pawn Код:
if(!strcmp(ip, "xxx.xxx.", false, strlen("xxx.xxx."))) print("ok");
This one must work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)