aka Blue Posted August 18, 2015 Share Posted August 18, 2015 (edited) Buenas, tras quitar el módulo de sha.so de MTA Paradise el cual no iba ya que era 32 bits y mi servidor era 64 bits, estaba haciendo el nuevo registro y logueo pero ahora tengo un problema con el logueo. El registro va bien, se almacena el usuario y la contraseña pero en el logueo, no loguea básicamente. Ésto es el registro addEvent( getResourceName( resource ) .. ":register", true ) addEventHandler( getResourceName( resource ) .. ":register", root, function( username, password ) if source == client then if allowRegistration then if username and password then username = trim( username ) password = trim( password ) -- client length checks are the same if #username >= 3 and #password >= 8 then -- see if that username is free at all local info = exports.sql:query_assoc_single( "SELECT COUNT(userID) AS usercount FROM wcf1_user WHERE username = '%s'", username, password ) if not info then triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 1 ) elseif info.usercount == 0 then -- generate a salt (SHA1) -- create the user if exports.sql:query_free("INSERT INTO wcf1_user (username, password) VALUES ('%s', '%s')", username, password) then triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 0 ) -- will automatically login when this is sent else triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 4 ) end else triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 3 ) end else -- shouldn't happen triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 1 ) end else -- can't do much without a username and password triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 1 ) end else triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 2, registrationErrorMessage ) end end end ) Éste es el logueo, lo que da problemas. addEvent( getResourceName( resource ) .. ":login", true ) addEventHandler( getResourceName( resource ) .. ":login", root, function( username, password ) if source == client then triedTokenAuth[ source ] = true if username and password and #username > 0 and #password > 0 then local info = exports.sql:query_assoc_single( "SELECT username, password FROM wcf1_user WHERE username = '%s'", username) p[ source ] = nil if not info then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 1 ) -- Wrong username/password loginAttempts[ source ] = ( loginAttempts[ source ] or 0 ) + 1 else loginAttempts[ source ] = nil performLogin( source, info.token, true ) end end end end ) function performLogin( source, token, isPasswordAuth, ip ) if source and ( isPasswordAuth or not triedTokenAuth[ source ] ) then triedTokenAuth[ source ] = true if token then if #token == 80 then local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username = '%s'") p[ source ] = nil if not info then if isPasswordAuth then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 1 ) -- Wrong username/password end return false else if info.banned == 1 then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 2 ) -- Banned return false elseif info.activationCode > 0 then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 3 ) -- Requires activation return false else -- check if another user is logged in on that account for player, data in pairs( p ) do if data.userID == info.userID then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 5 ) -- another player with that account found return false end end local username = info.username p[ source ] = { userID = info.userID, username = username, options = info.userOptions and fromJSON( info.userOptions ) or { } } -- check for admin rights aclUpdate( source, true ) -- show characters local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" ) local chars2 = exports.sql:query_assoc( "SELECT COUNT(*) AS count FROM characters WHERE userID = ".. info.userID .."" ) if chars2 then for key, value in ipairs( chars2 ) do --(value.count < 3) then local cuenta = value.count end end local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" ) p[source].cuenta = #chars if isPasswordAuth then triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, token, getPlayerIP( source ) ~= "127.0.0.1" and getPlayerIP( source ), #chars ) else triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, _, _, #chars ) end outputServerLog( "FLINT LOGIN: " .. getPlayerName( source ) .. " logueado como " .. info.username .. " (IP: " .. getPlayerIP( source ) .. ", Serial: " .. getPlayerSerial( source ) .. ")" ) exports.server:message( "%C04[" .. getID( source ) .. "]%C %B" .. info.username .. "%B se logueo (Nick: %B" .. getPlayerName( source ):gsub( "_", " " ) .. "%B)." ) exports.sql:query_free( "UPDATE wcf1_user SET lastIP = '%s', lastSerial = '%s' WHERE userID = " .. tonumber( info.userID ), getPlayerIP( source ), getPlayerSerial( source ) ) return true end end end end end return false end Las líneas a las cuales quité el SHA1 son éstas dos. La primera es del evento players:login, local info = exports.sql:query_assoc_single( "SELECT username, password FROM wcf1_user WHERE username = '%s'", username) Y la segunda es la cual debería comprobar todo y loguear. local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username = '%s'") Edited August 18, 2015 by Guest Link to comment
UserToDelete Posted August 18, 2015 Share Posted August 18, 2015 y se puede saber como funciona el export.sql? yo optaria por usar el predeterminado de MTA Link to comment
aka Blue Posted August 18, 2015 Author Share Posted August 18, 2015 sql es una carpeta que tiene mta paradise la cual contiene dos archivos, layout y mysql. En el archivo mysql.lua se coloca la base de datos, ya sabes, usuario, contraseña y demás. Link to comment
UserToDelete Posted August 18, 2015 Share Posted August 18, 2015 sql es una carpeta que tiene mta paradise la cual contiene dos archivos, layout y mysql. En el archivo mysql.lua se coloca la base de datos, ya sabes, usuario, contraseña y demás. Pero las funciones que usa son: dbConnect() --? dbQuery() --? dbPoll() --? Quizas cambiar todo a ese sistema, sea un poco lioso.. enfin Link to comment
aka Blue Posted August 18, 2015 Author Share Posted August 18, 2015 A ver, el problema está en éste código. local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username = '%s'") Aquí todo el código function performLogin( source, token, isPasswordAuth, ip ) if source and ( isPasswordAuth or not triedTokenAuth[ source ] ) then triedTokenAuth[ source ] = true if token then if #token == 80 then local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username = '%s'") p[ source ] = nil if not info then if isPasswordAuth then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 1 ) -- Wrong username/password end return false else if info.banned == 1 then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 2 ) -- Banned return false elseif info.activationCode > 0 then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 3 ) -- Requires activation return false else -- check if another user is logged in on that account for player, data in pairs( p ) do if data.userID == info.userID then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 5 ) -- another player with that account found return false end end local username = info.username p[ source ] = { userID = info.userID, username = username, options = info.userOptions and fromJSON( info.userOptions ) or { } } -- check for admin rights aclUpdate( source, true ) -- show characters local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" ) local chars2 = exports.sql:query_assoc( "SELECT COUNT(*) AS count FROM characters WHERE userID = ".. info.userID .."" ) if chars2 then for key, value in ipairs( chars2 ) do --(value.count < 3) then local cuenta = value.count end end local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" ) p[source].cuenta = #chars if isPasswordAuth then triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, token, getPlayerIP( source ) ~= "127.0.0.1" and getPlayerIP( source ), #chars ) else triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, _, _, #chars ) end outputServerLog( "FLINT LOGIN: " .. getPlayerName( source ) .. " logueado como " .. info.username .. " (IP: " .. getPlayerIP( source ) .. ", Serial: " .. getPlayerSerial( source ) .. ")" ) exports.server:message( "%C04[" .. getID( source ) .. "]%C %B" .. info.username .. "%B se logueo (Nick: %B" .. getPlayerName( source ):gsub( "_", " " ) .. "%B)." ) exports.sql:query_free( "UPDATE wcf1_user SET lastIP = '%s', lastSerial = '%s' WHERE userID = " .. tonumber( info.userID ), getPlayerIP( source ), getPlayerSerial( source ) ) return true end end end end end return false end Link to comment
Mr.Aleks Posted August 18, 2015 Share Posted August 18, 2015 Debo suponer que el debugscript 3 no da errores, ¿no? Link to comment
aka Blue Posted August 18, 2015 Author Share Posted August 18, 2015 Exacto, no da ningún error. Antes me salía el primer error, Usuario y contraseña incorrectas pero ahora no me sale el error, simplemente, no quiere loguear. Con el primer error me refiero a que cuando le daba a loguear me salía lo de "Usuario o contraseña incorrectas" ya que estaba mal el código. Link to comment
UserToDelete Posted August 18, 2015 Share Posted August 18, 2015 Postea todo el codigo lua del sql que incluye esa funcion y todas sus dependencias (si es que las tiene) Link to comment
Sasu Posted August 18, 2015 Share Posted August 18, 2015 A ver, el problema está en éste código. local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username = '%s'") Aquí todo el código function performLogin( source, token, isPasswordAuth, ip ) if source and ( isPasswordAuth or not triedTokenAuth[ source ] ) then triedTokenAuth[ source ] = true if token then if #token == 80 then local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username = '%s'") p[ source ] = nil if not info then if isPasswordAuth then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 1 ) -- Wrong username/password end return false else if info.banned == 1 then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 2 ) -- Banned return false elseif info.activationCode > 0 then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 3 ) -- Requires activation return false else -- check if another user is logged in on that account for player, data in pairs( p ) do if data.userID == info.userID then triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 5 ) -- another player with that account found return false end end local username = info.username p[ source ] = { userID = info.userID, username = username, options = info.userOptions and fromJSON( info.userOptions ) or { } } -- check for admin rights aclUpdate( source, true ) -- show characters local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" ) local chars2 = exports.sql:query_assoc( "SELECT COUNT(*) AS count FROM characters WHERE userID = ".. info.userID .."" ) if chars2 then for key, value in ipairs( chars2 ) do --(value.count < 3) then local cuenta = value.count end end local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" ) p[source].cuenta = #chars if isPasswordAuth then triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, token, getPlayerIP( source ) ~= "127.0.0.1" and getPlayerIP( source ), #chars ) else triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, _, _, #chars ) end outputServerLog( "FLINT LOGIN: " .. getPlayerName( source ) .. " logueado como " .. info.username .. " (IP: " .. getPlayerIP( source ) .. ", Serial: " .. getPlayerSerial( source ) .. ")" ) exports.server:message( "%C04[" .. getID( source ) .. "]%C %B" .. info.username .. "%B se logueo (Nick: %B" .. getPlayerName( source ):gsub( "_", " " ) .. "%B)." ) exports.sql:query_free( "UPDATE wcf1_user SET lastIP = '%s', lastSerial = '%s' WHERE userID = " .. tonumber( info.userID ), getPlayerIP( source ), getPlayerSerial( source ) ) return true end end end end end return false end No especificas el username %s en los argumentos por lo tanto no devolverá ningún row. Link to comment
aka Blue Posted August 18, 2015 Author Share Posted August 18, 2015 ¿Debería ser así dices? local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username =", ..username) Link to comment
Sasu Posted August 19, 2015 Share Posted August 19, 2015 local info = exports.sql:query_assoc_single( 'SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username ="%s"', username) Link to comment
Mr.Aleks Posted August 19, 2015 Share Posted August 19, 2015 Tenía algunas cosas mal respecto al gamemode Paradise default, ya está arreglado. Link to comment
UserToDelete Posted August 19, 2015 Share Posted August 19, 2015 Tenía algunas cosas mal respecto al gamemode Paradise default, ya está arreglado. ehh...okay..? local info = exports.sql:query_assoc_single( 'SELECT userID, username, banned, activationCode, password, userOptions FROM wcf1_user WHERE username ="%s"', username) Entonces esto funciona igual que el mysql de MTA por defecto, por lo que parece?, excepto por ese REGEX, pero bueno Link to comment
aka Blue Posted August 19, 2015 Author Share Posted August 19, 2015 Es que Paradise tiene sus maneras de hacer las cosas (? Si, ya está solucionado Link to comment
Recommended Posts