SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 10/09/2012, 10:25 AM   #1
Guitar
Huge Clucker
 
Guitar's Avatar
 
Join Date: Feb 2012
Location: ►░▒▓♫♪▓▒░◄
Posts: 357
Reputation: 3
Default Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

a Registration system - Using "Y_INI + Whirlpool + Dialogs"

First of all, I would like to thank Kush for his tutorial on making a registration system, but in his tutorial he used "udb hash" which is an old way to hash your passwords and could set you in troubles in the nearest future, like what happened to me. So, I decided to make this tutorial to show you how to create a Registration system from the scratch using Y_INI for saving, Whirlpool for hashing passwords and Dialogs for the log-in/registering.


So, welcome to this tutorial where I am going to show you how to make a registration system using Y_INI, Whirlpool and Dialogs. Let's move to our first step,

The first step is the step where you will be downloading the files you need, in our case we will be needing the following:



Download both of them, and install them. Whirlpool goes directly into your server's folder and Y_INI goes to pawno -> include -> YSI Folder(If you don't have YSI folder just put it in include folder).


So, after finishing step one, let us move to the second step where we will be scripting our registration system. Go to Pawno and open a new .pwn file so we can start .. Okay, after opening it add the "Y_INI" at the beginning of your script under #include <a_samp>.


pawn Code:
#include <YSI\y_ini>

"This include contains all necessary functions needed to create our Login and Register system." - Kush

After adding it, let us add the Hashing into our script, so under the includes goes our hashing native

pawn Code:
native WP_Hash(buffer[], len, const str[]);

This one will make the hashing work, so you just installed it into your script.

Alright, after adding them, let us start adding the defines and colors.


A) Let's define the dialogs:

pawn Code:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4

B) Defining the path where it will be saving the players' statistics.

pawn Code:
#define PATH "/Players/%s.ini"

C) Adding some colors to make our registration system look better,

pawn Code:
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"

So after defining the above, let us move to use an enum to save our variables,

pawn Code:
enum pInfo
{
    pPass[129],
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];

Alright, very well! Now we need something to load the statistics above! We will be adding the following to load the statistics,

pawn Code:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password",PlayerInfo[playerid][pPass], 129);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}

After doing that, let us move to adding the stock function,

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

"The stock function 'UserPath' is merely going to 'grab' the 'PATH' of the User's file." - Kush

Alright, very well! Now let us move to adding the registration system to make it work! Go to OnPlayerConnect, we will be scripting something to check if the player is registered or not.

pawn Code:
public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
    return 1;
}

"We'll be using the native 'fexist' function to search for our file. Parameters are set to our stock function which we've created. If the file exists, you will receive a 'Login' dialog. If it doesn't, you will receive a register dialog." - Kush

Alright, Awesome! After making that, let us move to making the dialogs respond!

pawn Code:
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_PASSWORD, ""COL_WHITE"Making your account ..",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"PlayerData");
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                INI_WriteString(File, "Password", HashPass);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",-1);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
               
                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Account created!",""COL_GREEN"You've created an account successfuly. Relogging is recommended.","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}

"Instead of using the 'if' statement to define our dialogs, I've used cases as they seem to take less space and are supposedly 'faster'. The (!response) is the function if the first Button hasn't been clicked, it will then kick the player.

The if(!strlen(inputtext)) explains if nothing has been entered into the dialog (input), you would then be prompted to another dialog which shows you 'Incorrect Password'.

If all goes well, the function INI_Open is then 'executed' which loads and opens the Userfile. Once open, the function 'INI_WriteInt' is then called and starts writing the data into the userfile. The Whirlpool Hasher would generate a hash code from the player's inputtext (what you've typed). And after all this is completed, it is then closed by 'INI_Close' function.

Once finished, you will then be prompted to the 'Login' dialog.

In 'DIALOG_LOGIN', if the response is false (you have clicked 'QUIT), you would then be kicked. If given the correct information (password provided), the INI_Parsefile function would then scan and load your player's data." - Kush (But I edited some of the text)

Okay very well going! Now let us define something to save our variables when a player disconnects, so the next step will be for opening the user file, save his latest statistics in server and close his file,

pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"PlayerData");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}

