Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 KB | None | 0 0
  1. addEvent( getResourceName( resource ) .. ":login", true )
  2. addEventHandler( getResourceName( resource ) .. ":login", root,
  3.     function( username, password )
  4.         if source == client then
  5.             triedTokenAuth[ source ] = true
  6.             if username and password and #username > 0 and #password > 0 then
  7.                 local info = exports.sql:query_assoc_single( "SELECT CONCAT(SHA1(CONCAT(username, '%s')),SHA1(CONCAT(salt, SHA1(CONCAT('%s',SHA1(CONCAT(salt, SHA1(CONCAT(username, SHA1(password)))))))))) AS token FROM wcf1_user WHERE `username` = '%s' AND password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, '" .. sha1(password) .. "'))))", getPlayerHash( source ), getPlayerHash( source ), username )
  8.                 p[ source ] = nil
  9.                 if not info then
  10.                     triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 1 ) -- Wrong username/password
  11.                     loginAttempts[ source ] = ( loginAttempts[ source ] or 0 ) + 1
  12.                     if loginAttempts[ source ] >= 5 then
  13.                         kickPlayer( source, true, false, false, root, "Too many login attempts.", 900 )
  14.                     end
  15.                 else
  16.                     loginAttempts[ source ] = nil
  17.                     performLogin( source, info.token, true )
  18.                 end
  19.             end
  20.         end
  21.     end
  22. )
  23.  
  24. function performLogin( source, token, isPasswordAuth, ip, username )
  25.     if source and ( isPasswordAuth or not triedTokenAuth[ source ] ) then
  26.         triedTokenAuth[ source ] = true
  27.         if token then
  28.             if #token == 80 then
  29.                 local info = exports.sql:query_assoc_single( "SELECT userID, username, banned, activationCode, password, AS salts, userOptions FROM wcf1_user WHERE CONCAT(username, password) = '%s' LIMIT 1", token )
  30.                 p[ source ] = nil
  31.                 if not info then
  32.                     if isPasswordAuth then
  33.                         triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 1 ) -- Wrong username/password
  34.                     end
  35.                     return false
  36.                 else
  37.                     if info.banned == 1 then
  38.                         triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 2 ) -- Banned
  39.                         return false
  40.                     elseif info.activationCode > 0 then
  41.                         triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 3 ) -- Requires activation
  42.                         return false
  43.                     else
  44.                         -- check if another user is logged in on that account
  45.                         for player, data in pairs( p ) do
  46.                             if data.userID == info.userID then
  47.                                 triggerClientEvent( source, getResourceName( resource ) .. ":loginResult", source, 5 ) -- another player with that account found
  48.                                 return false
  49.                             end
  50.                         end
  51.                         local username = info.username
  52.                         p[ source ] = { userID = info.userID, username = username, options = info.userOptions and fromJSON( info.userOptions ) or { } }
  53.                        
  54.                         -- check for admin rights
  55.                         aclUpdate( source, true )
  56.                        
  57.                         -- show characters
  58.                         local chars = exports.sql:query_assoc( "SELECT characterID, characterName, skin FROM characters WHERE userID = " .. info.userID .. " ORDER BY lastLogin DESC" )
  59.                         if isPasswordAuth then
  60.                             triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true, token, getPlayerIP( source ) ~= "127.0.0.1" and getPlayerIP( source ) )
  61.                         else
  62.                             triggerClientEvent( source, getResourceName( resource ) .. ":characters", source, chars, true )
  63.                         end
  64.                        
  65.                         outputServerLog( "Rockstar Roleplay: Login " .. getPlayerName( source ) .. " logged in as " .. info.username .. " (IP: " .. getPlayerIP( source ) .. ", Serial: " .. getPlayerSerial( source ) .. ")" )
  66.                         exports.server:message( "%C04[" .. getID( source ) .. "]%C %B" .. info.username .. "%B logged in (Nick: %B" .. getPlayerName( source ):gsub( "_", " " ) .. "%B)." )
  67.                         exports.sql:query_free( "UPDATE wcf1_user SET lastIP = '%s', lastSerial = '%s' WHERE userID = " .. tonumber( info.userID ), getPlayerIP( source ), getPlayerSerial( source ) )
  68.                        
  69.                         return true
  70.                     end
  71.                 end
  72.             end
  73.         end
  74.     end
  75.     return false
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement