SA-MP Forums Archive
Login/Register System with dialog - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Login/Register System with dialog (/showthread.php?tid=251507)



Login/Register System with dialog - Rivera - 27.04.2011

Hi guys. This time I am trying a login/register system, not only with a /login and /register command, but using dialogs. Now, I have these:

pawn Code:
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, 100, 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, 150, 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_Create(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;
}
What should I add to OnPlayerDialogResponse to get if the password is wrong or no. If it's wrong the server will kick him. Please help me !


Re: Login/Register System with dialog - Vickx - 27.04.2011

I'm checking it....


Re: Login/Register System with dialog - BASITJALIL - 27.04.2011

Here is the code
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 1)
	{
	    new file[128], Name[MAX_PLAYER_NAME], string[128];
	    GetPlayerName(playerid, Name, sizeof(Name));
	    format(file, sizeof(file), UserFile, Name);
	    if(response)
	    {
	        if(strlen(inputtext))
	        {
	            dini_Create(file);
	            dini_IntSet(file, "Password", num_hash(inputtext));
	            dini_IntSet(file, "Level", 0);
	            dini_IntSet(file, "Money", 50);
				dini_IntSet(file, "Kills", 0);
				dini_IntSet(file, "Deaths", 0);
				dini_IntSet(file, "AdminLevel", 0);
	            format(string, sizeof(string), "Your registered with this nick %s and with this password %s.", Name, inputtext);
	            SendClientMessage(playerid, 0x6F6F6FFF, string);
	            gPlayerInfo[playerid][Level] = dini_Int(file, "Level");
	            GivePlayerMoney(playerid, dini_Int(file, "Money"));
	            gPlayerInfo[playerid][Kills] = dini_Int(file, "Kills");
	            gPlayerInfo[playerid][Deaths] = dini_Int(file, "Deaths");
	            gPlayerLogged[playerid] = 1;
			}
			else
			{
			    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Please Enter Your password Here:", "Register", "Cancel");
			}
		}
		else
		{
		    Kick(playerid);
		}
	}

	if(dialogid == 2)
	{
	    new file[128], Name[MAX_PLAYER_NAME], string[128];
	    GetPlayerName(playerid, Name, sizeof(Name));
	    format(file, sizeof(file), UserFile, Name);
	    if(response)
	    {
	        if(strlen(inputtext))
	        {
	            if(num_hash(inputtext) != dini_Int(file, "Password"))
	            {
	                SendClientMessage(playerid, 0x408080FF, "You have enterd Wrong Password!");
	                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Please Enter your password here:", "Login", "Cancel");
				}
				else
				{
				    format(string, sizeof(string), "Successfully Logged in Welcome Back %s!", Name);
				    SendClientMessage(playerid, 0xFFFFFFFF, string);
				    gPlayerInfo[playerid][Level] = dini_Int(file, "Level");
	            	GivePlayerMoney(playerid, dini_Int(file, "Money"));
	            	gPlayerInfo[playerid][Kills] = dini_Int(file, "Kills");
	            	gPlayerInfo[playerid][Deaths] = dini_Int(file, "Deaths");
	            	gPlayerLogged[playerid] = 1;
				}
			}
			else
			{
			    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Please Enter Your password Here:", "Login", "Cancel");
			}
		}
		else
		{
		    Kick(playerid);
		}
	}
	return 1;
}



Re: Login/Register System with dialog - Rivera - 27.04.2011

working. thanks