iiv03 Posted August 13, 2018 Share Posted August 13, 2018 (edited) My problem is if a player writes his user name and password and clicks on Login : Account or Password error If the player clicks on the registration, his / her account is not registered Client : GUIEditor = { edit = {}, window = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(186, 56, 945, 607, "× [ Login Panel ] ×", false) guiWindowSetSizable(GUIEditor.window[1], false) register = guiCreateButton(714, 516, 115, 48, "Register", false, GUIEditor.window[1]) guiSetVisible(GUIEditor.window[1],false) Login = guiCreateButton(714, 458, 115, 48, "Login", false, GUIEditor.window[1]) user = guiCreateEdit(503, 304, 326, 33, "", false, GUIEditor.window[1]) guiEditSetMasked(pass, true) Password = guiCreateEdit(503, 247, 326, 33, "", false, GUIEditor.window[1]) end ) function Open ( ) guiSetVisible(GUIEditor.window[1], not guiGetVisible(GUIEditor.window[1])) showCursor(guiGetVisible(GUIEditor.window[1])) end bindKey("F10","down",Open) addEvent("onPutSave",true) addEventHandler("onPutSave",root, function (puser,ppass) guiSetText(user,puser) guiSetText(pass,ppass) end ) addEventHandler("onClientGUIClick",root, function () local user = guiGetText(user) local pass = guiGetText(pass) if ( source == Login ) then if user ~= "" and pass ~= "" then if guiCheckBoxGetSelected(remember) then triggerServerEvent("onLoginWith",localPlayer,user,pass) else triggerServerEvent("onLogin",localPlayer,user,pass) end else outputChatBox("* You Must Write Username Or Password",255,0,0) end elseif ( source == Register ) then if user ~= "" and pass ~= "" then triggerServerEvent("onReg",localPlayer,user,pass) else outputChatBox("* You Must Write Username Or Password",255,0,0) end end end ) Server : executeSQLQuery("CREATE TABLE IF NOT EXISTS players_save( serial TEXT, user TEXT, pass TEXT)") function AddPlayer(serial,user,pass) executeSQLQuery("INSERT INTO players_save(serial,user,pass) VALUES(?,?,?)",serial,user,pass) end function isPlayerSave(serial) local sel = executeSQLQuery("SELECT serial FROM players_save WHERE serial=?",serial) if sel == 0 then return false else return true end end function getUserAndPass(serial) local user,pass = "","" if isPlayerSave(serial) then local sel = executeSQLQuery("SELECT * FROM players_save WHERE serial=?",serial) for i,player in ipairs(sel) do if i == 1 then user = player.user pass = player.pass end end return user,pass end return false end addEvent("onGetSave",true) addEventHandler("onGetSave",root, function () local serial = getPlayerSerial(source) if isPlayerSave(serial) then local user,pass = getUserAndPass(serial) triggerClientEvent(source,"onPutSave",source,user,pass) end end ) addEvent("onLoginWith",true) addEventHandler("onLoginWith",root, function (user,pass) local acc = getAccount(user,pass) local serial = getPlayerSerial(source) if acc then logIn(source,acc,pass) outputChatBox("Login successfully*",source,0,255,0) AddPlayer(serial,user,pass) triggerClientEvent(source,"onCl",source) else outputChatBox("Account or password error*",source,255,0,0) end end ) addEvent("onLogin",true) addEventHandler("onLogin",root, function (user,pass) local acc = getAccount(user,pass) if acc then logIn(source,acc,pass) outputChatBox("Login successfully*",source,0,255,0) triggerClientEvent(source,"onCl",source) else outputChatBox("Account or password error*",source,255,0,0) end end ) addEvent("onReg",true) addEventHandler("onReg",root, function (user,pass) local acc = getAccount(user,pass) if acc then outputChatBox("This account is already used",source,255,0,0) else addAccount(user,pass) outputChatBox("* Username = " .. user .. "",source,0,255,0) outputChatBox("* Password = " .. pass .. "",source,0,255,0) end end ) Edited August 13, 2018 by liwahadri Link to comment
Administrators Lpsd Posted August 13, 2018 Administrators Share Posted August 13, 2018 (edited) Your event handling is all wrong. Do not pass the local player as an argument to the event like this: triggerServerEvent("onLoginWith",localPlayer,user,pass) Things wrong here: - you're making the source element the local player, that will not work - you're trying to pass the local player as an argument You should use the predefined variable `client` on the serverside. `client` contains the player that called the event. This is for security purposes. You should also set the source argument to resourceRoot, instead of localPlayer So you'd have: triggerServerEvent("onLoginWith", resourceRoot, pass) addEventHandler("onLoginWith", root, function(pass) local user = client ... end) Now in the rest of your code where you've tried to use 'source' to get the player, replace it with client. Edited August 13, 2018 by LopSided_ Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now