Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #define MySQL_Servidor "localhost"
- #define MySQL_Usuario "root"
- #define MySQL_DB "myserver"
- #define MySql_PASSWORD ""
- #define DIALOG_LOGIN 1
- #define DIALOG_REGISTER 2
- enum info
- {
- id,
- password,
- };
- new t_Datos[MAX_PLAYERS][info];
- new MySQL:db_conection;
- main()
- {
- print("\n----------------------------------");
- print(" Bare Script\n");
- print("----------------------------------\n");
- }
- ///////////////////////////////////////////////////////////////////////////
- public OnGameModeInit()
- {
- SetGameModeText("Bare Script");
- AddPlayerClass(265,1958.3783,1343.1572,15.3746,270.1425,0,0,0,0,-1,-1);
- mysql_log(ALL);
- db_conection = mysql_connect(MySQL_Servidor, MySQL_Usuario, MySql_PASSWORD, MySQL_DB);
- if(mysql_errno(db_conection) != 0)
- {
- print("Base de dato NO conectada");
- mysql_close(db_conection);
- }
- else
- {
- print("Base de dato conectada");
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new string[150], nombre[MAX_PLAYER_NAME];
- GetPlayerName(playerid, nombre, MAX_PLAYER_NAME);
- mysql_format(db_conection, string, sizeof(string), "SELECT 'clave', 'id' FROM 'cuentas' WHERE nombre = '%s' LIMIT 1", nombre);
- mysql_tquery(db_conection, string, "CheckCuenta", "i", playerid);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_LOGIN:
- {
- if(!response) Kick(playerid);
- if(!strcmp(t_Datos[playerid][password], inputtext))
- {
- new string[150], nombre[MAX_PLAYER_NAME];
- GetPlayerName(playerid, nombre, MAX_PLAYER_NAME);
- mysql_format(db_conection, string, sizeof(string), "SELECT 'clave', 'id' FROM 'cuentas' WHERE nombre = '%s' LIMIT 1", nombre);
- mysql_tquery(db_conection, string, "LoadCuenta", "i", playerid);
- }
- }
- case DIALOG_REGISTER:
- {
- if(!response) Kick(playerid);
- new cadena[412], nombre[MAX_PLAYER_NAME];
- GetPlayerName(playerid, nombre, MAX_PLAYER_NAME);
- mysql_format(db_conection, cadena, sizeof(cadena), "INSERT INTO 'cuentas' ('nombre', 'clave') VALUES ('%s', '%s')", nombre, inputtext);
- mysql_tquery(db_conection, cadena, "RegisterCuenta", "i", playerid);
- }
- }
- return 1;
- }
- forward CheckCuenta(playerid);
- public CheckCuenta(playerid)
- {
- new filas;
- cache_get_row_count(filas);
- //cache_get_field_count(fields);
- if(filas)
- {
- cache_get_value_name(0, "clave", t_Datos[playerid][password], 129);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "logueate", "Login", "x");
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "registrate", "Register", "x");
- }
- return 1;
- }
- forward LoadCuenta(playerid);
- public LoadCuenta(playerid)
- {
- cache_get_value_name_int(2, "id", t_Datos[playerid][id]);
- SpawnPlayer(playerid);
- return 1;
- }
- forward RegisterCuenta(playerid);
- public RegisterCuenta(playerid)
- {
- t_Datos[playerid][id] = cache_insert_id();
- SpawnPlayer(playerid);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement