Facebook
From Sole Wigeon, 4 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 61
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. new MySQL:m_sql;
  5. new samp[500];
  6.  
  7. main(){}
  8.  
  9. public OnGameModeInit()
  10. {
  11.         if(!MySQL_Init()) return printf("[MySQL] Error while trying to connect with database. [ID: %d].", mysql_errno(m_sql));
  12.         else print("[MySQL] Successfully connected to the database.");
  13.  
  14.         return 1;
  15. }
  16.  
  17. public OnPlayerConnect(playerid)
  18. {
  19.         mysql_format(m_sql, samp, sizeof(samp), "SELECT * FROM `players` WHERE `player_name` LIKE BINARY '%s'", GetPlayerNick(playerid));
  20.         mysql_query(m_sql, samp, true);
  21.         new rows = cache_num_rows();
  22.         if(rows)
  23.         {
  24.                 format(samp, sizeof(samp), "Witaj na serwerze %s.nnWpisz swoje haslo aby sie zalogowac", GetPlayerNick(playerid));
  25.                 ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Logowanie", samp, "Wyjdz", "zaloguj");
  26.         } else {
  27.                 format(samp, sizeof(samp), "Witaj na serwerze %s.nnWpisz swoje haslo aby sie ZAREJESTROWAC", GetPlayerNick(playerid));
  28.                 ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "REJESTRACJA", samp, "Wyjdz", "REJESTRUJ");
  29.         }
  30.  
  31.         return 1;
  32. }
  33.  
  34. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  35. {
  36.         if(dialogid == 2)
  37.         {
  38.                 if(response == 1)
  39.                 {
  40.                         mysql_format(m_sql, samp, sizeof(samp), "SELECT `player_password` FROM `players` WHERE `player_name` LIKE BINARY '%s'", GetPlayerNick(playerid));
  41.             mysql_query(m_sql, samp, true);
  42.  
  43.             new haslo[25];
  44.             cache_get_value_name(0, "haslo", haslo);
  45.             if(strcmp(haslo, inputtext))
  46.             {
  47.                 ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Niepoprawne", "niepoprawne haslo", "loguj", "wyjc");
  48.                 return 1;
  49.             }
  50.             TogglePlayerSpectating(playerid, 0);
  51.             SpawnPlayer(playerid);
  52.                 }
  53.                 else
  54.                 {
  55.                         Kick(playerid);
  56.                 }
  57.  
  58.         }
  59.  
  60.         if(dialogid == 1)
  61.         {
  62.                 if(response == 1)
  63.                 {
  64.                         if(strlen(inputtext) <= 2 || strlen(inputtext) >= 21)
  65.                         return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "REJESTRACJA", "rejestracja", "rejestruj", "wyjc");
  66.  
  67.                         mysql_format(m_sql, samp, sizeof(samp), "INSERT INTO `players` SET `player_name` = '%s', `player_password` = '%s'", GetPlayerNick(playerid), inputtext);
  68.                         mysql_query(m_sql, samp, true);
  69.  
  70.                         TogglePlayerSpectating(playerid, 0);
  71.                         SpawnPlayer(playerid);
  72.  
  73.                 } else {
  74.                         Kick(playerid);
  75.                 }
  76.                 return 1;
  77.         }
  78.         return 1;
  79. }
  80.  
  81. stock MySQL_Init()
  82. {
  83.         mysql_log();
  84.         m_sql = mysql_connect_file("mysql.ini");
  85.         if(m_sql == MYSQL_INVALID_HANDLE || mysql_errno(m_sql) != 0) return false;
  86.         else return true;
  87. }
  88.  
  89. stock GetPlayerNick(playerid)
  90. {
  91.     new name[MAX_PLAYER_NAME+1];
  92.     GetPlayerName(playerid, name, sizeof(name));
  93.     return name;
  94. }