SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/02/2020, 08:22 PM   #1
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 816
Reputation: 68
Default ReturnIP issue

Hello i have this function to retrieve player's IP:

pawn Code:
stock ReturnIP(playerid)
{
    new ip[30];
    GetPlayerIp(playerid, ip, sizeof(ip));
    return ip;
}

There is an issue tho, it works and it doesn't. I mean, if i place it in a command like /getip, it works, IP is displayed correctly.

But if i save last login IP on database, it returns 255.255.255.0 almost everytime. I tried using just the normal GetPlayerIP but got same result.

This is the LastLoginIP row in database:

Code:
`LastLoginIP` varchar(33) NOT NULL
When saving:
pawn Code:
`LastLoginIP` = '%s'
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 16/02/2020, 08:26 PM   #2
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,528
Reputation: 1642
Default Re: ReturnIP issue

Did you use it under OnPlayerDisconnect? If so, the IP is not available under that callback because the player is already disconnected at that point. Try using it elsewhere (eg. save the IP when a player logs in). Or save the IP to a variable when they connect.
If that's not the case (I assume it is, because I'm assuming it saves data under OnPlayerDisconnect, retrieving the IP in the saving query), it is pretty odd. Try using NetStats_GetIpPort..

What is also odd is that it seems to be the subnet mask. GetPlayerIp should return 255.255.255.255 if the player is not connected.

Also, the maximum IP length is xxx.xxx.xxx.xxx, which is 15 characters (3 + 4*3). Null terminator included, an array size of 16 cells would be enough.
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Old 16/02/2020, 08:29 PM   #3
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 816
Reputation: 68
Default Re: ReturnIP issue

Yes i use it on OnPlayerDisconnect to - as the name says - save the last login IP. Would be that the issue? And yes, i have normalized the cells size and reduced to 16.
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 16/02/2020, 08:42 PM   #4
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,528
Reputation: 1642
Default Re: ReturnIP issue

I am very sure that that is the issue.
Since it's the "Last Login IP", altering that data when the player logs in is more logical.

EDIT:
https://wiki.sa-mp.com/wiki/GetPlayerIp
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Old 16/02/2020, 09:06 PM   #5
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 816
Reputation: 68
Default Re: ReturnIP issue

Quote:
This function does not work when used in OnPlayerDisconnect because the player is already disconnected. It will return an invalid IP (255.255.255.255). Save players' IPs under OnPlayerConnect if they need to be used under OnPlayerDisconnect.
Fixed with this simple query after player has logged in:

pawn Code:
new upIP[120];
mysql_format(g_SQL, upIP,sizeof(upIP), "UPDATE `players` SET `LastLoginIP` = '%s' WHERE `ID` = %d LIMIT 1", ReturnIP(playerid), ReturnAccDbID(playerid));
mysql_query(g_SQL, upIP);

Thanks for the help.
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is offline   Reply With Quote
Old 17/02/2020, 08:37 AM   #6
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,528
Reputation: 1642
Default Re: ReturnIP issue

LIMIT is unnecessary tho. Assuming ID is either AUTO_INCREMENT or UNIQUE there cannot be two or more rows with the same value in the ID column.

If it is possible then LIMIT could be usefull but you'd need other checks, as it may update the wrong user. But that is quite unlikely.
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Old 17/02/2020, 09:31 AM   #7
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,044
Reputation: 172
Default Re: ReturnIP issue

May I suggest you two miscellaneous functions:

IP (as text) to integer: https://dev.mysql.com/doc/refman/8.0...tion_inet-aton
IP (as integer) to text: https://dev.mysql.com/doc/refman/8.0...tion_inet-ntoa

Faster for comparing and takes less storage space.
__________________
Calisthenics is offline   Reply With Quote
Old 18/02/2020, 08:27 AM   #8
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,528
Reputation: 1642
Default Re: ReturnIP issue

You may. Knowledge is well received
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a_zones issue still (Compile issue) Oldyman Scripting Help 3 10/06/2015 01:08 PM
Mouse Issue (Not The Freezing Issue) CovertCrayon Client Support 5 07/11/2013 08:11 PM
Unoccupied vehicle sync, boat surfing pausing issue, parachute with vehicle issue, surfing w/ skydiving issue Kar Bug Reports 2 10/06/2013 09:24 AM
Issue with TMP MrBorsh Scripting Help 4 24/03/2012 05:29 PM
[help] I HAve An Very Small Issue [not Error] Issue HayZatic Help Archive 1 06/07/2011 04:33 AM


All times are GMT. The time now is 11:07 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.