Server Don't load Stats, easy help!
#1

Hey guys, my system save stats but when login don't load it... It allways show me you are already logged, but i have when player disconect a code to set logged to 0... Here's the code, please see what is bad
THANKS GUYS!

pawn Код:
#include <a_samp>
#include <dini>
#include <dudb>
#include <zcmd>
#include <sscanf>

#pragma unused ret_memcpy

new IsLogged[MAX_PLAYERS];
new gLogged[MAX_PLAYERS];
new gRegistred[MAX_PLAYERS];
new file[256];

enum pInfo
{
    AdminLevel,
    Cash,
    Score,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

COMMAND:register(playerid, params[])
{
    new tmp[256];
    new name[MAX_PLAYER_NAME];
    new id;
    GetPlayerName(playerid, name, sizeof(name));
    if(!sscanf(params, "u", id))
    {
            format(file,sizeof(file),"/RicAdmin/users/%s.ini",name);
            if(!fexist(file))
            {
                dini_Create(file);
                dini_IntSet(file,"Password", udb_hash(tmp));
                dini_IntSet(file,"AdminLevel", 0);
                dini_IntSet(file,"Cash", 0);
                dini_IntSet(file,"Score", 0);
                SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Created!");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                GetPlayerName(playerid, name, sizeof(name));
                printf("%s has registered a account!", name);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFFFFFFFF, " Account Already Found In Database");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                return 1;
            }
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /register [password]");
}

COMMAND:login(playerid, params[])
{
    new tmp[256], tmp2[256];
    new id;
    new PlayerName[24];
    if(!sscanf(params, "u", id))
    {
        new name[MAX_PLAYER_NAME];
        if(IsLogged[playerid] == 1)
        {

                GetPlayerName(playerid, name, sizeof(name));
                format(file,sizeof(file),"/RicAdmin/users/%s.ini",name);
                if(fexist(file))
                {
                    tmp2 = dini_Get(file, "Password");
                    if(udb_hash(tmp) != strval(tmp2))
                    {
                        SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!");
                        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
                        printf("%s has failed to login", name);
                        IsLogged[playerid] = 1;
                        SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                        SetPlayerMoney(playerid, dini_Int(file, "Score"));
                        PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
                        SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!");
                       
                    }
                }
           
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "You already are logged in!");
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /login [password]");
    return 1;
}
public OnPlayerDisconnect(playerid)
{
    new name[24];
    GetPlayerName(playerid,name,24);
    format(file,sizeof(file),"RicAdmin/users/%s.ini",name);
    if(dini_Exists(file))
    {
        dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
        dini_IntSet(file,"Score",GetPlayerScore(playerid));
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][AdminLevel]);
        IsLogged[playerid] = 0;
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}
public OnPlayerConnect(playerid)
{
    if(gLogged[playerid] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Use /login to login into your account!");
        return 1;
    }
    if(gRegistred[playerid] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Use /register to register your account!");
        return 1;
    }
    return 1;
}
Reply
#2

This if statement doesn't make any sense?

pawn Код:
if(udb_hash(tmp) != strval(tmp2))
You're using that to see if the login information is wrong, and if it is wrong, you are logging them in!

Additionally this if statement makes no sense either:

pawn Код:
if(IsLogged[playerid] == 1)
You are only allowing them to login if they are already logged in, so you should be checking if IsLogged is 0, not if it's 1! (All of this code came from the login command)
Reply
#3

Hum... And what is the soluction? Plz, give me this help.... The work i gonna do will be posted in forums, and if you see my works, tha last's have credits for forum members

This is my first time working with dini and i needed to convert the cmds from a tut to zcmd..
Reply
#4

I explained the solution in my post, read it.
Reply
#5

I did, i changed the
pawn Код:
if(IsLogged[playerid] == 1)
to
pawn Код:
if(IsLogged[playerid] == 0)
But then the cmd just don't work... I type /login it show the form, i type /login password and it don't show nothing...
Reply
#6

Quote:
Originally Posted by ricardo178
Посмотреть сообщение
I did, i changed the
pawn Код:
if(IsLogged[playerid] == 1)
to
pawn Код:
if(IsLogged[playerid] == 0)
But then the cmd just don't work... I type /login it show the form, i type /login password and it don't show nothing...
Again like I said, what about the other if statement? Where you only perform the login procedure when the person enters in the password incorrectly....so did you try writing the wrong password? It should work then according to your code.

Instead of checking if the passwords are different and then logging them in, why not check if they are the same and then log them in?

pawn Код:
if(udb_hash(tmp) == strval(tmp2))
!= means not equal to and == means equal to, remember that!
Reply
#7

Thanks, now it work and don't work...
I type login password and it show login sucegfull and login failed(right, first failed and after show sucefull)
And in files it is saved 10k money and 100 score and it load 0 score and 100 money....
The code it now like this:

pawn Код:
#include <a_samp>
#include <dini>
#include <dudb>
#include <zcmd>
#include <sscanf>

#pragma unused ret_memcpy

new IsLogged[MAX_PLAYERS];
new gLogged[MAX_PLAYERS];
new gRegistred[MAX_PLAYERS];
new file[256];

enum pInfo
{
    AdminLevel,
    Cash,
    Score,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

COMMAND:register(playerid, params[])
{
    new tmp[256];
    new name[MAX_PLAYER_NAME];
    new id;
    GetPlayerName(playerid, name, sizeof(name));
    if(!sscanf(params, "u", id))
    {
            format(file,sizeof(file),"/RicAdmin/users/%s.ini",name);
            if(!fexist(file))
            {
                dini_Create(file);
                dini_IntSet(file,"Password", udb_hash(tmp));
                dini_IntSet(file,"AdminLevel", 0);
                dini_IntSet(file,"Cash", 0);
                dini_IntSet(file,"Score", 0);
                SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Created!");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                GetPlayerName(playerid, name, sizeof(name));
                printf("%s has registered a account!", name);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFFFFFFFF, " Account Already Found In Database");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                return 1;
            }
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /register [password]");
}

COMMAND:login(playerid, params[])
{
    new tmp[256], tmp2[256];
    new id;
    new PlayerName[24];
    if(!sscanf(params, "u", id))
    {
        new name[MAX_PLAYER_NAME];
        if(IsLogged[playerid] == 0)
        {

                GetPlayerName(playerid, name, sizeof(name));
                format(file,sizeof(file),"/RicAdmin/users/%s.ini",name);
                if(fexist(file))
                {
                    tmp2 = dini_Get(file, "Password");
                    if(udb_hash(tmp) == strval(tmp2))
                    {
                        SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!");
                        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
                        printf("%s has failed to login", name);
                        IsLogged[playerid] = 1;
                        SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                        SetPlayerMoney(playerid, dini_Int(file, "Score"));
                        PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
                        SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!");
                       
                    }
                }
           
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "You already are logged in!");
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /login [password]");
    return 1;
}
public OnPlayerDisconnect(playerid)
{
    new name[24];
    GetPlayerName(playerid,name,24);
    format(file,sizeof(file),"RicAdmin/users/%s.ini",name);
    if(dini_Exists(file))
    {
        dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
        dini_IntSet(file,"Score",GetPlayerScore(playerid));
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][AdminLevel]);
        IsLogged[playerid] = 0;
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}
public OnPlayerConnect(playerid)
{
    if(gLogged[playerid] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Use /login to login into your account!");
        return 1;
    }
    if(gRegistred[playerid] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Use /register to register your account!");
        return 1;
    }
    return 1;
}
THANKS
Reply
#8

Okay, lets try looking at it together, because these problems aren't that complex, it shouldn't be that hard to debunk it on your own. So I'm going to help you along, lets look at your problem code, step by step.

pawn Код:
if(udb_hash(tmp) == strval(tmp2)) // The passwords matched...so now do the code in the brackets
{
    SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!"); // The login was successful, why do you send them a message saying it failed?
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));  // Get the name and store it in a variable
    printf("%s has failed to login", name); // Again, printing that he failed to login, when he didn't?
    IsLogged[playerid] = 1; // Setting the IsLogged variable to 1
    SetPlayerMoney(playerid, dini_Int(file, "Cash")); // Setting the players money to the value of Cash in the file
    SetPlayerMoney(playerid, dini_Int(file, "Score")); // You're setting the money of the person to the value of score in the file, why? Shouldn't you be using SetPlayerScore?
    PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel"); // Setting the variable to the value of AdminLevel in the file
    SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!"); // Telling the player that he logged in!                    
}
Read the comments I put in the code. You should be able to do simple debugging like this on your own! Just look through your code, and try to understand where the problematic parts are, take it step by step and use some algoritihmic problem solving.
Reply
#9

