[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(playerid, ip, sizeof(ip));
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(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(playerid, name, sizeof(name));
format(file, sizeof(file), "%s.ini", udb_encode(name));
if(dini_Exists(file))
{
strcpy(ip, dini_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(playerid, ip, sizeof(ip));
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(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(playerid, name, sizeof(name));
format(file, sizeof(file), "%s.ini", udb_encode(name));
if(dini_Exists(file))
{
strcpy(ip, dini_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(playerid, reason)
{
new __ip[16];
GetPVarString(playerid, "IP" __ip, sizeof(__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(playerid, reason)
{
new __ip[16];
GetPVarString(playerid, "IP" __ip, sizeof(__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