[HowTo] Create a simple registration system using dini! -
bogeymanEST - 14.08.2008
How to create a simple
Registration System
using dini!
by bogeyman_EST
Getting started
First of all you will need to download
dini,
dutils and
DUBD and also you have to place them in your include folder!
Now we can get started. I have to point out, that i will be using dcmd, to create the /register and /login commands! Ok, let's say we want to create a script, which saves the player's score, money, password and admin level to a .ini file. So in this tutorial, you will learn, how to set a value in a .ini file, read the value and use it to allow the player to log in. Also we will save the admin level for the file to a variable! So let's get started!
First we should want to create some variables to store the admin level, whether the player is logged in and we should want to define dcmd, too:
pawn Code:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
new level[MAX_PLAYERS];
new logged[MAX_PLAYERS];
Ok, now we can start creating our commands. First, put
pawn Code:
dcmd(register, 8, cmdtext);
dcmd(login, 5, cmdtext);
into your OnPlayerCommandText callback!
Creating /register
Now let's start creating our /register command!
pawn Code:
dcmd_register(playerid, params[])
{
new file[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Users\\%s.ini", pname);
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE:/register [password]");
This script created a variable to store the file path and the player's name, it wrote the file path to the variable "file" and checked if there is anything in the params. Now we can start checking, if the player's stats file exists:
pawn Code:
dcmd_register(playerid, params[])
{
new file[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Users\\%s.ini", pname);
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE:/register [password]");
if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "You are already registered!");
Now our script checks if a file stored in the variable "file" exists, if it does, returns an error message.
Now let's start writing into our file:
pawn Code:
dcmd_register(playerid, params[])
{
new file[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Users\\%s.ini", pname);
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE:/register [password]");
if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "You are already registered!");
dini_Create(file);
dini_IntSet(file, "hashPW", udb_hash(params));
dini_Set(file, "password", params);
dini_IntSet(file, "level", 0);
dini_IntSet(file, "score", GetPlayerScore(playerid));
dini_IntSet(file, "money", GetPlayerMoney(playerid));
Ok, now our little script created the file in the "file" variable, then set some things in the file:
hashPW - Identifying later in our /login command
password - Just the password the player sent us
level - The player's admin level
score - The player's score
money - The player's money
Now let's add some messages and automatically login the player:
pawn Code:
dcmd_register(playerid, params[])
{
new file[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Users\\%s.ini", pname);
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE:/register [password]");
if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "You are already registered!");
dini_Create(file);
dini_IntSet(file, "hashPW", udb_hash(params));
dini_Set(file, "password", params);
dini_IntSet(file, "level", 0);
dini_IntSet(file, "score", GetPlayerScore(playerid));
dini_IntSet(file, "money", GetPlayerMoney(playerid));
new string[128];
format(string, 128, "You succesfully registered the nickname %s with password %s", pname, params);
SendClientMessage(playerid, COLOR_YELLOW, string);
logged[playerid] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You have been automatically logged in!");
return 1;
}
Now it sent a message displaying the password and logged the player in!
This completes the /register command! Now we can start creating the /login command.
Creating /login
This is basically the same process as in /register: Create the variables, store the path, check if the file exists. But there is a difference, that we have to read the file instead of writing. I'll create the command and explain it after creating:
pawn Code:
dcmd_login(playerid, params[])
{
new file[128];
new string[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Users\\%s.ini", pname);
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /login [password]");
if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "You are not registered!");
if(logged[playerid]) return SendClientMessage(playerid, COLOR_RED, "You are already logged in!");
new tmp;
tmp = dini_Int(file, "hashPW");
if(udb_hash(params) != tmp)
{
format(string, 256, "You specified the wrong password for %s!", pname);
SendClientMessage(playerid, COLOR_RED, string);
}
else
{
logged[playerid] = 1;
level[playerid] = dini_Int(file, "level");
SetPlayerScore(playerid, dini_Int(file, "score"));
GivePlayerMoney(playerid, dini_Int(file, "money")-GetPlayerMoney(playerid));
SendClientMessage(playerid, COLOR_YELLOW, "You have succesfully logged in!");
printf("%s (%i) logged in with password %s", pname, playerid, params);
}
return 1;
}
Ok, this script, like in the /register command, creates the "file" variable to store the file path, a "string" for the messages, and "pname" to store the player's name. Then some basic if() statements to check if the player is registered, logged in or there are no params.
Then it creates a variable "tmp" to store the hashed version of the password. Then it hashes the player's inputted password and checks if the two passwords match, if they do, logs the player in and sets the "level" variable to the level, their score to the score and their money to the money in the player's stats file!
Done!
See, wasn't that hard! =)
Download as a file:
Please read this post COMPLETELY through before posting a problem. Everything you will need is here!
Re: [HowTo] Create a simple registration system using dini! -
MaTrIx4057 - 14.08.2008
Very nice tutorial
Re: [HowTo] Create a simple registration system using dini! -
Kapil - 14.08.2008
edit:
nice
Re: [HowTo] Create a simple registration system using dini! -
bogeymanEST - 14.08.2008
It's good that, there is a better way of doing this, but this a tutorial for noobs, who don't know anything about creating registration systems etc. But thanks for pointing that out anyway =)
Re: [HowTo] Create a simple registration system using dini! -
Maniac_X - 25.08.2008
Hi i'm not sure why it's doing this but i'm getting the following error :
blahblahblah.pwn(177) : error 017: undefined symbol "string"
blahblahblah.pwn(17 : error 017: undefined symbol "string"
blahblahblah.pwn(179) : error 017: undefined symbol "string"
blahblahblah.pwn(193) : error 037: invalid string (possibly non-terminated string)
blahblahblah.pwn(193) : error 029: invalid expression, assumed zero
blahblahblah.pwn(193) : error 029: invalid expression, assumed zero
blahblahblah.pwn(193) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
7 Errors.
relating to this code :
Code:
LINE
(177) dini_IntSet(string, "level", 0);
(178) dini_IntSet(string, "score", GetPlayerScore(playerid));
(179) dini_IntSet(string, "money", GetPlayerMoney(playerid));
Re: [HowTo] Create a simple registration system using dini! -
mamorunl - 25.08.2008
pawn Code:
new string[218]; // you can change 218 to a number you prefer regarding to the size of the string
I would suggest using DUDB for user accounts
Re: [HowTo] Create a simple registration system using dini! -
Antironix - 25.08.2008
Quote:
Originally Posted by [NT
SpeedDevil ]
pawn Code:
new string[218]; // you can change 218 to a number you prefer regarding to the size of the string
I would suggest using DUDB for user accounts
|
Explain me why please.
Re: [HowTo] Create a simple registration system using dini! -
bogeymanEST - 25.08.2008
Quote:
Originally Posted by Maniac_X
Hi i'm not sure why it's doing this but i'm getting the following error :
blahblahblah.pwn(177) : error 017: undefined symbol "string"
blahblahblah.pwn(17 : error 017: undefined symbol "string"
blahblahblah.pwn(179) : error 017: undefined symbol "string"
blahblahblah.pwn(193) : error 037: invalid string (possibly non-terminated string)
blahblahblah.pwn(193) : error 029: invalid expression, assumed zero
blahblahblah.pwn(193) : error 029: invalid expression, assumed zero
blahblahblah.pwn(193) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
7 Errors.
relating to this code :
Code:
LINE
(177) dini_IntSet(string, "level", 0);
(178) dini_IntSet(string, "score", GetPlayerScore(playerid));
(179) dini_IntSet(string, "money", GetPlayerMoney(playerid));
|
yeah, had a small typo.. fixed now
Re: [HowTo] Create a simple registration system using dini! -
mamorunl - 25.08.2008
Quote:
Originally Posted by Wadabak
Quote:
Originally Posted by [NT
SpeedDevil ]
pawn Code:
new string[218]; // you can change 218 to a number you prefer regarding to the size of the string
I would suggest using DUDB for user accounts
|
Explain me why please.
|
explain what?
Re: [HowTo] Create a simple registration system using dini! -
Antironix - 25.08.2008
Why you are suggesting DUDB for user accounts instead of Dini.
Re: [HowTo] Create a simple registration system using dini! -
Maniac_X - 26.08.2008
.pwn(193) : error 037: invalid string (possibly non-terminated string)
which is referring to this line
format(file, sizeof(string), "\\Users\\%s.ini, pname);
I've adjusted that other stuff as mentioned and those errors are now resolved just got this one to go and i'm sure it will take out those other 2 errors i'm experiencing.
Re: [HowTo] Create a simple registration system using dini! -
Extremo - 26.08.2008
Code:
new string[256];
format(string, sizeof(string), "\\Users\\%s.ini, pname);
that should work
Re: [HowTo] Create a simple registration system using dini! -
Antironix - 26.08.2008
I would suggest to change Dini/Dudb for Djson.
Re: [HowTo] Create a simple registration system using dini! -
Maniac_X - 26.08.2008
Will the rest of this conde work with this Djson.inc ?
Thats what I would have thought too *with regards to the adding of the new string[256];*but it came up with the error.. String is already defined cause it's got it
new file[256];
new string[256], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "\\Users\\%s.ini, pname);
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /login [password]");
hmm it's very confusing stuff ..or maybe i'm just too tired to think straight right now.
Re: [HowTo] Create a simple registration system using dini! -
mamorunl - 26.08.2008
Quote:
Originally Posted by Wadabak
Why you are suggesting DUDB for user accounts instead of Dini.
|
because DUDB (DracoBlue User DataBase) is for Users so it can hold playerstatistics. Dini (DracoBlue INI -no idea where INI for stands but it is a file extention) is mostly for other files like server messages, a list of cars, players (and not statistics because DUDB is for that)
thats why I should use DUDB instead of DINI - because it is a User DataBase and specifically made for users, unlike dini
Re: [HowTo] Create a simple registration system using dini! -
Antironix - 26.08.2008
Quote:
Originally Posted by [NT
SpeedDevil ]
Quote:
Originally Posted by Wadabak
Why you are suggesting DUDB for user accounts instead of Dini.
|
because DUDB (DracoBlue User DataBase) is for Users so it can hold playerstatistics. Dini (DracoBlue INI -no idea where INI for stands but it is a file extention) is mostly for other files like server messages, a list of cars, players (and not statistics because DUDB is for that)
thats why I should use DUDB instead of DINI - because it is a User DataBase and specifically made for users, unlike dini
|
It does the same, but I am changing to Djson now, way better as dini/dudb
Re: [HowTo] Create a simple registration system using dini! -
Maniac_X - 28.08.2008
So i tried screwing around a bit seeing if there was a way to identify that string properly but naturaly being so new to this stuff it made it worse not better so i ended up copying the original code back again from this topic post. however it came back with the same string error
Code:
.pwn(193) : error 037: invalid string (possibly non-terminated string)
.pwn(193) : error 029: invalid expression, assumed zero
.pwn(193) : error 029: invalid expression, assumed zero
.pwn(193) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
and the line that it's referring to is :
Code:
// PLAYER LOGIN SCRIPT
dcmd_login(playerid, params[])
{
new file[256]; //190
new string[256], pname[MAX_PLAYER_NAME]; //191
GetPlayerName(playerid, pname, sizeof(pname)); //192
format(file, sizeof(string), "\\Users\\%s.ini, pname); //193
I think i'm Jynxd
Re: [HowTo] Create a simple registration system using dini! -
FedorMS - 28.08.2008
Quote:
Originally Posted by Maniac_X
So i tried screwing around a bit seeing if there was a way to identify that string properly but naturaly being so new to this stuff it made it worse not better so i ended up copying the original code back again from this topic post. however it came back with the same string error
Code:
.pwn(193) : error 037: invalid string (possibly non-terminated string)
.pwn(193) : error 029: invalid expression, assumed zero
.pwn(193) : error 029: invalid expression, assumed zero
.pwn(193) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
and the line that is referring to is :
Code:
// PLAYER LOGIN SCRIPT
dcmd_login(playerid, params[])
{
new file[256]; //190
new string[256], pname[MAX_PLAYER_NAME]; //191
GetPlayerName(playerid, pname, sizeof(pname)); //192
format(file, sizeof(string), "\\Users\\%s.ini, pname); //193
I think i'm Jynxd
|
Did you close your brackets?
Re: [HowTo] Create a simple registration system using dini! -
Maniac_X - 28.08.2008
yeah i did but you did give me the clue to figurieng out what was wrong.. the "" paranthesis were missing on the closure of that statement which in turn had made my ")" symbol blue as if it were part of that statement. so i added the " in before the closed bracket and that cleaned up that error
Thanks man.
unfortunately the pain continued on at line 206. a new error has spured up so i'll take a quick look into that and see if i can figure it first
says unidentified symbol :
Quote:
pwn(206) : error 017: undefined symbol "dini_IntGet"
|
line 206 :
Code:
level[playerid] = dini_IntGet(file, "level");
I get the feeling that somewhere in the dini.inc file it isnt' defined right but i can't back that up as i have no idea whats what in there.
Re: [HowTo] Create a simple registration system using dini! -
bogeymanEST - 29.08.2008
Quote:
Originally Posted by [NT
SpeedDevil ]
Quote:
Originally Posted by Wadabak
Why you are suggesting DUDB for user accounts instead of Dini.
|
because DUDB (DracoBlue User DataBase) is for Users so it can hold playerstatistics. Dini (DracoBlue INI -no idea where INI for stands but it is a file extention) is mostly for other files like server messages, a list of cars, players (and not statistics because DUDB is for that)
thats why I should use DUDB instead of DINI - because it is a User DataBase and specifically made for users, unlike dini
|
Yeah, but this is a dini tutorial, the registration system is just an example what could be done with it. This tutorial just helps people to get started with using dini.