WOW, Thanks man, now it login good, load all right, only have 1 litle problem It login even with right or wrong password...

Could i put an other if?
pawn Код:
if(udb_hash(tmp) != strval(tmp2))
You make me understund this better! Really thanks. The great think on this forum is: You help and be helped when needed!
Reply
#10

Okay, so what you should do in this situation is just use an else statement on top of the if statement that checks if the passwords were the same or not, so that will then mean the information must not have matched, so the login must be wrong, for example:

pawn Код:
if(udb_hash(tmp) == strval(tmp2)) // The passwords matched...so now do the code in the brackets
{
    SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!"); // The login was successful, why do you send them a message saying it failed?
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));  // Get the name and store it in a variable
    printf("%s has failed to login", name); // Again, printing that he failed to login, when he didn't?
    IsLogged[playerid] = 1; // Setting the IsLogged variable to 1
    SetPlayerMoney(playerid, dini_Int(file, "Cash")); // Setting the players money to the value of Cash in the file
    SetPlayerMoney(playerid, dini_Int(file, "Score")); // You're setting the money of the person to the value of score in the file, why? Shouldn't you be using SetPlayerScore?
    PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel"); // Setting the variable to the value of AdminLevel in the file
    SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!"); // Telling the player that he logged in!                    
}
else // The passwords didn't match in the "if(udb_hash(tmp) == strval(tmp2))" statement!
{
    SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Passwords did not match!");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)