SA-MP Forums Archive
[HELP] Save IP Address? - 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: [HELP] Save IP Address? (/showthread.php?tid=250050)



[HELP] Save IP Address? - Fredden1993 - 21.04.2011

Is there a good way to save a player's IP Address when creating an account? I'm using a Dini register system by the way.

Thanks for the help!


Re: [HELP] Save IP Address? - Sinner - 21.04.2011

To set:
PHP код:
    new ip[12], file[64], name[24];
    
GetPlayerIp(playeridipsizeof(ip));
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "%s.ini"udb_encode(name));
    if(!
dini_Exists(file)) dini_Create(file);
    
dini_Set(file"ip"ip); 
To get:
PHP код:
    new ip[12], file[64], name[24];
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "%s.ini"udb_encode(name));
    if(
dini_Exists(file))
    {
        
strcpy(ipdini_Get(file"ip"ip));
    } 



Re: [HELP] Save IP Address? - Fredden1993 - 21.04.2011

Quote:
Originally Posted by Sinner
Посмотреть сообщение
To set:
PHP код:
    new ip[12], file[64], name[24];
    
GetPlayerIp(playeridipsizeof(ip));
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "%s.ini"udb_encode(name));
    if(!
dini_Exists(file)) dini_Create(file);
    
dini_Set(file"ip"ip); 
To get:
PHP код:
    new ip[12], file[64], name[24];
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "%s.ini"udb_encode(name));
    if(
dini_Exists(file))
    {
        
strcpy(ipdini_Get(file"ip"ip));
    } 
When I did this the IP Address only says "255.255.255." What's up with that?


Re: [HELP] Save IP Address? - Sinner - 21.04.2011

Quote:
Originally Posted by Fredden1993
Посмотреть сообщение
When I did this the IP Address only says "255.255.255." What's up with that?
How did you do it? I think getting an IP in the OnPlayerdisconnect() callback will always return 255.255.255


Re: [HELP] Save IP Address? - [NoV]LaZ - 21.04.2011

Quote:
Originally Posted by Sinner
Посмотреть сообщение
How did you do it? I think getting an IP in the OnPlayerdisconnect() callback will always return 255.255.255
He said "when creating an account", not when he's leaving.


Re: [HELP] Save IP Address? - Sinner - 21.04.2011

Quote:
Originally Posted by [NoV]LaZ
Посмотреть сообщение
He said "when creating an account", not when he's leaving.
Should work fine then?

If you are running your server locally, though, your IP will always be 127.0.0.1, I don't know if its 255.255.255 for some people so that might be the reason.


Re: [HELP] Save IP Address? - [NoV]LaZ - 21.04.2011

I'm more than sure he's saving the IP in OnPlayerDisconnect. A solution to this bug is to save the IP upon player connecting.
pawn Код:
new pIP[16]; // Global variable

public OnPlayerConnect(playerid)
{
    GetPlayerIp(playerid, pIP, sizeof (pIP));
    SetPVarString(playerid, "IP", pIP, sizeof (pIP));

   return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new ip[16];
    GetPVarString(playerid), "IP", ip, sizeof (ip)
    printf("playerid %d disconnected, and his IP was %s", playerid, ip);

    return 1;
}



Re: [HELP] Save IP Address? - Sinner - 21.04.2011

Quote:
Originally Posted by [NoV]LaZ
Посмотреть сообщение
I'm more than sure he's saving the IP in OnPlayerDisconnect. A solution to this bug is to save the IP upon player connecting.
pawn Код:
new pIP[16]; // Global variable

public OnPlayerConnect(playerid)
{
    GetPlayerIp(playerid, pIP, sizeof (pIP));
    SetPVarString(playerid, "IP", pIP, sizeof (pIP));

   return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    printf("playerid %d disconnected, and his IP was %s", playerid, GetPVarString(playerid), "IP", pIP, sizeof (pIP));

    return 1;
}
That's not how GetPVarString() should be used lol

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
__ip[16];
    
GetPVarString(playerid"IP" __ipsizeof(__ip));
    
printf("playerid %d disconnected, and his IP was %s"playerid__ip);
    return 
1;

[/troll]


Re: [HELP] Save IP Address? - [NoV]LaZ - 21.04.2011

Quote:
Originally Posted by Sinner
Посмотреть сообщение
That's not how GetPVarString() should be used lol

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
__ip[16];
    
GetPVarString(playerid"IP" __ipsizeof(__ip));
    
printf("playerid %d disconnected, and his IP was %s"playerid__ip);
    return 
1;

[/troll]
Yeah, my bad.


Re: [HELP] Save IP Address? - Fredden1993 - 21.04.2011

I got it to work, I odn't know what error I did but it's saving the IP Address now anyway. Thanks for your support guys and girls