Advertisement
Shiny_

Untitled

May 6th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. local host = 'localhost'
  2. local user = 'shiny'
  3. local password = 'LSDRULEZ'
  4. local db = 'baza'
  5. local tablename = 'konta'
  6. local nick = 'Pseudonim'
  7. local pass = 'Haslo'
  8. local handler = mysql_connect(host, username, password, db)
  9.  
  10. function CreateTableInDatabase(res)
  11.     local create_database = mysql_query(handler, "CREATE TABLE IF NOT EXISTS `" ..tablename.. "` (`" ..nick.. "` varchar(255) DEFAULT NULL, `" ..pass.. "` varchar(255) DEFAULT NULL) ENGINE = MyISAM DEFAULT CHARSET = utf8;"
  12.     mysql_free_result(handler)
  13.     outputDebugString("Połączenie z bazą MySQL zostało pomyślnie zainicjowane.");
  14. end
  15. addEventHandler("onResourceStart", getRootElement(), CreateTableInDatabase)
  16.  
  17. addEventHandler("onPlayerJoin", getRootElement(), function()
  18.     triggerClientEvent(source, "onJoin", getRootElement())
  19. end)
  20.  
  21. function onLogin(player, user, pass)
  22.     local login = mysql_query(handler,"SELECT * FROM " ..tablename.. " WHERE " ..nick.. " = '"..mysql_escape_string(handler, user).."' AND " ..pass.. " = '"..mysql_escape_string(handler, sha256(pass)).."';")
  23.     if login
  24.     then
  25.         local rows = mysql_num_rows(login)
  26.         if rows == 1
  27.         then
  28.             triggerClientEvent(player, "closeWindow", getRootElement())
  29.             outputChatBox("Pomyślnie logujesz się na swoje konto.", player, 255, 255, 255)
  30.             spawnPlayer(player, 0,0,3)
  31.             fadeCamera(player, true)
  32.             setCameraTarget(player, player)
  33.         else outputChatBox("Próba zalogowania nie powiodła się.", player, 255, 255, 255)
  34.         end
  35.         mysql_free_result(login)
  36.     end
  37. end
  38. addEvent("onLogin", true)
  39. addEventHandler("onLogin", getRootElement(), onLogin)
  40.  
  41. addEventHandler("onResourceStop", root, function(resource)
  42.     mysql_close(handler)
  43.     outputDebugString("Połączenie z bazą MySQL zostało zakończone.")
  44. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement