SA-MP Forums Archive
MySQL Aka System - 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)
+--- Thread: MySQL Aka System (/showthread.php?tid=615745)



MySQL Aka System - sampkinq - 26.08.2016

Hi, How do I withdraw IP address of the player's names ?
MySQL Version: R39-5



Re: MySQL Aka System - justjamie - 26.08.2016

new ip[25]; GetPlayerIp(playerid, ip, 25);

no need for mysql lol.
no problem


Re: MySQL Aka System - DarkSkull - 26.08.2016

https://sampwiki.blast.hk/wiki/GetPlayerIp


Re: MySQL Aka System - Stinged - 26.08.2016

If you want to get a player's IP:

Код:
SELECT `IP` FROM `users` WHERE `Name` = '%e'
NOTE: Everything in red can be different (depending on your table)

If you want to get all the names that share a certain IP:

Код:
SELECT `Name` FROM `users` WHERE `IP` = '%s'



Re: MySQL Aka System - sampkinq - 26.08.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
If you want to get a player's IP:

Код:
SELECT `IP` FROM `users` WHERE `Name` = '%e'
NOTE: Everything in red can be different (depending on your table)

If you want to get all the names that share a certain IP:

Код:
SELECT `Name` FROM `users` WHERE `IP` = '%s'
All the names of the user, How do I withdraw ?

Код:
CMD:aka(playerid,params[])
{
new isim[24];
if(sscanf(params, "s[24]", isim)) return SendClientMessage(playerid, -1, "{D324FF}Kullanım: {FFFFFF}/Aka (IP)");
new query[128];
mysql_format(g_SQL, query, sizeof(query), "SELECT `Isim` FROM `oyuncudata` WHERE `IPAdress` = '%s'", isim);
mysql_tquery(g_SQL, query, "AkaCek", "ds", playerid,isim);
return 1;
}

function:AkaCek(playerid, ip_adress[])
{
	new rows, fields;
	cache_get_data(rows, fields);
	if(rows)
	{
    	 for(new i = 0; i < rows; ++i)
	    {
			new isim[24];
			cache_get_field_content(i, "Isim", isim);
			printf("%s\n",isim);
	    }
	}
	else
	{
	SendClientMessage(playerid, ERROR_COLOR_HD, "yok.");
	}
return 1;
}



Re: MySQL Aka System - Gammix - 26.08.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
If you want to get a player's IP:

Код:
SELECT `IP` FROM `users` WHERE `Name` = '%e'
NOTE: Everything in red can be different (depending on your table)

If you want to get all the names that share a certain IP:

Код:
SELECT `Name` FROM `users` WHERE `IP` = '%s'
I would recommend a subnet cum CIDR check which i implemented in GAdmin and also you can use IpMatch function:
pawn Код:
static GetIPVal(const ip[])
{
    new len = strlen(ip);
    if (!(len > 0 && len < 17))
        return 0;

    new count;
    for (new i; i < len; i++)
    {
        if (ip[i] == '.')
            count++;
    }

    if (!(count == 3))
        return 0;

    new address = strval(ip) << 24;
    count = strfind(ip, ".", false, 0) + 1;
    address += strval(ip[count]) << 16;
    count = strfind(ip, ".", false, count) + 1;
    address += strval(ip[count]) << 8;
    count = strfind(ip, ".", false, count) + 1;
    address += strval(ip[count]);
    return address;
}

stock IpMatch(const ip1[], const ip2[], rangetype = 26)
{
    new ip = GetIPVal(ip1);
    new subnet = GetIPVal(ip2);

    new mask = -1 << (32 - rangetype);
    subnet &= mask;

    return bool:((ip & mask) == subnet);
}
In this case you have to loop through all rows:
pawn Код:
SELECT * FROM `Users`
When the data load, use cache_get_field_content to retrieve a row's IP (new rowip[18]).
And then compare with player's ip (new pip[18]):
pawn Код:
if (IpMatch(rowip, pip))
{
    // player matched
}



