Jump to content

login script


FlyingSpoon

Recommended Posts

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
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
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

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
 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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...