Dialog login doesn't work
#1

pawn Код:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                //if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                if(strlen(inputtext) == PInfo[playerid][Password]) {
                //if(strcmp(inputtext, PInfo[playerid][Password])) {
                    new file[64], password2[23], PlayerName[24];
                    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
                    format(file,sizeof file,"Admin/%s.ini",PlayerName);
                    INI_Open(file);//Opening the file with SII include
                    INI_ReadString(password2,"Password");
                    PInfo[playerid][Registered] = INI_ReadInt("Registered");
                    PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
                    PInfo[playerid][Score] = INI_ReadInt("Score"); // Setting the score of player
                    PInfo[playerid][Money] = INI_ReadInt("Money"); // Setting the money of player
                    PInfo[playerid][Operator] = INI_ReadInt("Operator");
                    INI_Close();//"Closing the file", that means that we're not using it anymore :P
                    SendClientMessage(playerid,-1,"You have been successfully logged in!");
                    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
                    SetPlayerScore(playerid, PInfo[playerid][Score]);
                    GivePlayerMoney(playerid, PInfo[playerid][Money]);
                } else {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER: {
            if (!response) return Kick(playerid);
            if(response) {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register Below","Wrong Password!\nEnter Password To Play!","Register","Quit");
                    new file[64], PlayerName[24];
                    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
                    format(file,sizeof file,"Admin/%s.ini",PlayerName);
                    INI_Open(file);
                    INI_WriteString("Password", inputtext);
                    INI_WriteInt("Registered",1);
                    INI_WriteInt("Level",0);
                    INI_WriteInt("Operator",0);
                    INI_WriteInt("Score",0);
                    INI_WriteInt("Money",15000);
                    INI_Save();
                    INI_Close();
                    SendClientMessage(playerid,-1,"You have successfully registered!");
                    GivePlayerMoney(playerid, 15000); //WHEN YOU LOG OUT IT WILL GET SAVED
                    PInfo[playerid][Logged] = 1;
                    PInfo[playerid][Registered] = 1;
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Success!","Your Account Is Now In Our Database! Thanks For Registering","Ok","");
            }
        }
Alright i have those Dialogs for loging in and regestering i got two problems:

One: When you register everything saves password etc, but when you login again and you enter your password it says its wrong, and when just click "LOGIN" option with no password filled in it works.

Second: When you register everything saves also, but when i like restart the server you have to reregister and your account gets overwriten...

So when i looked up at the Server_Log i also found something weird:


Код:
----------------------
v0.3e-R2, ©2005-2012 SA-MP Team

[18:07:37] password = ""  (string)
[18:07:37] filterscripts = ""  (string)
Reply
#2

Oh nevermind.
Reply
#3

Current Progress

pawn Код:
case DIALOG_LOGIN: {
            if ( !response ) return Kick ( playerid );
            if( response ) {
                //if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                //if(strlen(PInfo[playerid][Password])) {
                new file[64], password2[23], PlayerName[24];
                INI_Open(file);//Opening the file with SII include
                INI_ReadString(password2,"Password");
                if(strlen(password2)) {
                    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
                    format(file,sizeof file,"Admin/%s.ini",PlayerName);
                    PInfo[playerid][Registered] = INI_ReadInt("Registered");
                    PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
                    PInfo[playerid][Score] = INI_ReadInt("Score"); // Setting the score of player
                    PInfo[playerid][Money] = INI_ReadInt("Money"); // Setting the money of player
                    PInfo[playerid][Operator] = INI_ReadInt("Operator");
                    INI_Close();//"Closing the file", that means that we're not using it anymore :P
                    SendClientMessage(playerid,-1,"You have been successfully logged in!");
                    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
                    SetPlayerScore(playerid, PInfo[playerid][Score]);
                    GivePlayerMoney(playerid, PInfo[playerid][Money]);
                } else {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
I managed to get this working now, but now i got the next problem
When you login 3 times like this:

First == register
Second time == Login
Third time == It shows me the register dialog again

pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,-1,"Welcome to United Kingdom TDM! Dont forget to check /updates ! ");
    new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "** %s has joined United Kingdom TDM", name);
    IsOnAdminDuty[playerid] = false;
    SendClientMessageToAll(-1, string);
    PMEnabled[playerid] = 1;

    new file[64],PlayerName[25];//Creating a variable where we can store the file path, and the variable to store the player's name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);//Storing the players name in the PlayerName variable.
    format(file,sizeof file,"Admin/%s.ini",PlayerName);//Storing the file path with the players name.
    if(PInfo[playerid][Registered] == 1) {
        format(file,sizeof file,"Admin/%s.ini",PlayerName);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Below", "Enter Your Password To Login!", "Login", "Quit");
        //ShowPlayerDialog(playerid, 999, DIALOG_STYLE_LIST, "{6EF83C}Choose A Class:", "Soldier Class\nSniper Class\nEngineer Class\nJet-Trooper Class\nPilot Class\nSpy Class", "Choose","");
    } else {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register Below", "Enter A Password To Register And Play!", "Register", "Quit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(PInfo[playerid][Logged] == 1)
    {
        PInfo[playerid][Logged] = 0;
        new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME], file[64];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "** %s has left United Kingdom TDM", name);
        IsOnAdminDuty[playerid] = false;
        SendClientMessageToAll(-1, string);
        format(file, sizeof file, "Admin/%s.ini", name);
        new scores = GetPlayerScore(playerid), //Created extra var to check it.
        money = GetPlayerMoney(playerid);
        INI_Open(file);
        INI_WriteInt("Registered", PInfo[playerid][Registered]);
        INI_WriteInt("Level", PInfo[playerid][Level]);
        INI_WriteInt("Operator", PInfo[playerid][Operator]);
        INI_WriteInt("Score", scores);
        INI_WriteInt("Money", money);
        INI_Save();
        INI_Close();
    }
    return 1;
}
pawn Код:
case DIALOG_REGISTER: {
            if (!response) return Kick(playerid);
            if(response) {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register Below","Wrong Password!\nEnter Password To Play!","Register","Quit");
                    new file[64], PlayerName[24];
                    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
                    format(file,sizeof file,"Admin/%s.ini",PlayerName);
                    INI_Open(file);
                    INI_WriteString("Password", inputtext);
                    INI_WriteInt("Registered",1);
                    INI_WriteInt("Level",0);
                    INI_WriteInt("Operator",0);
                    INI_WriteInt("Score",0);
                    INI_WriteInt("Money",15000);
                    INI_Save();
                    INI_Close();
                    SendClientMessage(playerid,-1,"You have successfully registered!");
                    GivePlayerMoney(playerid, 15000); //WHEN YOU LOG OUT IT WILL GET SAVED
                    PInfo[playerid][Logged] = 1;
                    PInfo[playerid][Registered] = 1;
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Success!","Your Account Is Now In Our Database! Thanks For Registering","Ok","");
            }
        }
