Jump to content

Sistem MySQL R41-2 Name & Password


CiJey

Recommended Posts

#include <a_samp>
#include <a_mysql>

new MySQL: sql;
new PlayerLogged[MAX_PLAYERS];

#define DIALOG_REGISTER		0
#define DIALOG_LOGIN		1

stock GetName(playerid)
{
	new playerName[24];
	GetPlayerName(playerid, playerName, 24);
	return playerName;
}

public OnGameModeInit()
{
	sql = mysql_connect("", "", "", "");
	return 1;
}

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

public OnPlayerConnect(playerid)
{
	new query[128];
	mysql_format(sql, query, 128, "SELECT * FROM `` WHERE `Name` = '%s' LIMIT 1", GetName(playerid));
	mysql_query(sq;, query);
	if(cache_num_rows() == 0) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "", "", "", "");
	if(cache_num_rows() > 0) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "", "", "", "");
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		case DIALOG_REGISTER:
		{
			if(!response) return Kick(playerid);
			if(response)
			{
				if(strlen(inputtext) == 0) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "", "", "", "");
				if(strlen(inputtext) > 0)
				{
					new query[256];
					mysql_format(sql, query, 256, "INSERT INTO `` (`Name`, `Password`) VALUES ('%s', '%s')", GetName(playerid), inputtext);
					mysql_query(sql, query);

					PlayerLogged[playerid] = 1;
				}
			}
		}
		case DIALOG_LOGIN:
		{
			if(!response) return Kick(playerid);
			if(response)
			{
              	new query[128];
              	mysql_format(sql, query, 128, "SELECT * FROM `` WHERE `Name` = '%s' AND `Password` = '%s' LIMIT 1", GetName(playerid), inputtext);
              	mysql_query(sql, query);
              	if(cache_num_rows() == 0) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "", "", "", "");
              	if(cache_num_rows() > 0)
                {
					PlayerLogged[playerid] = 1;
                  	
                  	// Aici scrieti voi ce sa se intample dupa ce se logheaza.
                }
			}
		}
	}
	return 1;
}

 

Edited by CiJey
Link to comment
Share on other sites

Asta nu e un tutorial, nu ai explicat nimic decat ai dat copy paste la ce ai lucrat in gmul tau, nu zic ca nu stii ce ai scris acolo dar cei care vor sa invete nu vor reusi pentru ca nu ai specificat ce face fiecare functie. Postand asa s ar incadra la gamemodeuri sau alta categorie

  • Upvote 1

 

    __  ____      __           
   /  |/  (_)____/ /____  _____
  / /|_/ / / ___/ __/ _ \/ ___/
 / /  / / (__  ) /_/  __/ /    
/_/  /_/_/____/\__/\___/_/     
SERVICII SCRIPTING DE CALITATE
Pagina     Scripting     pawn
Link to comment
Share on other sites

1 oră în urmă, Mister a spus:

Asta nu e un tutorial, nu ai explicat nimic decat ai dat copy paste la ce ai lucrat in gmul tau, nu zic ca nu stii ce ai scris acolo dar cei care vor sa invete nu vor reusi pentru ca nu ai specificat ce face fiecare functie. Postand asa s ar incadra la gamemodeuri sau alta categorie

Asta vroiam sa zic si eu.

Link to comment
Share on other sites

Acum 24 minute, Banditul a spus:

Si de ce mysql_query? Daca ti se conecteaza > 2 playeri in acelasi timp va fi bai ales daca ai foarte multe date si lucruri facute la login/register. + ce a zis Mister

ok si care ar fi mai buna decat mysql_query ca multa lume nu stiu sau nu auzit de ea ?

FiveGame  Lands

Pawno Developer, Mapping , Scripter

Since 2016

Link to comment
Share on other sites

https://github.com/pBlueG/SA-MP-MySQL/archive/R41-3.zip

Ai in example_scripts , cel mai bun, in dupa parerea mea, pentru ca mysql_query opreste tot scriptu pana se executa query-ul (desigur, in naumite cazuri poate lua doar cateva nano secunde sau chiar milisecunde , dar afecteaza rularea gm-ului) (sau poti folosi mysql_pquery in loc de mysql_tquery pentru a executa query-uri in paralel astfel incat sa poti incarca datele mai rapid , da doar pentru incarcare , si nu zic ca e recomandat dar e bun)

 

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.