[HELP] Save IP Address?
#1

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!
Reply
#2

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));
    } 
Reply
#3

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?
Reply
#4

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
Reply
#5

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.
Reply
#6

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.
Reply
#7

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;
}
Reply
#8

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]
Reply
#9

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.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)