[Looking For] DINI Register/Login
#1

Hello, im looking for a tutorial where i can learn how to make Register / Login scripts.
I've searched around and found alot of tutorials, but they didnt work?
I've also looked in other scripts to see how they did it, but i couldnt find out?
I would like one with DCMD and sscanf
Reply
#2

It's not a Tuturial, but i fixed the code from this one(CLICK)

For explaination just read the Tuturial.

_________________________________________________
Over script:

pawn Code:
enum pInfo
{
    Cash
}

new PlayerInfo[MAX_PLAYERS][pInfo];
new IsPlayerLogged[MAX_PLAYERS];
OnPlayerCommandText:

pawn Code:
dcmd(register, 8, cmdtext);
dcmd(login, 5, cmdtext);
Somewhere else:

pawn Code:
dcmd_register(playerid, params[])
{
    new file[MAX_PLAYER_NAME+4];
        new PName[MAX_PLAYER_NAME];
        new Pass[50];

      if(sscanf(params, "s", Pass))return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /register [Password] (maximum: 50 cells)");
      if(IsPlayerLogged[playerid]==1)return SendClientMessage(playerid, COLOR_SYSTEM, "You're already logged in!");

      GetPlayerName(playerid, PName, sizeof(PName));
      format(file,sizeof(file),"D-Admin/Players/%s.ini",PName);

      if(!fexist(file))
            {
              dini_Create(file);
              dini_IntSet(file,"Password", udb_hash(Pass));
              dini_IntSet(file,"Cash", 0);
              SendClientMessage(playerid, COLOR_SYSTEM, "[System]: Account Created! Please log in with /login.");
              PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
              printf("[Register]%s has created an account!", PName);
            }
            else
            {
              SendClientMessage(playerid, COLOR_SYSTEM, "[System]: Account Already Found In Database");
        PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            }
        return 1;
}
pawn Code:
dcmd_login(playerid, params[])
{
  new file[MAX_PLAYER_NAME+4];
  new PlayerName[MAX_PLAYER_NAME];
    new LogPass[50];
    if(sscanf(params, "s", LogPass))return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /login [password]");

    if(IsPlayerLogged[playerid] == 1)
    {
        SendClientMessage(playerid, COLOR_GREEN, "You already are logged in!");
        return 1;
    }
    else
    {
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        format(file,sizeof(file),"D-Admin/Players/%s.ini",PlayerName);
        if(fexist(file))
        {
          new FilePass[256];
        FilePass = dini_Get(file, "Password");
            if(udb_hash(LogPass) != strval(FilePass))
            {
              SendClientMessage(playerid, COLOR_RED, "Login Failed!");
              printf("%s has failed logging in!", PlayerName);
            }
            else
            {
                IsPlayerLogged[playerid] = 1;
                SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                PlayerInfo[playerid][Cash] = dini_Int(file, "Cash");
                SendClientMessage(playerid, COLOR_GREEN, "[System]: You logged in!");
                PlayerPlaySound(playerid,1058,0.0,0.0,0.0);
            }
        }
    }
    return 1;
}
_________________________________________________


Cheers.

Reply
#3

Thank you, Another question?

Shouldn't there be somesort of saving when the user disconnect?
Reply
#4

Quote:
Originally Posted by Niixie
Thank you, Another question?

Shouldn't there be somesort of saving when the user disconnect?
Yes, it should. Use there, e.g. for saving money/cash:

OnPlayerDisconnect:
pawn Code:
dini_IntSet(file,"Cash", GetPlayerMoney(playerid));
Reply
#5

I get this error
Code:
error 017: undefined symbol "file"
Reply
#6

Write in top of the script:
#define <file>
Reply
#7

Then i get these

Code:
error 074: #define pattern must start with an alphabetic character
error 017: undefined symbol "file"
Reply
#8

Quote:
Originally Posted by Adam199
Write in top of the script:
#define <file>
Oh god, now that's the most stupid answer I could ever thought of.

Niixie, don't just copy paste the code, you should edit it to suit your needs. It's most probably the file's directory, so you should get the player's name and edit the script to put the file in the folder you use to save accounts.

pawn Code:
new

   PlayerName[MAX_PLAYER_NAME];
   string[128];

GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

format(string, sizeof(string), "Your directory for saving users/%s", PlayerName);
dini_IntSet(string, "Cash", GetPlayerMoney(playerid));
Reply
#9

Already did that ... I know that much

I just need to get rid of that file error thing? and i know that "#define file" is a VERY bad idea.
Reply
#10

Quote:
Originally Posted by Niixie
I get this error
Code:
error 017: undefined symbol "file"
Post line please.

#EDIT#: Figured it out by myself =P. Fix:

Add this to OnPlayerDisconnect:

pawn Code:
new file[MAX_PLAYER_NAME+4], PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(file,sizeof(file),"D-Admin/Players/%s.ini",PlayerName);
(By the way: You need to create the directory "D-Admin/Players" into scriptfiles, because i took those codes out of my Admin script)

Cheers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)