Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local host = 'localhost'
- local user = 'shiny'
- local password = 'LSDRULEZ'
- local db = 'baza'
- local tablename = 'konta'
- local nick = 'Pseudonim'
- local pass = 'Haslo'
- local handler = mysql_connect(host, username, password, db)
- function CreateTableInDatabase(res)
- 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;"
- mysql_free_result(handler)
- outputDebugString("Połączenie z bazą MySQL zostało pomyślnie zainicjowane.");
- end
- addEventHandler("onResourceStart", getRootElement(), CreateTableInDatabase)
- addEventHandler("onPlayerJoin", getRootElement(), function()
- triggerClientEvent(source, "onJoin", getRootElement())
- end)
- function onLogin(player, user, pass)
- local login = mysql_query(handler,"SELECT * FROM " ..tablename.. " WHERE " ..nick.. " = '"..mysql_escape_string(handler, user).."' AND " ..pass.. " = '"..mysql_escape_string(handler, sha256(pass)).."';")
- if login
- then
- local rows = mysql_num_rows(login)
- if rows == 1
- then
- triggerClientEvent(player, "closeWindow", getRootElement())
- outputChatBox("Pomyślnie logujesz się na swoje konto.", player, 255, 255, 255)
- spawnPlayer(player, 0,0,3)
- fadeCamera(player, true)
- setCameraTarget(player, player)
- else outputChatBox("Próba zalogowania nie powiodła się.", player, 255, 255, 255)
- end
- mysql_free_result(login)
- end
- end
- addEvent("onLogin", true)
- addEventHandler("onLogin", getRootElement(), onLogin)
- addEventHandler("onResourceStop", root, function(resource)
- mysql_close(handler)
- outputDebugString("Połączenie z bazą MySQL zostało zakończone.")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement