Jump to content
Autentificarea cu Google și Facebook nu mai este disponibilă. ×

Recommended Posts

Posted (edited)
#include <a_samp>
#include <a_mysql>

new MySQL:sql, logged[100];

#define DREGISTER 0
#define DLOGIN 1

enum pinfo
{
	psqlid,
	padmin
}; new playerinfo[100][pinfo];

stock getname(playerid)
{
	new strname[20];
	GetPlayerName(playerid, strname, sizeof strname);
	return strname;
}

public OnGameModeInit()
{
	sql = mysql_connect("127.0.0.1", "root", "", "");
	return true;
}

public OnGameModeExit()
{
	mysql_close(sql);
	return true;
}

public OnPlayerConnect(playerid)
{
	logged[playerid] = 0;
	new query[100];
	mysql_format(sql, query, sizeof query, "SELECT * FROM `PLAYERS` WHERE `NAME` = '%s'", getname(playerid));
	mysql_query(sql, query);
	if(cache_num_rows() == 0) return ShowPlayerDialog(playerid, DREGISTER, DIALOG_STYLE_INPUT, "Register", "Type your new password below to Register!", "Register", "Quit");
	if(cache_num_rows() == 1) return ShowPlayerDialog(playerid, DLOGIN, DIALOG_STYLE_INPUT, "Login", "Type your password below to Login.", "Login", "Quit");
	return true;
}

public OnPlayerDisconnect(playerid, reason)
{
	logged[playerid] = 0;
	return true;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
	    case DREGISTER:
	    {
	        if(!response) return Kick(playerid);
	        if(response)
	        {
	            if(strlen(inputtext) < 8 || strlen(inputtext) > 64) return ShowPlayerDialog(playerid, DREGISTER, DIALOG_STYLE_INPUT, "Register", "Your new password must be from 8 to 64 characters.", "Register", "Quit");
	            //
	            new query[200];
	            mysql_format(sql, query, sizeof query, "INSERT INTO `PLAYERS` (`NAME`,`PASSWORD`) VALUES ('%s','%s')", getname(playerid), inputtext);
	            mysql_query(sql, query);
	            //
	            playerinfo[playerid][psqlid] = cache_insert_id();
	            //
	            ShowPlayerDialog(playerid, DLOGIN, DIALOG_STYLE_INPUT, "Login", "Now type your password below to Login.", "Login", "Quit");
	        }
	    }
	    case DLOGIN:
	    {
	        if(!response) return Kick(playerid);
	        if(response)
	        {
				if(strlen(inputtext) == 0) return ShowPlayerDialog(playerid, DLOGIN, DIALOG_STYLE_INPUT, "Login", "You do not typed your password below!", "Login", "Quit");
				//
	            new query[200];
	            mysql_format(sql, query, sizeof query, "SELECT * FROM `PLAYERS` WHERE `NAME` = '%s' AND `PASSWORD` = '%s'", getname(playerid), inputtext);
	            mysql_query(sql, query);
	            if(cache_num_rows() == 0) return ShowPlayerDialog(playerid, DLOGIN, DIALOG_STYLE_INPUT, "Login", "You typed a wrong password.", "Login", "Quit");
	            if(cache_num_rows() == 1)
	            {
	                logged[playerid] = 1;
	                //
	                cache_get_value_int(0, "ADMIN", playerinfo[playerid][padmin]);
	                if(playerinfo[playerid][padmin] > 0)
	                {
	                    new msg[50];
	                    format(msg, sizeof msg, "Bine ai venit %s! Admin Level-ul tau este %i.", getname(playerid), playerinfo[playerid][padmin]);
	                    SendClientMessage(playerid, 0xC0FF00FF, msg);
	                }
	            }
	        }
	    }
	}
	return true;
}

// Remy's MySQL Register & Login System R41-2

 

Edited by Remy1738
  • Like 1
Posted

Acest sistem este unul foarte simplu. Tot ce trebuie sa faci este sa creezi baza de date (conform script-ului sau modificand-ul dupa bunul plac), apoi sa adaugi numele bazei tale de date la OnGameModeInit >> mysql_connect >> string-ul cu numarul 4. Dupa ce ai facut toate astea, poti sa adaugi orice alt sistem doresti, si sa-ti continui treaba cu un sistem de salvare gata facut, simplu si rapid. Trebuie sa ai MySQL R41-2 instalat si functional (logic).

Am sa revin si cu alte sisteme, care vor fi compatibile cu acesta.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.