31.08.2013, 18:51
Hey guys, I am trying to write a simple code that allows players register/login their/into their accounts. I have finished with register dialog, everything works fine, which can not be told about login. The problem is that while I type any character I am getting logged-in. I guess that I've made a mistake in comparing password with the inputtext. Here is the code:
The following callbacks are used only. Somebody, pimp my code.
And, yeah, create a folder called "Users" in the scriptfiles folder.
PHP код:
#define DIALOG_REGISTER 0
#define DIALOG_LOGIN 1
#define DIALOG_QUIT 2
#define DIALOG_PASSLEN 3
#define DIALOG_WRONGPASS 4
PHP код:
public OnPlayerConnect(playerid)
{
new PlrFile[128];
format(PlrFile, sizeof(PlrFile), "/Users/%s.txt", RetPlrName(playerid));
if(!fexist(PlrFile))
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registration", "Please type your future password below:", "Register", "Cancel");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logging-in", "Please type your password below:", "Login", "Cancel");
}
return 1;
}
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_REGISTER)
{
if(response == 0)
{
ShowPlayerDialog(playerid, DIALOG_QUIT, DIALOG_STYLE_MSGBOX, "Cancelled", "Use /q to exit", "OK", "");
Kick(playerid);
}
else if(response == 1)
{
new KeyLen = strlen(inputtext);
if(KeyLen <= 5 || KeyLen >= 33)
{
ShowPlayerDialog(playerid, DIALOG_PASSLEN, DIALOG_STYLE_MSGBOX, "Notice", "The password must be between 6 and 32 symbols", "OK", "");
}
else
{
new PlrFile[128], File:PlrFileOpen;
format(PlrFile, sizeof(PlrFile), "/Users/%s.txt", RetPlrName(playerid));
PlrFileOpen = fopen(PlrFile, io_write);
fwrite(PlrFileOpen, inputtext);
fclose(PlrFileOpen);
}
}
}
else if(dialogid == DIALOG_LOGIN)
{
if(response == 0)
{
ShowPlayerDialog(playerid, DIALOG_QUIT, DIALOG_STYLE_MSGBOX, "Cancelled", "Use /q to exit", "OK", "");
Kick(playerid);
}
else if(response == 1)
{
new PlrFile[128], File:PlrFileOpen, pass[128];
format(PlrFile, sizeof(PlrFile), "/Users/%s.txt", RetPlrName(playerid));
PlrFileOpen = fopen(PlrFile, io_read);
fread(PlrFileOpen, pass);
if(strcmp(inputtext, pass, false, 32))
{
SendClientMessage(playerid, 0xFFFFFFAA, "You have successfully logged-in");
}
else
{
ShowPlayerDialog(playerid, DIALOG_WRONGPASS, DIALOG_STYLE_MSGBOX, "Error", "You have typed wrong password", "OK", "");
}
fclose(PlrFileOpen);
}
}
else if(dialogid == DIALOG_PASSLEN)
{
if(response == 1)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registration", "Please type your future password below:", "Register", "Cancel");
}
}
else if(dialogid == DIALOG_WRONGPASS)
{
if(response == 1)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logging-in", "Please type your password below:", "Login", "Cancel");
}
}
return 1;
}
And, yeah, create a folder called "Users" in the scriptfiles folder.