FlyingSpoon Posted February 12, 2017 Share Posted February 12, 2017 serverContainer.loginClient = function(user, pass) local qh = dbQuery(serverContainer.connection,'SELECT * FROM mybb_users WHERE username = ?',user) local result, row, errmsg = dbPoll ( qh, 5000 ) if row < 0 then for id, result in ipairs(result) do local salt = result['salt'] local username = result['username'] local password = result['password'] if salt and username and password then local newPass = md5(md5(salt):lower()..md5(pass):lower()):lower() if newPass == password then triggerClientEvent(source,'onClientSuccessfullyLogin',source) userData("success", player, user, pass) end end end end end addEvent('onClientLogins', true) addEventHandler('onClientLogins', root, serverContainer.loginClient) 'if row <0' : Attempt to compare number with nill - Server lags, and times out each time someone logs in. Any ideas? Link to comment
NeXuS™ Posted February 12, 2017 Share Posted February 12, 2017 If you set the dbPoll's timeout to -1, will it run? Link to comment
FlyingSpoon Posted February 13, 2017 Author Share Posted February 13, 2017 Yeah it runs, still crashes the server. Just freezes. Link to comment
NeXuS™ Posted February 13, 2017 Share Posted February 13, 2017 function serverContainer.loginClient(user, pass) local qh = dbQuery(serverContainer.connection,'SELECT * FROM mybb_users WHERE username = ?',user) local result, row, errmsg = dbPoll ( qh, 5000 ) end addEvent('onClientLogins', true) addEventHandler('onClientLogins', root, serverContainer.loginClient) Try this one, and reply if it's still crashing it. Link to comment
pa3ck Posted February 14, 2017 Share Posted February 14, 2017 17 hours ago, Patrik91 said: function serverContainer.loginClient(user, pass) local qh = dbQuery(serverContainer.connection,'SELECT * FROM mybb_users WHERE username = ?',user) local result, row, errmsg = dbPoll ( qh, 5000 ) end addEvent('onClientLogins', true) addEventHandler('onClientLogins', root, serverContainer.loginClient) Try this one, and reply if it's still crashing it. 5 sec timeout? What for? That's loads, wiki: timeout: How many milliseconds to wait for a result. Use 0 for an instant response (which may return nil). Use -1 to wait until a result is ready. Note: A wait here will freeze the entire server just like the executeSQL* functions Link to comment
FlyingSpoon Posted February 15, 2017 Author Share Posted February 15, 2017 I've used -1 too, still lags out the server. And there's not outputs to the debug either. It works perfectly fine for 1 or 2 players. But once 3+ players join and they click on 'Login' nothing actually happens, and it just crashes the server. I have a pretty powerful host, so I know host isn't an issue. Link to comment
pa3ck Posted February 15, 2017 Share Posted February 15, 2017 (edited) Okay, what about this: dbQuery( function(qh) local result = dbPoll( qh, 0 ) outputChatBox("Result: " .. #result) end , connection, "SELECT * FROM mybb_users WHERE username = ?", user ) Edited February 15, 2017 by pa3ck Link to comment
FlyingSpoon Posted February 15, 2017 Author Share Posted February 15, 2017 Don't work But result is returned as 0 when logged in Link to comment
xeon17 Posted February 15, 2017 Share Posted February 15, 2017 serverContainer.loginClient = function(user, pass) connection:query(function(result) local result = result:poll(0) for _,row in pairs(result) do local salt = row.salt local username = row.username local password = row.password print("Username: "..username..", Password: "..password.."") if salt and username and password then local newPass = md5(md5(salt):lower()..md5(pass):lower()):lower() if newPass == password then triggerClientEvent(source,'onClientSuccessfullyLogin',source) userData("success", player, user, pass) end end end end, "SELECT * FROM mybb_users WHERE username = ?", user) end addEvent('onClientLogins', true) addEventHandler('onClientLogins', root, serverContainer.loginClient) Link to comment
FlyingSpoon Posted February 16, 2017 Author Share Posted February 16, 2017 (Line 2) attempt to index global 'connection' (a userdata value) Link to comment
xeon17 Posted February 16, 2017 Share Posted February 16, 2017 Enable OOP or replace query with dbQuery <oop>true</oop> Link to comment
1B0Y Posted February 21, 2017 Share Posted February 21, 2017 serverContainer.loginClient = function(user,pass) if not serverContainer.connection then error("No DB connection to query.") end serverContainer.connection:query( function(query) local results = query:poll(0) for _,row in pairs(results) do local salt = row.salt local username = row.username local password = row.password print("Username:"..username..",Password:"..password.."") if salt and username and password then local newPass = md5(md5(salt):lower()..md5(pass):lower()):lower() if newPass == password then triggerClientEvent(source,'onClientSuccessfullyLogin',source) userData("success",player,user,pass) end end end end,"SELECT * FROM mybb_users WHERE username=?",user ) end addEvent('onClientLogins',true) addEventHandler('onClientLogins',root,serverContainer.loginClient) The problem was that you weren't taking advantage of callbacks. using dbPoll(query,-1) locks up the server until the MySQL query is completed. Callbacks doesn't have the lockup effect. Also - you were missing serverContainer.connection, hence the error above. 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