Jump to content

Quebec

Members
  • Posts

    17
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Quebec's Achievements

Square

Square (6/54)

2

Reputation

  1. Oh, thanks. Will keep that in mind!
  2. Alright, thank you for the tip! You've helped me a lot. :D
  3. -1 for dbPoll can cause freeze on the server? should I give an actual value in miliseconds rather than -1?
  4. This actually works! Thanks man! But I really want to understand the issue if you don't mind... so when I put a non existing username the "if result then" statement was true because i got an empty table and it ran the for loop?
  5. yes, that's what im testing it with. I want the code to trigger 'account:noaccount' when no such username is found.
  6. I'm coming back with another question, I've been struggling for like 3 hours with this one. I'm trying to get an error message when I press the login button if username or password is incorrect. Maybe it's a typo but I can't find it. Here's the code: Client Side loadstring(exports.dgs:dgsImportFunction())() local screenW, screenH = guiGetScreenSize() local camerapos1 = Vector3(1324.3000488281, 231.19999694824, 19.10000038147) local camerapos2 = Vector3(1473.5, 319.10000610352, 60) function triggerLogin() setCameraMatrix(camerapos1, camerapos2) guiSetInputEnabled(true) setTimer(function() fadeCamera(true) showCursor(true) showChat(true) setPlayerHudComponentVisible('all', false) loginMenu() end, 1500, 1) end addEventHandler('onClientResourceStart', resourceRoot, triggerLogin) function loginMenu() loginwindow = dgsCreateWindow((screenW - 317) / 2, (screenH - 371) / 2, 317, 371, "Bun venit pe server!", false, nil, nil, nil, nil, nil, nil, nil, true) dgsWindowSetMovable(loginwindow, false) dgsWindowSetSizable(loginwindow, false) loginedit1 = dgsCreateEdit(89, 65, 205, 33, "", false, loginwindow) loginedit2 = dgsCreateEdit(89, 122, 205, 33, "", false, loginwindow) dgsEditSetMasked(loginedit2, true) loginlabel1 = dgsCreateLabel(10, 68, 74, 30, "Username:", false, loginwindow) loginlabel2 = dgsCreateLabel(10, 125, 74, 30, "Password:", false, loginwindow) logintemplabel = dgsCreateLabel(20, 165, 281, 17, "", false, loginwindow) dgsLabelSetHorizontalAlign(logintemplabel, "center", true) loginbutonlogin = dgsCreateButton(0, 305, 159, 41, "Logheaza-te", false, loginwindow) loginbutonregister = dgsCreateButton(159, 305, 158.5, 41, "Inregistreaza-te", false, loginwindow) addEventHandler('onDgsMouseClick', loginbutonregister, function(button, state) if button == "left" and state == "down" then destroyElement(loginwindow) registerMenu() end end, false) addEventHandler('onDgsMouseClick', loginbutonlogin, function(button, state) if button == "left" and state == "down" then validateLoginData() end end, false) end function registerMenu() registerwindow = dgsCreateWindow((screenW - 317) / 2, (screenH - 371) / 2, 317, 371, "Bun venit pe server!", false, nil, nil, nil, nil, nil, nil, nil, true) dgsWindowSetMovable(registerwindow, false) dgsWindowSetSizable(registerwindow, false) registeredit1 = dgsCreateEdit(89, 65, 205, 33, "", false, registerwindow) registeredit2 = dgsCreateEdit(89, 122, 205, 33, "", false, registerwindow) registeredit3 = dgsCreateEdit(89, 180, 205, 33, "", false, registerwindow) dgsEditSetMasked(registeredit2, true) registerlabel1 = dgsCreateLabel(10, 68, 74, 30, "Username:", false, registerwindow) registerlabel2 = dgsCreateLabel(10, 125, 74, 30, "Password:", false, registerwindow) registerlabel3 = dgsCreateLabel(10, 183, 74, 30, "Email:", false, registerwindow) registerbutonlogin = dgsCreateButton(0, 305, 159, 41, "Logheaza-te", false, registerwindow) registerbutonregister = dgsCreateButton(159, 305, 158.5, 41, "Inregistreaza-te", false, registerwindow) registertemplabel = dgsCreateLabel(20, 223, 281, 17, "", false, registerwindow) dgsLabelSetHorizontalAlign(registertemplabel, "center", true) addEventHandler('onDgsMouseClick', registerbutonlogin, function(button, state) if button == "left" and state == "down" then destroyElement(registerwindow) loginMenu() end end, false) addEventHandler('onDgsMouseClick', registerbutonregister, function(button, state) if button == "left" and state == "down" then validateRegisterData() end end, false) end function validateRegisterData() local username = dgsGetText(registeredit1) local password = dgsGetText(registeredit2) local email = dgsGetText(registeredit3) if username == "" or password == "" or email == "" then dgsLabelSetColor(registertemplabel, 255, 100, 100, 255) dgsSetText(registertemplabel, "Completeaza toate spatiile!") return false end if string.len(username) < 3 then dgsLabelSetColor(registertemplabel, 255, 100, 100, 255) dgsSetText(registertemplabel, "Numele trebuie sa fie mai mare de 3 caractere!") return false elseif string.len(password) < 6 then dgsLabelSetColor(registertemplabel, 255, 100, 100, 255) dgsSetText(registertemplabel, "Parola trebuie sa fie mai mare de 6 caractere!") return false elseif email == "" then dgsLabelSetColor(registertemplabel, 255, 100, 100, 255) dgsSetText(registertemplabel, "Introduce un email!") return false end triggerServerEvent("account:register", localPlayer, localPlayer, username, password, email) end addEvent('account:alreadyname', true) addEventHandler('account:alreadyname', root, function() dgsLabelSetColor(registertemplabel, 255, 100, 100, 255) dgsSetText(registertemplabel, "Un cont cu acest nume exista deja!") end) addEvent('account:succesfulregister', true) addEventHandler('account:succesfulregister', root, function() dgsLabelSetColor(registertemplabel, 100, 255, 100, 255) dgsSetText(registertemplabel, "Contul a fost creat cu succes!") end) function validateLoginData() local username = dgsGetText(loginedit1) local password = dgsGetText(loginedit2) if username == "" or password == "" then dgsLabelSetColor(logintemplabel, 255, 100, 100, 255) dgsSetText(logintemplabel, "Completeaza toate spatiile!") return false end triggerServerEvent("account:login", localPlayer, localPlayer, username, password) end ---PROBLEM addEvent('account:noaccount', true) addEventHandler('account:noaccount', root, function() dgsLabelSetColor(logintemplabel, 255, 100, 100, 255) dgsSetText(logintemplabel, "Nu exista acest cont!") end) ---PROBLEM addEvent('account:succesfullogin', true) addEventHandler('account:succesfullogin', root, function() dgsLabelSetColor(logintemplabel, 100, 255, 100, 255) dgsSetText(logintemplabel, "Ai fost logat cu succes!") end) addEvent('account:switchcamera', true) addEventHandler('account:switchcamera', root, function() setTimer(function() destroyElement(loginwindow) guiSetInputEnabled(false) showCursor(false) showChat(true) setPlayerHudComponentVisible('all', true) setCameraTarget(localPlayer, localPlayer) end, 3000, 1) end) Server Side local db = exports.mysqlconnection:getConnection() addEvent("account:register", true) addEventHandler("account:register", root, function(thePlayer, username, password, email) if not username or not password then return false end local queryCheck = dbQuery(db, "SELECT * FROM `accounts` WHERE `username` = '" .. username .. "'") local result = dbPoll(queryCheck, -1) if #result > 0 then return triggerClientEvent(thePlayer, "account:alreadyname", thePlayer) end local playerIp = getPlayerIP(thePlayer) local playerSerial = getPlayerSerial(thePlayer) local passHash = passwordHash(password, "bcrypt", {}) dbExec(db, "INSERT INTO `accounts` (`username`, `password`, `ip`, `serial`, `email`) VALUES (?, ?, ?, ?, ?)", username, passHash, playerIp, playerSerial, email) triggerClientEvent(thePlayer, 'account:succesfulregister', thePlayer) end) addEvent("account:login", true) addEventHandler("account:login", root, function(thePlayer, username, password) if not username or not password then return false end local queryCheck = dbQuery(db, "SELECT * FROM `accounts` WHERE `username` = '" .. username .. "'") local result = dbPoll(queryCheck, -1) if result then for k, row in ipairs(result) do local hashedPassword = row["password"] if passwordVerify(password, hashedPassword) then triggerClientEvent(thePlayer, 'account:succesfullogin', thePlayer) setElementData(thePlayer, "account:id", row["id"]) setElementData(thePlayer, "account:username", row["username"]) setElementData(thePlayer, "account:email", row["email"]) setElementData(thePlayer, "account:ip", row["ip"]) setElementData(thePlayer, "account:serial", row["serial"]) setTimer(function() spawnPlayer(thePlayer, 1245.1999511719, 332.5, 19.200000762939) triggerClientEvent(thePlayer, 'account:switchcamera', thePlayer) end, 2900, 1) end end else --this is where I dont get anything in return (tried putting outputconsole of an error message but i dont get that either) return triggerClientEvent(thePlayer, 'account:noaccount', thePlayer) end end) Red area is where dgs label should appear. All other labels work.
  7. Didn't even notice that, it's a typo. Lemme check if this works. Works like a charm, thanks a lot!
  8. Client side script: addEventHandler('onClientResourceStart', root, function() setCameraMatrix (0, 0, 100, 0, 100, 50) fadeCamera(true) end) function validateRegisterData(command, username, password) if username == "" or password == "" then return outputChatBox("SINTAXA:", 255, 100, 100) end if string.len(username) < 3 then return outputChatBox("Numele trebuie sa fie mai mare de 3 caractere!", 255, 100, 100) elseif string.len(password) < 6 then return outputChatBox("Parola trebuie sa fie mai mare de 6 caractere!", 255, 100, 100) end triggerServerEvent('accountsystem:register', localPlayer, localPlayer, username, password) end addCommandHandler('registeraccount', validateRegisterData) function validateLoginData(command, username, password) if username == "" or password == "" then return outputChatBox("Umple toate spatiile!", 255, 100, 100) end triggerServerEvent('accountsystem:login', localPlayer, loginPlayer, username, password) end addCommandHandler('loginaccount', validateLoginData) addEvent('accountsystem:schimbacamera', true) addEventHandler('accountsystem:schimbacamera', root, function() setCameraTarget(localPlayer, localPlayer) end) Server side script: local db = exports.mysqlconnection:getConnection() addEvent('accountsystem:register', true) addEventHandler('accountsystem:register', root, function(thePlayer, username, password) if not username or not password then return false end local queryCheck = dbQuery(db, "SELECT * FROM `accounts` WHERE `username` = '" .. username .. "'") local result = dbPoll(queryCheck, -1) if #result > 0 then return outputChatBox("Acest nume este deja folosit!", thePlayer) end local playerIP = getPlayerIP(thePlayer) local hash = passwordHash(password, "bcrypt", {}) dbExec(db, "INSERT INTO `accounts` (`username`, `password`, `ip`) VALUES (?, ?, ?)", username, hash, playerIP) outputChatBox("Contul a fost creat cu succes!", thePlayer, 100, 255, 100) end) addEvent('accountsystem:login', true) addEventHandler('accountsystem:login', root, function(thePlayer, username, password) if not username or not password then return false end local queryCheck = dbQuery(db, "SELECT * FROM `accounts` WHERE `username` = '" .. username .. "'") local result = dbPoll(queryCheck, -1) if result then for k, row in ipairs(result) do local hashedPassword = row["password"] setElementData(thePlayer, "account:id", row["id"]) setElementData(thePlayer, "account:ip", row["ip"]) setElementData(thePlayer, "account:username", row["username"]) if passwordVerify(password, hashedPassword) then outputChatBox("Ai fost autentificat cu succes!", thePlayer, 100, 255, 100) spawnPlayer(thePlayer, 0, 5, 5) triggerClientEvent(thePlayer, 'accountsystem:schimbacamera', thePlayer) else outputChatBox("Contul/Parola sunt incorecte!", thePlayer, 255, 100, 100) end end else return outputChatBox("Acest cont nu exista!", thePlayer, 255, 100, 100) end end)
  9. Hey, I'm trying to make a very basic login system just for learning and I'm trying to pass the player to the function but i don't know how. Error I get is: line 25 "Bad argument @ setElementData: [Expected element as argument 1, got nil]". Here's the code: addEvent('accountsystem:login', true) addEventHandler('accountsystem:login', root, function(thePlayer, username, password) if not username or not password then return false end local queryCheck = dbQuery(db, "SELECT * FROM `accounts` WHERE `username` = '" .. username .. "'") local result = dbPoll(queryCheck, -1) if result then for k, row in ipairs(result)do local hashedPassword = row["password"] if passwordVerify(password, hashedPassword) then outputChatBox("Ai fost autentificat cu succes!", thePlayer, 100, 255, 100) setElementData(thePlayer, "account:id", row["id"]) setElementData(thePlayer, "account:ip", row["ip"]) setElementData(thePlayer, "account:username", row["username"]) spawnPlayer(thePlayer, 0, 5, 5) triggerClientEvent(thePlayer, 'accountsystem:schimbacamera', thePlayer) else outputChatBox("Contul/Parola sunt incorecte!", thePlayer, 255, 100, 100) end end end end)
  10. Thank you for your answer, it works. I'm pretty new to MySQL so I didn't know how to approach this.
  11. I tried it yet it gives me a wrong result. The value in database is set to 1 (true) and in game I get the message from FALSE ouputChatBox. I know that # operator measures the length of the variable but is there a way to identify the actual value of it?
  12. This could be a very basic question but I don't know where to search the answer so I came here. In the MySQL database I have a table called accounts and I want to get value from hascharacter column (tinyint value, 0 to 1)which is located inside accounts. After that I want to check if it is true but I don't know how. Here is the code: local hasCharacter = tonumber(hasCharacter) local verificationQuery = dbQuery(db, "SELECT `hascharacter` FROM `accounts` WHERE `hascharacter` = '" .. hasCharacter .. "'") local verificationResult = dbPoll(verificationQuery, -1) if verificationResult > 0 then --this is the line which I don't know how to use properly outputChatBox('Verification value is TRUE', thePlayer, 100, 255, 100) else outputChatBox('Verification value is FALSE', thePlayer, 255, 100, 100) end
  13. I checked the database connection code again and I found the error, dbConnect had some faulty arguments. Problem got fixed, thank you!
  14. Actually I think this could be an issue, I'll check when I get back home if everything is alright in the mysql connection
  15. I'm trying to make a login system but I keep getting this error: WARNING: login-panel\login_panel_s.lua:9: dbPoll failed; No database selected ERROR: login-panel\login_panel_s.lua:10: attempt to get length of local 'result' (a boolean value) This is the code: local db = exports.dbconnection:getConnection() addEvent('login:registerAccount', true) addEventHandler('login:registerAccount', root, function(thePlayer, username, password, email) if not username or not password or not email then return false end local queryCheck = dbQuery(db, "SELECT * FROM `accounts` WHERE `username` = '" .. username .. "'") local result = dbPoll(queryCheck, -1) if #result > 0 then return outputChatBox("Acest username exista deja!") end local mtaserial = getPlayerSerial(thePlayer) local playerIP = getPlayerIP(thePlayer) local hash = passwordHash(password, "bcrypt", {}) if hash then dbExec(db, "INSERT INTO `accounts` (`username`, `password`, `ip`, `mtaserial`, `email`) VALUES (?, ?, ?, ?, ?)", username, hash, ip, mtaserial, email) outputChatBox("Contul a fost creat cu succes", thePlayer) end end)
×
×
  • Create New...