SA-MP Forums Archive
GetPlayerIp - Getting it with strcmp? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetPlayerIp - Getting it with strcmp? (/showthread.php?tid=149271)



GetPlayerIp - Getting it with strcmp? - Jakku - 21.05.2010

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?


Re: GetPlayerIp - Getting it with strcmp? - DJDhan - 21.05.2010

shouldn't it be Kick(playerid); ?


Re: GetPlayerIp - Getting it with strcmp? - Jakku - 21.05.2010

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.


Re: GetPlayerIp - Getting it with strcmp? - WackoX - 21.05.2010

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);
  }



Re: GetPlayerIp - Getting it with strcmp? - Calgon - 21.05.2010

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 );
    }



Re: GetPlayerIp - Getting it with strcmp? - Zeex - 21.05.2010

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




Re: GetPlayerIp - Getting it with strcmp? - Calgon - 21.05.2010

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.


Re: GetPlayerIp - Getting it with strcmp? - ¤Adas¤ - 21.05.2010

OMG, lames! Freddo was first, who posted working code!


Re: GetPlayerIp - Getting it with strcmp? - Zeex - 21.05.2010

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



Re: GetPlayerIp - Getting it with strcmp? - ¤Adas¤ - 21.05.2010

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