SA-MP Forums Archive
Register/Login system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Register/Login system (/showthread.php?tid=413449)



Register/Login system - MechaTech - 05.02.2013

I've been looking for a Register/Login system and I found one. Everything is in my gamemode and went testing.
But the problem is: It creates the User file, but it doesn't write anything in it.



This is the Login/Register system:

pawn Код:
#include <YSI\y_ini>
pawn Код:
#define DIALOG_REGISTER     261
#define DIALOG_LOGIN        272
#define USERS               "Users/%s.ini"
native WP_Hash(buffer[],len,const str[]);

enum PlayerInfo
{
    Pass[129],
    Money,
    Scores,
    Kills,
    Deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

forward LoadUser_data(playerid, name[], value[]);
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","{FFFFFF}Welcome back. This account is {00FF00}registered. \n{FFFFFF}Insert your password to login to your account","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Register","{FFFFFF}Welcome! This account is {FF0000}not registered.\n{FFFFFF}Enter your own password to create a new account.","Register","Quit");
    }
// There is some codes underneath here.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(fexist(UserPath(playerid)))
    {
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
        INI_WriteInt(File,"Scores",GetPlayerScore(playerid));
        INI_WriteInt(File,"Kills",pInfo[playerid][Kills]);
        INI_WriteInt(File,"Deaths",pInfo[playerid][Deaths]);
        INI_Close(File);
    }
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_REGISTER)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(!strlen(inputtext))
            {
                ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","You have entered an {FF0000}invalid password.\n{FFFFFF}Enter your own password to create a new account!","Register","Quit");
                return 1;
            }
            new hashpass[129];
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            new INI:File = INI_Open(UserPath(playerid));
            INI_SetTag(File,"data");
            INI_WriteString(File,"Password",hashpass);
            INI_WriteInt(File,"Money",0);
            INI_WriteInt(File,"Scores",0);
            INI_WriteInt(File,"Kills",0);
            INI_WriteInt(File,"Deaths",0);
            INI_Close(File);
            SendClientMessage(playerid,COLOR_WHITE,"You have been {00FF00}successfully {FFFFFF}registered");
            return 1;
        }
    }

    if(dialogid == DIALOG_LOGIN)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            new hashpass[129];
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            if(!strcmp(hashpass,pInfo[playerid][Pass]))
            {
                INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                SetPlayerScore(playerid,pInfo[playerid][Scores]);
                GivePlayerMoney(playerid,pInfo[playerid][Money]);
                SendClientMessage(playerid,COLOR_WHITE,"Welcome back! You have {00FF00}successfully {FFFFFF}logged in");
            }
            else
            {
                ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \n{FF0000}Insert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}
pawn Код:
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password",pInfo[playerid][Pass],129);
    INI_Int("Money",pInfo[playerid][Money]);
    INI_Int("Scores",pInfo[playerid][Scores]);
    INI_Int("Kills",pInfo[playerid][Kills]);
    INI_Int("Deaths",pInfo[playerid][Deaths]);
    return 1;
}
pawn Код:
stock UserPath(playerid)
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),USERS,name);
    return str;
}
Thank you for trying to help me.


Re: Register/Login system - LarzI - 05.02.2013

Try changing
pawn Код:
"Users/%s.ini"
to
pawn Код:
"Users\\%s.ini"



Re: Register/Login system - MechaTech - 05.02.2013

Quote:
Originally Posted by LarzI
Посмотреть сообщение
Try changing
pawn Код:
"Users/%s.ini"
to
pawn Код:
"Users\\%s.ini"
That didn't work.


Re: Register/Login system - Ockad - 05.02.2013

Run your server.exe as Administrator.


Re: Register/Login system - MechaTech - 05.02.2013

Quote:
Originally Posted by Ockad
Посмотреть сообщение
Run your server.exe as Administrator.
So simple thing can do so much! Thank you!!!!!! It worked!


Re: Register/Login system - Ockad - 05.02.2013

Happy to be of service young man.


Re: Register/Login system - faiznurfaza - 09.02.2013

C:\Program Files\Rockstar Games\GTA San Andreas\Pirate\gamemodes\BAW.pwn(35 : error 001: expected token: "-string end-", but found "-identifier-"
C:\Program Files\Rockstar Games\GTA San Andreas\Pirate\gamemodes\BAW.pwn(35 : warning 215: expression has no effect
C:\Program Files\Rockstar Games\GTA San Andreas\Pirate\gamemodes\BAW.pwn(35 : error 001: expected token: ";", but found ")"
C:\Program Files\Rockstar Games\GTA San Andreas\Pirate\gamemodes\BAW.pwn(35 : error 029: invalid expression, assumed zero
C:\Program Files\Rockstar Games\GTA San Andreas\Pirate\gamemodes\BAW.pwn(35 : fatal error 107: too many error messages on one line

line 358 :
Код:
if(fexist(UserPath(playerid)));
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","{FFFFFF}Welcome back. This account is {00FF00}registered. \n{FFFFFF}Insert your password to login to your account","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Register","{FFFFFF}Welcome! This account is {FF0000}not registered.\n{FFFFFF}Enter your own password to create a new account.","Register","Quit");
    }
help me


Re: Register/Login system - Ranchand1998 - 09.02.2013

Delete ; from line 358.