Saving IP with Dini.
#1

So, I'm just touching up my account save system, and adding the IP seemed easy, just using dini_Set. Weelll, when I got done, I looked at my .ini file, and oddly enough, it showed me that my IP variable = the last command I eneted..? Anyways, that doesn't seem logical. I've tried any kind of command, defined or not, it all shows up afterwards.

Here's the parts of the code where it saves the IP:

pawn Код:
enum PlayerStats
{

IP,
pawn Код:
public LoadStats(playerid)
{
    new ip[16], ipstring[16];
    LoggedIN[playerid] = 1;
    format(ipstring, sizeof(ipstring), "%s", GetPlayerIp(playerid,ip,sizeof(ip)));
    Stats[playerid][IP] = dini_Set(playernamefile(playerid),"IP", ipstring);
pawn Код:
public SaveStats(playerid)
{
    if(IsPlayerConnected(playerid) && LoggedIN[playerid] == 1)
    {
        new ip[16], ipstring[16];
        format(ipstring, sizeof(ipstring), "%s", GetPlayerIp(playerid,ip,sizeof(ip)));
        dini_Set(playernamefile(playerid),"IP",ipstring);
pawn Код:
//OnPlayerDisconnect
            new ip[16], ipstring[16];
            format(ipstring, sizeof(ipstring),"%s",GetPlayerIp(playerid, ip, sizeof(ip)));
            dini_Set(playernamefile(playerid),"IP", ipstring);
pawn Код:
//On the register dialog
                    new ip[16], ipstring[16];
                    format(ipstring, sizeof(ipstring),"%s",GetPlayerIp(playerid,ip,sizeof(ip)));
                                        dini_Set(playernamefile(playerid),"IP",ipstring);
pawn Код:
//On the login dialog
                            new ip[16], ipstring[16];
                            format(ipstring, sizeof(ipstring), "%s", GetPlayerIp(playerid,ip,sizeof(ip)));
                            Stats[playerid][IP] = dini_Set(playernamefile(playerid),"IP",ipstring);
And here's my PlayerNameFile stock.

pawn Код:
stock playernamefile(playerid) // Used to return the players file name, eg. Dexter_Morgan.ini
{
    new pName[MAX_PLAYER_NAME],FileName[31]; //  Creating the Variables
    GetPlayerName(playerid, pName,MAX_PLAYER_NAME); // Gets the players name, and stores it to the variable pName
    format(FileName,34,"/Users2/%s.ini", pName); //Formats the FileName string, so that it contains the full file name %s = insert string
    return FileName; // Sends the string, "FileName" back to the function who called it.
}
And that's all. Does anyone see any reason to why it sets my IP account variable to the last command I entered? Thanks in advance.
Reply
#2

The issue is that you're not using the function GetPlayerIp correctly, it doesn't return the IP address as a string. It stores it in the second parameter, for example:

pawn Код:
new ip[16];
GetPlayerIp(playerid, ip, sizeof(ip));
dini_Set(playernamefile(playerid),"IP", ip);
Does that make sense?

In future, check out the documentation for the functions you are using!
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
The issue is that you're not using the function GetPlayerIp correctly, it doesn't return the IP address as a string. It stores it in the second parameter, for example:

pawn Код:
new ip[16];
GetPlayerIp(playerid, ip, sizeof(ip));
dini_Set(playernamefile(playerid),"IP", ip);
Does that make sense?

In future, check out the documentation for the functions you are using!
You sir, are a life saver. I completely didn't realize it until you pointed it out to me. Again, thanks. Any whereabouts on why it sets my ip to 255.255.255.255? I wasn't LAN testing either, uploaded straight to my server.
Reply
#4

You are using GetPlayerIp wrongly.

And why do you need to declare a varable to store player IP again and again?

pawn Код:
enum PlayerStats
{

IP[16],
}

newStats[MAX_PLAYERS][PlayerStats];
pawn Код:
public OnPlayerConnect(playerid)
{
    GetPlayerIp(playerid,Stats[playerid][IP],16);//stores player ip in enum
    return 1;
}
Quote:
Originally Posted by TyThaBomb
Посмотреть сообщение
You sir, are a life saver. I completely didn't realize it until you pointed it out to me. Again, thanks. Any whereabouts on why it sets my ip to 255.255.255.255? I wasn't LAN testing either, uploaded straight to my server.
You must be saving IP when player disconnects.
Reply
#5

Quote:
Originally Posted by TyThaBomb
Посмотреть сообщение
You sir, are a life saver. I completely didn't realize it until you pointed it out to me. Again, thanks. Any whereabouts on why it sets my ip to 255.255.255.255? I wasn't LAN testing either, uploaded straight to my server.
If I recall correctly that happens when you use GetPlayerIp in OnPlayerDisconnect, as the IP is no longer stored by the server and therefore it is invalid.

You should do what the above poster suggested, store the IP when the player connects and make use of it through the globally scoped variable when needed.
Reply
#6

Yes, I apologize, it's 3:30AM over here, kinda half-asleep scripting, just going with the flow hehe. Thanks so much, I appreciate it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)