Advertisement
GranaT3

Registro FS

Jan 3rd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. #define MySQL_Servidor "localhost"
  5. #define MySQL_Usuario "root"
  6. #define MySQL_DB "myserver"
  7. #define MySql_PASSWORD ""
  8.  
  9. #define DIALOG_LOGIN 1
  10. #define DIALOG_REGISTER 2
  11.  
  12. enum info
  13. {
  14. id,
  15. password,
  16. };
  17. new t_Datos[MAX_PLAYERS][info];
  18.  
  19. new MySQL:db_conection;
  20.  
  21. main()
  22. {
  23. print("\n----------------------------------");
  24. print(" Bare Script\n");
  25. print("----------------------------------\n");
  26. }
  27.  
  28.  
  29. ///////////////////////////////////////////////////////////////////////////
  30.  
  31. public OnGameModeInit()
  32. {
  33. SetGameModeText("Bare Script");
  34. AddPlayerClass(265,1958.3783,1343.1572,15.3746,270.1425,0,0,0,0,-1,-1);
  35.  
  36. mysql_log(ALL);
  37.  
  38. db_conection = mysql_connect(MySQL_Servidor, MySQL_Usuario, MySql_PASSWORD, MySQL_DB);
  39.  
  40. if(mysql_errno(db_conection) != 0)
  41. {
  42. print("Base de dato NO conectada");
  43. mysql_close(db_conection);
  44. }
  45. else
  46. {
  47. print("Base de dato conectada");
  48. }
  49.  
  50. return 1;
  51. }
  52.  
  53.  
  54. public OnPlayerConnect(playerid)
  55. {
  56. new string[150], nombre[MAX_PLAYER_NAME];
  57. GetPlayerName(playerid, nombre, MAX_PLAYER_NAME);
  58.  
  59. mysql_format(db_conection, string, sizeof(string), "SELECT 'clave', 'id' FROM 'cuentas' WHERE nombre = '%s' LIMIT 1", nombre);
  60. mysql_tquery(db_conection, string, "CheckCuenta", "i", playerid);
  61.  
  62. return 1;
  63. }
  64.  
  65. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  66. {
  67. switch(dialogid)
  68. {
  69. case DIALOG_LOGIN:
  70. {
  71. if(!response) Kick(playerid);
  72. if(!strcmp(t_Datos[playerid][password], inputtext))
  73. {
  74. new string[150], nombre[MAX_PLAYER_NAME];
  75. GetPlayerName(playerid, nombre, MAX_PLAYER_NAME);
  76. mysql_format(db_conection, string, sizeof(string), "SELECT 'clave', 'id' FROM 'cuentas' WHERE nombre = '%s' LIMIT 1", nombre);
  77. mysql_tquery(db_conection, string, "LoadCuenta", "i", playerid);
  78.  
  79. }
  80.  
  81. }
  82.  
  83. case DIALOG_REGISTER:
  84. {
  85. if(!response) Kick(playerid);
  86.  
  87. new cadena[412], nombre[MAX_PLAYER_NAME];
  88. GetPlayerName(playerid, nombre, MAX_PLAYER_NAME);
  89.  
  90. mysql_format(db_conection, cadena, sizeof(cadena), "INSERT INTO 'cuentas' ('nombre', 'clave') VALUES ('%s', '%s')", nombre, inputtext);
  91. mysql_tquery(db_conection, cadena, "RegisterCuenta", "i", playerid);
  92. }
  93. }
  94.  
  95. return 1;
  96. }
  97.  
  98. forward CheckCuenta(playerid);
  99. public CheckCuenta(playerid)
  100. {
  101. new filas;
  102. cache_get_row_count(filas);
  103. //cache_get_field_count(fields);
  104.  
  105. if(filas)
  106. {
  107. cache_get_value_name(0, "clave", t_Datos[playerid][password], 129);
  108. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "logueate", "Login", "x");
  109.  
  110. }
  111. else
  112. {
  113. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "registrate", "Register", "x");
  114.  
  115. }
  116.  
  117.  
  118. return 1;
  119. }
  120.  
  121. forward LoadCuenta(playerid);
  122. public LoadCuenta(playerid)
  123. {
  124. cache_get_value_name_int(2, "id", t_Datos[playerid][id]);
  125. SpawnPlayer(playerid);
  126.  
  127.  
  128. return 1;
  129. }
  130.  
  131.  
  132. forward RegisterCuenta(playerid);
  133. public RegisterCuenta(playerid)
  134. {
  135. t_Datos[playerid][id] = cache_insert_id();
  136. SpawnPlayer(playerid);
  137.  
  138.  
  139. return 1;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement