28.04.2011, 11:53
(
Последний раз редактировалось Rivera; 02.05.2011 в 20:04.
)
Introduction
Hi guys. This is my other tutorial. This will show you how to use and create a dialog login/register and admin system. Dialog systems are much better and harder than a simple /login & /register commands. For these dialogs, I have used the slow DINI. Now, I have heard that this job can be done even with Y_INI, but this is a DINI TuT, so you have to have these includes :
dutils is needed just for one simple step, so be sure to download it. Now, let's begin.
Full defines and includes
Now, we will need some other defines before we begin. First get some color defines. You can get them here. Now, define the new PlayerInfo. We need the player's money, admin level, ig level AND his password.
The new PlayerInfo will add a needed variable. Now, if you got everything (includes, defines, etc...) we should proceed to the next step.
OnPlayerConnect
Now, the second step. Here, we will need all the information of the client that logs in. If the server has created a 'database file' of him, then the server will check if the file exists (login) or it should be created (register). For this we need the file, the client's name, and the location of the file.
Now, here is the file checking part with two simple commands.
Here, you can see we have the ShowPlayerDialog lines. Well, this is our dialog.
Now, he should remember the dialog id's. For the register command the dialog id is 1 and for the login 2. We have used here the DIALOG_STYLE_INPUT, because we have to input something into the dialog. In this case, the password.
OnPlayerDisconnect
Under OnPlayerDisconnect you should add the dini commands that will save his password, money, level, etc...
You can see the PlayerInfo helped us here.
Now, let's proceed to dialogs.
OnDialogRespone
Here, we have to do all the job. First, let's begin with the dialog's id. The register dialog id is 1, so let's begin with this.
Same thing. We should check the User folder, player's name etc... Now, you can see that if(dialogid == 1) checks the dialogid (in this case 1). If the player responds with typing his password, then we give him a response too. If he types his password we have to create the new file and dini_IntSet all the parameters (level, pw, admin level...).
Now, everything we have done is checking this client's parameters and kicking him if he kicks the "Cancel" button. Let's proceed now with the login dialog, which's id was 2. We have to check if his password is wrong or right. We'll need the dutils include for this. Now, the same thing as we done before:
Now, a line will check if his password is wrong or not
This is very much needed because without it players can log even with another's password. There's only the left part of the command now and it should be easy to script it with dini.
Conclusion
Last, I wanted to say that it's better to use this system, as it's more professional and it's mostly used these days. For lazy guys who want a CTRL + C and CTRL + V I am adding ALL what I have done here:
P.s.: Just for more professionalism, add this line to avoid warnings:
Cya' to my next TuT ! Please rate & comment
The End
Hi guys. This is my other tutorial. This will show you how to use and create a dialog login/register and admin system. Dialog systems are much better and harder than a simple /login & /register commands. For these dialogs, I have used the slow DINI. Now, I have heard that this job can be done even with Y_INI, but this is a DINI TuT, so you have to have these includes :
pawn Код:
#include <a_samp>
#include <dutils>
#include <Dini>
Full defines and includes
Now, we will need some other defines before we begin. First get some color defines. You can get them here. Now, define the new PlayerInfo. We need the player's money, admin level, ig level AND his password.
pawn Код:
enum pInfo {
AdminLevel,
level,
cash,
pw,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
OnPlayerConnect
Now, the second step. Here, we will need all the information of the client that logs in. If the server has created a 'database file' of him, then the server will check if the file exists (login) or it should be created (register). For this we need the file, the client's name, and the location of the file.
pawn Код:
public OnPlayerConnect(playerid) {
new name[MAX_PLAYER_NAME], file[128]; // the name and the file
GetPlayerName(playerid, name, MAX_PLAYER_NAME); // getting client's name
format(file, sizeof(file), ".../Users/%s.ini", name); // the location of the file
pawn Код:
if(!fexist(file)) { // if the file does not exists
SendClientMessage(playerid, COLOR_YELLOW, "You are not registered, please register");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Please Register", "Enter Your Password Below", "Register", "Cancel"); // this is the dialog type
}
else {
new str[128]; // if the player IS registered
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(str, sizeof(str), "Welcome Back ~r~%s. Enjoy!", name);
SendClientMessage(playerid, COLOR_YELLOW, str);
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Please Login", "Enter Your Password Below", "Login", "Cancel");
}
return 1;
}
Код:
playerid The ID of the player to show the dialog to. dialogid An ID to assign this dialog to, so responses can be processed. Max dialogid is 32767. Using negative values will close any open dialog. style The style of the dialog. caption[] The title at the top of the dialog. The length of the caption can not exceed more than 64 characters before it starts to cut off. info[] The text to display in the dialog. Use \n to start a new line and \t to tabulate. button1[] The text on the left button. button2[] The text on the right button. Leave it blank to hide it.
OnPlayerDisconnect
Under OnPlayerDisconnect you should add the dini commands that will save his password, money, level, etc...
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
new file[128], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), ".../Users/%s.ini", name);
if(dini_Exists(file)) {
dini_IntSet(file, "pw", PlayerInfo[playerid][pw]);
dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][AdminLevel]);
dini_IntSet(file, "cash", PlayerInfo[playerid][cash]);
dini_IntSet(file, "level", PlayerInfo[playerid][level]);
}
return 1;
Now, let's proceed to dialogs.
OnDialogRespone
Here, we have to do all the job. First, let's begin with the dialog's id. The register dialog id is 1, so let's begin with this.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1) {
new file[128], name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), ".../Users/%s.ini", name);
pawn Код:
if(dialogid == 1) {
new file[128], name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), ".../Users/%s.ini", name);
if(response) {
if(strlen(inputtext)) {
dini_Create(file);
dini_IntSet(file, "pw", num_hash(inputtext));
dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][AdminLevel]);
dini_IntSet(file, "cash", PlayerInfo[playerid][cash]);
dini_IntSet(file, "level", PlayerInfo[playerid][level]);
format(str, sizeof(str), "You are registered as ~r~%s. Your password is ~r~%s. /changepass to change it", name, inputtext);
SendClientMessage(playerid, COLOR_SYSTEM, str);
PlayerInfo[playerid][level] = dini_Int(file, "level");
PlayerInfo[playerid][cash] = dini_Int(file, "cash");
PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
}
}
else {
Kick(playerid);
}
}
pawn Код:
if(dialogid == 2) {
new file[128], name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(str, sizeof(str), ".../Users/%s.ini", name);
if(response) {
if(strlen(inputtext)) {
pawn Код:
if(num_hash(inputtext) != dini_Int(file, "pw")) {
pawn Код:
if(dialogid == 2) {
new file[128], name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(str, sizeof(str), ".../Users/%s.ini", name);
if(response) {
if(strlen(inputtext)) {
if(num_hash(inputtext) != dini_Int(file, "pw")) {
SendClientMessage(playerid, COLOR_SYSTEM, "Wrong Password");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Please Login", "Enter Your Password Below", "Login", "Cancel");
}
else {
SendClientMessage(playerid, COLOR_SYSTEM, "Succesfuly logged in");
PlayerInfo[playerid][level] = dini_Int(file, "level");
PlayerInfo[playerid][cash] = dini_Int(file, "cash");
GivePlayerMoney(playerid, dini_Int(file, "cash"));
PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
}
}
}
else {
Kick(playerid);
}
Last, I wanted to say that it's better to use this system, as it's more professional and it's mostly used these days. For lazy guys who want a CTRL + C and CTRL + V I am adding ALL what I have done here:
pawn Код:
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid, COLOR_BRIGHTRED, "Welcome to UK-DM");
SendClientMessage(playerid, COLOR_BRIGHTRED, "Hope you enjoy!");
SendClientMessage(playerid, COLOR_BRIGHTRED, "Type /commands for a list of commands");
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), ".../Users/%s.ini", name);
if(!fexist(file)) {
SendClientMessage(playerid, COLOR_YELLOW, "You are not registered, please register");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Please Register", "Enter Your Password Below", "Register", "Cancel");
}
else {
new str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(str, sizeof(str), "Welcome Back ~r~%s. Enjoy!", name);
SendClientMessage(playerid, COLOR_YELLOW, str);
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Please Login", "Enter Your Password Below", "Login", "Cancel");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new file[128], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), ".../Users/%s.ini", name);
if(dini_Exists(file)) {
dini_IntSet(file, "pw", PlayerInfo[playerid][pw]);
dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][AdminLevel]);
dini_IntSet(file, "cash", PlayerInfo[playerid][cash]);
dini_IntSet(file, "level", PlayerInfo[playerid][level]);
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1) {
new file[128], name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), ".../Users/%s.ini", name);
if(response) {
if(strlen(inputtext)) {
dini_Create(file);
dini_IntSet(file, "pw", num_hash(inputtext));
dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][AdminLevel]);
dini_IntSet(file, "cash", PlayerInfo[playerid][cash]);
dini_IntSet(file, "level", PlayerInfo[playerid][level]);
format(str, sizeof(str), "You are registered as ~r~%s. Your password is ~r~%s. /changepass to change it", name, inputtext);
SendClientMessage(playerid, COLOR_SYSTEM, str);
PlayerInfo[playerid][level] = dini_Int(file, "level");
PlayerInfo[playerid][cash] = dini_Int(file, "cash");
PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
}
}
else {
Kick(playerid);
}
}
if(dialogid == 2) {
new file[128], name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(str, sizeof(str), ".../Users/%s.ini", name);
if(response) {
if(strlen(inputtext)) {
if(num_hash(inputtext) != dini_Int(file, "pw")) {
SendClientMessage(playerid, COLOR_SYSTEM, "Wrong Password");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Please Login", "Enter Your Password Below", "Login", "Cancel");
}
else {
SendClientMessage(playerid, COLOR_SYSTEM, "Succesfuly logged in");
PlayerInfo[playerid][level] = dini_Int(file, "level");
PlayerInfo[playerid][cash] = dini_Int(file, "cash");
GivePlayerMoney(playerid, dini_Int(file, "cash"));
PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
}
}
}
else {
Kick(playerid);
}
}
return 1;
}
pawn Код:
#pragma unused ret_memcpy
The End