Reply
#4

try
pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,-1,"Welcome to United Kingdom TDM! Dont forget to check /updates ! ");
    new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "** %s has joined United Kingdom TDM", name);
    IsOnAdminDuty[playerid] = false;
    SendClientMessageToAll(-1, string);
    PMEnabled[playerid] = 1;

    new file[64],PlayerName[25];//Creating a variable where we can store the file path, and the variable to store the player's name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);//Storing the players name in the PlayerName variable.
    format(file,sizeof file,"Admin/%s.ini",PlayerName);//Storing the file path with the players name.
    if(fexist(file)) {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Below", "Enter Your Password To Login!", "Login", "Quit");
        //ShowPlayerDialog(playerid, 999, DIALOG_STYLE_LIST, "{6EF83C}Choose A Class:", "Soldier Class\nSniper Class\nEngineer Class\nJet-Trooper Class\nPilot Class\nSpy Class", "Choose","");
    } else {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register Below", "Enter A Password To Register And Play!", "Register", "Quit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(PInfo[playerid][Logged] == 1)
    {
        PInfo[playerid][Logged] = 0;
        new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME], file[64];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "** %s has left United Kingdom TDM", name);
        IsOnAdminDuty[playerid] = false;
        SendClientMessageToAll(-1, string);
        format(file, sizeof file, "Admin/%s.ini", name);
        new scores = GetPlayerScore(playerid), //Created extra var to check it.
        money = GetPlayerMoney(playerid);
        INI_Open(file);
        INI_WriteInt("Registered", PInfo[playerid][Registered]);
        INI_WriteInt("Level", PInfo[playerid][Level]);
        INI_WriteInt("Operator", PInfo[playerid][Operator]);
        INI_WriteInt("Score", scores);
        INI_WriteInt("Money", money);
        INI_Save();
        INI_Close();
    }
    return 1;
}
Reply
#5

Thanks, will be trying it. What did you actualy do?

EDIT:: THANKS it works now, but now i came across the problem that you can login with like any password if the password is like "example" you would be able to login with "ex"

pawn Код:
case DIALOG_LOGIN: {
            if ( !response ) return Kick ( playerid );
            if( response ) {
                //if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                //if(strlen(PInfo[playerid][Password])) {
                new file[64], PlayerName[24];
                GetPlayerName(playerid,PlayerName,sizeof PlayerName);
                format(file,sizeof file,"Admin/%s.ini",PlayerName);
                if(strlen(inputtext[PInfo[playerid][Password]])) {
                    INI_Open(file);//Opening the file with SII include
                    INI_ReadString(inputtext[PInfo[playerid][Password]],"Password");
                    PInfo[playerid][Registered] = INI_ReadInt("Registered");
                    PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
                    PInfo[playerid][Score] = INI_ReadInt("Score"); // Setting the score of player
                    PInfo[playerid][Money] = INI_ReadInt("Money"); // Setting the money of player
                    PInfo[playerid][Operator] = INI_ReadInt("Operator");
                    INI_Close();//"Closing the file", that means that we're not using it anymore :P
                    SendClientMessage(playerid,-1,"You have been successfully logged in!");
                    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
                    SetPlayerScore(playerid, PInfo[playerid][Score]);
                    GivePlayerMoney(playerid, PInfo[playerid][Money]);
                } else {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)