[HELP]register system(y_ini)!!!
#1

OK,so first off all I know I've been off for a long time,but now I am back,and maybe some of you think I have an evoluated gamemode file,but for some reason(DO NOT ask why)I decided to start with a new gamemode file.You may also think that I should have some experience scripting-related(that's true) but I've switched from dini to y_ini(and as y_ini mentions in his tutorial y_ini file is different from any other reea-wrtie file system[Yes,I've read the tutorial]).I am ecountering a kinda "smal" problem,I mean only 1 problem,but I can't classify it as A BIG one.The noly problem is that I cannot login,after I have created my account,for somne reason.If you can spot any mistake in my code,please tell me:

pawn Код:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2

stock Accounts(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

stock udb_hash(buf[])
{
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

stock LoadRegisteredAccount(playerid)
{
   GivePlayerMoney(playerid,1000);
   SetPlayerSkin(playerid,28);
   SetPVarInt(playerid,"registered",1);
}

new
   Score[MAX_PLAYERS],
   Money[MAX_PLAYERS],
   Admin[MAX_PLAYERS],
   Password[MAX_PLAYERS];

stock LoadPlayerAccount_data(playerid,name[],value[])
{
     INI_Int("Password",Password[playerid]);
     INI_Int("Money",Money[playerid]);
     INI_Int("Score",Score[playerid]);
     INI_Int("Adminlevel",Admin[playerid]);
     return 1;
}

public OnPlayerConnect(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,sizeof(pName));
    new connected[64];
    format(connected,sizeof(connected),"%s(%d) has joined the server",pName,playerid);
    SendClientMessageToAll(COLOR_GREY,connected);
    SendClientMessage(playerid,COLOR_GREEN,"Welcome to San Fierro RP");
    if(!fexist(Accounts(playerid)))
    {
       ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register","Please type in a password to register: ","Register","Cancel");
    }
    else
    {
       INI_ParseFile(Accounts(playerid), "LoadPlayerAccount_%s", .bExtra = true, .extra = playerid);
       ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Welcome back.Please type in your password: ","Login","Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:PFile = INI_Open(Accounts(playerid));
    INI_SetTag(PFile,"PlayerInfo");
    INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
    INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
    INI_WriteInt(PFile,"Adminlevel",GetPVarInt(playerid,"Adminlevel"));
    INI_Close(PFile);
    new pName[MAX_PLAYER_NAME];
    new string[64];
    GetPlayerName(playerid,pName,sizeof(pName));
    format(string,sizeof(string),"%s(%d) has left the server!",pName,playerid);
    SendClientMessageToAll(COLOR_GREY,string);
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid==1)
    {
      if(response==1)
      {
        if(!strlen(inputtext))
        {
          PlayerPlaySound(playerid,1055,0,0,0);
          SendClientMessage(playerid,COLOR_RED,"Invalid password,please try again");
          ShowPlayerDialog(playerid,DIALOG_STYLE_INPUT,1,"Register","Please type in a password to register: ","Register","Cancel");
        }
        else
        {
         new pName[24];
         GetPlayerName(playerid,pName,sizeof(pName));
         LoadRegisteredAccount(playerid);
         SendClientMessage(playerid,COLOR_GREEN,"Succesfully registered!!!");
         PlayerPlaySound(playerid,1057,0,0,0);
         SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
         LoadRegisteredAccount(playerid);
         new INI:PFile = INI_Open(Accounts(playerid));
         INI_SetTag(PFile,"PlayerInfo");
         INI_WriteInt(PFile,"Passwrod",udb_hash(inputtext));
         INI_WriteInt(PFile,"Score",GetPlayerScore(playerid));
         INI_WriteInt(PFile,"Money",GetPlayerMoney(playerid));
         INI_WriteInt(PFile,"Adminlevel",0);
         INI_Close(PFile);
        }
      }
      if(response==0)
      {
        SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
        Kick(playerid);
      }
    }
    if(dialogid==2)
    {
     if(response==1)
     {
        if(udb_hash(inputtext) == Password[playerid])
        {
         SendClientMessage(playerid,COLOR_GREEN,"Succesfully logged!!!");
         PlayerPlaySound(playerid,1057,0,0,0);
         SendClientMessage(playerid,COLOR_PURPLE,"This is San Fierro RolePlay");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /new for more infos about the server");
         SendClientMessage(playerid,COLOR_YELLOW,"Type /rules for server rules");
         SetPlayerScore(playerid,Score[playerid]);
         GivePlayerMoney(playerid,Money[playerid]);
         SetPVarInt(playerid,"Adminlevel",Admin[playerid]);
        }
        else
        {
         PlayerPlaySound(playerid,1055,0,0,0);
         SendClientMessage(playerid,COLOR_RED,"Wrong password,please try again");
         ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Welcome back.Please type in your password: ","Login","Cancel");
        }
     }
     if(response==0)
     {
        SendClientMessage(playerid,COLOR_GREEN,"I hope you will be back soon");
        Kick(playerid);
     }
    }
    return 1;
}
The DataBase works good after I registered,but when I try to login even if I type my password in I cannot login.PLUS,if you think there's a way that in my database I can turn my password from numbers to letters also tell me(What I mean:By reading several tutorials I've spotted this udb_hash password,I understood that it turns my letters-containing password into numbers in PlayerDatabase,but I'd like it to be displayed as letters-containing(original password) in PlayerDatabase too).Any1 help me please?

NOTE:I did not copy this register system from somewhere,I've just read 4 tutorials,and made this 1.The only think I have copied is the udb_hash function,wich I think it is the problem!
Reply
#2

Anyone,please?I have read a similar thread to mine,but nobody answered that also
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)