ip saving
#1

hello so im saving player ip into database (mysql)
but it is not saving i mean updating
pawn Код:
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `IP`='%s', `Admin`=%d, `Kills`=%d, `Deaths`=%d, `Cookie`=%d,`Notify`=%d, `TotalTime`=%d,`Money`=%d WHERE `ID`=%d",\
    pInfo[playerid][IP],pInfo[playerid][Admin],pInfo[playerid][Kills],pInfo[playerid][Deaths], pInfo[playerid][Cookie],pInfo[playerid][Notify], pInfo[playerid][ConnectTime], pInfo[playerid][Money], pInfo[playerid][ID]);

public OnPlayerConnect(playerid)
{
   GetPlayerIp(playerid, pInfo[playerid][IP], 16); //Getting layer's IP
   return 1;
}
i load them into enum pInfo[playerid][IP]

pInfo[playerid][IP] = cache_get_field_content_int(0,"IP");
Reply
#2

IP is (generally) a string, and must be handled as such. Not every sequence of numbers with dots is classified as a number. If you want to save the IP as a number (e.g. for easier use of the BETWEEN clause) then you can do so by using INET_ATON() and INET_NTOA().

Pawn implementation:
pawn Код:
inet_aton(ip[])
{
    new parts[4];
    sscanf(ip, "p<.>a<i>[4]", parts);
    return (parts[3] << 24 | parts[2] << 16 | parts[1] << 8 | parts[0]);
}
Reply
#3

i just fixed little bit it and now its saving like this " 92.168.1.2" but my ip is "192.168.1.2"
Reply
#4

pawn Код:
GetPlayerIp(playerid, pInfo[playerid][IP], 16);  // pInfo[playerid][IP] is a string ?
pInfo[playerid][IP] = cache_get_field_content_int(0,"IP"); // because, here you store an integer
Reply
#5

Quote:
Originally Posted by Namer
Посмотреть сообщение
i just fixed little bit it and now its saving like this " 92.168.1.2" but my ip is "192.168.1.2"
92.168.1.2 would be your public IP. 192.168.1.2 is a local IP.
Reply
#6

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
pawn Код:
GetPlayerIp(playerid, pInfo[playerid][IP], 16);  // pInfo[playerid][IP] is a string ?
pInfo[playerid][IP] = cache_get_field_content_int(0,"IP"); // because, here you store an integer
Not worked and as
pawn Код:
pInfo[playerid][IP] cache_get_field_content(0, "IP", pInfo[playerid][IP], mysql, 16); // this is savin ip like "92.168.1.2 insteed of 192.168.1.2"
Reply
#7

Is your pInfo[playerid][IP] is even long enough to hold up the IP?
Reply
#8

this is not right Ip[16]; ?
Reply
#9

Quote:
Originally Posted by Namer
Посмотреть сообщение
this is not right Ip[16]; ?
IP[16] is right (15 to be exact, but it doesn't matter that much).

Don't use cache_get_field_content_int, as an IP address is a string and not an int.

Where does it say this wrong IP address? IG or in the database?

Add a debug cmd that shows PlayerInfo[playerid][IP] and use a printf() for your UPDATE query to see what exactly is entered into your database.
Reply
#10



[https://sampforum.blast.hk/showthread.php?tid=485633]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)