Wrong IP
#1

I'm using the last (R34) BlueG's( or by the current developer maddinat0r) mysql plugin, I'm not even sure if the problems is from the mysql part, but I'm trying to save player's IP when player leaves. The problem is that everybody's IP goes 255.255.255.255. There is part of my code:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{

if(Logged[playerid] == 1)
{
new query[512];
format(query, sizeof(query), "UPDATE players SET IP = '%s' WHERE Name = '%s'", GetIP(playerid), GetPName(playerid));
mysql_function_query(IMDb, query, false, "", "");
}
return 1;
}

stock GetPName(playerid)
{
    GetPlayerName(playerid,gName,sizeof gName);
    return gName;
}

stock GetIP(playerid)
{
    new gIP[16];
    GetPlayerIp(playerid, gIP, sizeof gIP);
    return gIP;
}
I know that getting IP wasn't working either on the onplayerconnect or onplayerdisconnect callback, but I don't remember which one. So what is the solution there ?
Thanks in advance.
Reply
#2

Store the player's IP at OnPlayerConnect(), and use it in OnPlayerDisconnect().
Reply
#3

pawn Код:
new
    Player_Ip[ MAX_PLAYERS ][ 16 ]
;

// OnPlayerConnect:
GetPlayerIp( playerid, Player_Ip[ playerid ], 16 );

// Anywhere else you want to use the IP (such as passing it as an argument to format):
Player_Ip[ playerid ]
Everytime I used to get the IP at localhost, 255.255.255.255 was returned. I fixed the problem by getting the IP only ONCE and using it then
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
new
    Player_Ip[ MAX_PLAYERS ][ 16 ]
;

// OnPlayerConnect:
GetPlayerIp( playerid, Player_Ip[ playerid ], 16 );

// Anywhere else you want to use the IP (such as passing it as an argument to format):
Player_Ip[ playerid ]
Everytime I used to get the IP at localhost, 255.255.255.255 was returned. I fixed the problem by getting the IP only ONCE and using it then
Still 255.255.255.255, I used to get the IP when I connected and I sent an UPDATE query when I logged in (where I use to load player stats).
EDIT: I deleted my user account and the IP field is empty.
Reply
#5

What happens if you SendClientMessage the query, does it show IP = '255.255.255.255' or does it show the correct IP?

What field type are you using to store the IP in your table?
Reply
#6

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
What happens if you SendClientMessage the query, does it show IP = '255.255.255.255' or does it show the correct IP?

What field type are you using to store the IP in your table?
I will use to debug the query and I will tell you the result, it's varchar(16) with collation latin_swedish_ci (if it even matters).
EDIT: the size of the query wasnt big enough (64) and I made it 128 so it works now, thank you both.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)