You might ask, where is the password? The answer is that the password saves by itself while registering, so no worries!

After doing that, we're almost done, let us add something cool, such as OnPlayerDeath, so when a player dies it saves and kills another player saves,


pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}

So, that will increase and decrease the kill/death.

Important notes:

a) Make sure you create " Players " folder in your scriptfiles folder.
b) Make sure you've installed Y_INI and Whirlpool correctly.

In case you couldn't follow up, I've made this Gamemode for you, you may be able to download/view it from here:

Click me.

Finally, I would like to thank:

1) Kush for his great tutorial, without his tutorial I wouldn't be able to make this one today!
2) ****** for the great releases and things he does/create!
__________________
3habGamingY_INI Registration system
Click meClick me
Code:
funland.dyndns.org:7777 - Connect and test my work :) [Tutorial] Making a registration system - Using "Y_INI + Whirlpool + Dialogs" 3habGaming is looking for members/helpers/staff - www.3habgaming.icyboards.net :oops:. I am interested in learning the basics to a Roleplay GM.
Jansish is great :) + I hate Dialogs :(

Last edited by Guitar; 10/09/2012 at 12:32 PM.
Guitar is offline   Reply With Quote
Old 10/09/2012, 10:42 AM   #2
iSaad
Little Clucker
 
Join Date: Sep 2012
Posts: 46
Reputation: 25
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Nice it is good to see people finally using up to date methods like Whirlpool, but you could expand the tutorial with adding simple commands for example a /setadmin command, and a /kick command, because this looks like the tutorial made by newbienoob http://forum.sa-mp.com/showthread.php?t=352703.

However other then that nice job.
iSaad is offline   Reply With Quote
Old 10/09/2012, 10:43 AM   #3
Guitar
Huge Clucker
 
Guitar's Avatar
 
Join Date: Feb 2012
Location: ►░▒▓♫♪▓▒░◄
Posts: 357
Reputation: 3
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Thank you and sure, I will be creating commands and such also /stats when I find a free time . About "newbienoob" It's all created by Kush and edited by me, so no worries and I didn't know that there is actually a tutorial like this one .
__________________
3habGamingY_INI Registration system
Click meClick me
Code:
funland.dyndns.org:7777 - Connect and test my work :) [Tutorial] Making a registration system - Using "Y_INI + Whirlpool + Dialogs" 3habGaming is looking for members/helpers/staff - www.3habgaming.icyboards.net :oops:. I am interested in learning the basics to a Roleplay GM.
Jansish is great :) + I hate Dialogs :(
Guitar is offline   Reply With Quote
Old 10/09/2012, 11:30 AM   #4
Deviant96
Big Clucker
 
Join Date: May 2011
Location: Indonesia
Posts: 51
Reputation: 2
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Nice, i used it on my server and works well
__________________
"Even Earth tells us to learn from anything. Human race learned the basic survival on this planet. We are here for help if anyway we can. SAMP Wiki its just a guide with few instructions. You will never get the Advance Pawno Scripting with it. And You're not making your ancestors proud of yourself , Respect The Learners mate and the same goes for everyone." - Ballu Miaa

Last edited by Deviant96; 10/09/2012 at 01:24 PM.
Deviant96 is offline   Reply With Quote
Old 10/09/2012, 12:33 PM   #5
Guitar
Huge Clucker
 
Guitar's Avatar
 
Join Date: Feb 2012
Location: ►░▒▓♫♪▓▒░◄
Posts: 357
Reputation: 3
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Quote:
Originally Posted by Deviant96 View Post
the folder in the scriptfile should be "Users" not "Players"
Ops, yes. I forgot to change the "Users", anyway it's fixed now and uses "Players". - Can you edit your post so nobody gets confused?
__________________
3habGamingY_INI Registration system
Click meClick me
Code:
funland.dyndns.org:7777 - Connect and test my work :) [Tutorial] Making a registration system - Using "Y_INI + Whirlpool + Dialogs" 3habGaming is looking for members/helpers/staff - www.3habgaming.icyboards.net :oops:. I am interested in learning the basics to a Roleplay GM.
Jansish is great :) + I hate Dialogs :(
Guitar is offline   Reply With Quote
Old 10/09/2012, 12:42 PM   #6
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,004
Reputation: 824
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

why you added sentances from kush's tutorial ?
Kaperstone is offline   Reply With Quote
Old 10/09/2012, 01:07 PM   #7
Guitar
Huge Clucker
 
Guitar's Avatar
 
Join Date: Feb 2012
Location: ►░▒▓♫♪▓▒░◄
Posts: 357
Reputation: 3
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Quote:
Originally Posted by xkirill View Post
why you added sentances from kush's tutorial ?
Because his explanation is better than mine.
__________________
3habGamingY_INI Registration system
Click meClick me
Code:
funland.dyndns.org:7777 - Connect and test my work :) [Tutorial] Making a registration system - Using "Y_INI + Whirlpool + Dialogs" 3habGaming is looking for members/helpers/staff - www.3habgaming.icyboards.net :oops:. I am interested in learning the basics to a Roleplay GM.
Jansish is great :) + I hate Dialogs :(
Guitar is offline   Reply With Quote
Old 15/09/2012, 07:01 AM   #8
JaKe Elite
High-roller
 
JaKe Elite's Avatar
 
Join Date: Apr 2012
Location: Philippines
Posts: 3,715
Reputation: 489
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Then, why you bother creating one if you can't explain it?

__________________
Discord: Cipher#7353
__________________


Server IP: Click me | Discord: Click me
JaKe Elite is offline   Reply With Quote
Old 15/09/2012, 10:21 AM   #9
Guitar
Huge Clucker
 
Guitar's Avatar
 
Join Date: Feb 2012
Location: ►░▒▓♫♪▓▒░◄
Posts: 357
Reputation: 3
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Quote:
Originally Posted by Romel View Post
Then, why you bother creating one if you can't explain it?

Because, I have explained what I have added. The already added scripts are better to be explained by their creator. I just replaced the password saving with a hashed one using whirlpool for those who don't know how to do it. Seriously, what I have done is not wrong. And yes, I bother creating one, because I want to help SA-MP members new ones and make it easier for others to make their first step in their Gamemode if they're going to use Y_INI. I can explain it, but you seem to be ignorant about that. I explained what I have added into this script and quoted Kush's explanation for a better results and because of my English not being as good as his, I had to put his.
__________________
3habGamingY_INI Registration system
Click meClick me
Code:
funland.dyndns.org:7777 - Connect and test my work :) [Tutorial] Making a registration system - Using "Y_INI + Whirlpool + Dialogs" 3habGaming is looking for members/helpers/staff - www.3habgaming.icyboards.net :oops:. I am interested in learning the basics to a Roleplay GM.
Jansish is great :) + I hate Dialogs :(
Guitar is offline   Reply With Quote
Old 15/09/2012, 11:11 AM   #10
JaKe Elite
High-roller
 
JaKe Elite's Avatar
 
Join Date: Apr 2012
Location: Philippines
Posts: 3,715
Reputation: 489
Default Re: Making a registration system - Using "Y_INI + Whirlpool + Dialogs"

Let me ask you one thing.
Are you the one who make the password hashing one?
I don't think so. I remember the time which i help you in password hashing one.

Or is this a copy/paste from your script?



I understand you.
But newbienoob already done this tutorial.
__________________
Discord: Cipher#7353
__________________


Server IP: Click me | Discord: Click me
JaKe Elite is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
5 Dialog errors - Input line too long, undefined symbol "t","is" and "only" Deal-or-die Scripting Help 6 01/05/2012 12:08 PM
Admin script requires "ReturnUser", "strtok" and "IsNumeric" Rubennnnn Help Archive 1 02/12/2009 06:08 PM
Making a Registration "window" Alex_Duna Help Archive 2 24/10/2009 01:43 PM
"Bots", "AI", "NPCs"... Computer-controlled pedestrians and traffic! ssflsnoob General 2 23/11/2008 06:06 PM


All times are GMT. The time now is 09:13 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.