Re: MySQL Aka System - Stinged - 26.08.2016

Quote:
Originally Posted by Gammix
Посмотреть сообщение
I would recommend a subnet cum CIDR check which i implemented in GAdmin and also you can use IpMatch function:
pawn Код:
static GetIPVal(const ip[])
{
    new len = strlen(ip);
    if (!(len > 0 && len < 17))
        return 0;

    new count;
    for (new i; i < len; i++)
    {
        if (ip[i] == '.')
            count++;
    }

    if (!(count == 3))
        return 0;

    new address = strval(ip) << 24;
    count = strfind(ip, ".", false, 0) + 1;
    address += strval(ip[count]) << 16;
    count = strfind(ip, ".", false, count) + 1;
    address += strval(ip[count]) << 8;
    count = strfind(ip, ".", false, count) + 1;
    address += strval(ip[count]);
    return address;
}

stock IpMatch(const ip1[], const ip2[], rangetype = 26)
{
    new ip = GetIPVal(ip1);
    new subnet = GetIPVal(ip2);

    new mask = -1 << (32 - rangetype);
    subnet &= mask;

    return bool:((ip & mask) == subnet);
}
In this case you have to loop through all rows:
pawn Код:
SELECT * FROM `Users`
When the data load, use cache_get_field_content to retrieve a row's IP (new rowip[18]).
And then compare with player's ip (new pip[18]):
pawn Код:
if (IpMatch(rowip, pip))
{
    // player matched
}
I'll search later on my PC if there's any other way to do that without looping through all rows.

But why do you use that awful way of converting an IP to decimal?
You can do something like this (Might have some indentation mistakes cause I'm on my phone)

Код:
GetIPVal(const ip[])
{
    new ip1, ip2, ip3, ip4;
    if (sscanf(ip, "p<.>iiii", ip1, ip2, ip3, ip4))
        return 0;

    if (!(0 <= ip1 <= 255) || !(0 <= ip2 <= 255) || !(0 <= ip3 <= 255) || !(0 <= ip4 <= 255))
        return 0;

    return ip1*16777216 + ip2*65536 + ip3*256 + ip4;
}



Re: MySQL Aka System - Gammix - 26.08.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
I'll search later on my PC if there's any other way to do that without looping through all rows.

But why do you use that awful way of converting an IP to decimal?
You can do something like this (Might have some indentation mistakes cause I'm on my phone)

Код:
GetIPVal(const ip[])
{
    new ip1, ip2, ip3, ip4;
    if (sscanf(ip, "p<.>iiii", ip1, ip2, ip3, ip4))
        return 0;

    return ip1*16777216 + ip2*65536 + ip3*256 + ip4;
}
For the matter of fact, i am not the original mentor of GetIPVal. And i didn't care enough to look or try to change the code of R@f!

EDIT: Without sscanf version:
pawn Код:
static GetIPVal(const ip[])
{
    new len = strlen(ip);
    if (!(len > 0 && len < 17))
        return 0;

    new count;
    new pos;
    new dest[3];
    new val[4];
    for (new i; i < len; i++)
    {
        if (ip[i] == '.' || i == len)
        {
            strmid(dest, ip, pos, i);
            pos = (i + 1);
       
            val[count] = strval(dest);
            if (!(1 <= val[count] <= 255))
                return 0;
               
            count++;
            if (count > 3)
                return 0;
        }
    }
   
    if (count != 3)
        return 0;

    return ((val[0] * 16777216) + (val[1] * 65536) + (val[2] * 256) + (val[3]));
}

stock IpMatch(const ip1[], const ip2[], rangetype = 26)
{
    new ip = GetIPVal(ip1);
    new subnet = GetIPVal(ip2);

    new mask = -1 << (32 - rangetype);
    subnet &= mask;

    return bool:((ip & mask) == subnet);
}