Jump to content

MySQL R41-2 System by Remy


VexioH

Recommended Posts

#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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.