Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- enum pInfo
- {
- pName[MAX_PLAYER_NAME],
- pPassword[64],
- pLevel,
- }
- new P_DATA[MAX_PLAYERS][pInfo];
- public OnPlayerConnect(playerid)
- {
- new string[128];
- mysql_format(SQL, string, sizeof(string), "SELECT `Name` FROM `server_accounts` WHERE `Name` = '%e', getName(playerid));
- mysql_tquery(SQL, string, "CheckAccount", "i", playerid);
- return 1;
- }
- forward CheckAccount(playerid);
- public CheckAccount(playerid)
- {
- if(cache_num_rows() > 0)
- {
- print("Contul a fost gasit cu succes!");
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Introdu parola contului tau mai jos:", "Ok", "Close");
- }
- else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Te rugam sa introduci parola pentru acest cont:", "Ok", "Close");
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_REGISTER:
- {
- CreateAccount(playerid, inputtext);
- }
- case DIALOG_LOGIN:
- {
- new string[128 + 64]; // 64 caractere de la parola + lungimea de 73 de la format + lungimea de la nume de maxim 24 caractere
- mysql_format(SQL, string, sizeof(string), "SELECT * FROM `server_accounts` WHERE `Name` = '%e' AND `Password` = '%e'", getName(playerid), inputtext);
- mysql_tquery(SQL, string, "LoadAccount", "i", playerid);
- }
- }
- }
- forward CreateAccount(playerid, password[]);
- public CreateAccount(playerid, password[])
- {
- new string[128 + 64];
- mysql_format(SQL, string, sizeof(string), "INSERT INTO `server_accounts` (`Name`, `Password`) VALUES ('%e', '%e')", getName(playerid), password);
- mysql_tquery(SQL, string, "", "");
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Introdu parola contului tau mai jos:", "Ok", "Close");
- return 1;
- }
- forward LoadAccount(playerid);
- public LoadAccount(playerid)
- {
- if(cache_num_rows() > 0)
- {
- cache_get_field_content(0, "Name", P_DATA[playerid][pName], SQL, MAX_PLAYER_NAME);
- cache_get_field_content(0, "Password", P_DATA[playerid][pPassword], SQL, 64);
- cache_get_field_content_int(0, "Level", P_DATA[playerid][pLevel], SQL);
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Parola introdusa nu este corecta.\nTe rugam sa introduci parola acestui cont:", "Ok", "Close");
- }
- }
- stock getName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- if(!IsPlayerConnected(playerid)) name = "Unknown";
- else
- {
- GetPlayerName(playerid, name, MAX_PLAYER_NAME);
- format(name, sizeof(name), name);
- }
- return name;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement