Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1.     function loginHandler(password)
  2.          outputDebugString('* trying to log in')
  3.           --If there is no connection, print it.
  4.           --if( not connect_mysql ) then
  5.           --      outputChatBox( "Could not connect to MySQL server [DG:RP]" )
  6.           --else
  7.           -- MODIFIED!!
  8.           -- It's better to do all checkings via MySQL directly. Why fetch it then check if is it equal?
  9.           -- Notice that "password" is build-in word in mysql, so if you want to use it as a column name you have to
  10.           -- cover it with this quote ----> `
  11.           local login = mysql_query( connect_mysql, "SELECT * FROM players WHERE Username='" .. getPlayerName(client) .. "' and `Password`='"..password.."'")
  12.          outputDebugString('* query executed')
  13.           -- check that the username and password are correct
  14.           if (login) then
  15.              outputDebugString('* query execution OK')
  16.              local row = mysql_fetch_assoc(login)
  17.              if (row) then
  18.                 outputDebugString('* row is fetched')
  19.                 pass = row['Password']
  20.                 posx = row['saveX']
  21.                 posy = row['saveY']
  22.                 posz = row['saveZ']
  23.                 -- if all succeed -> do all your actions here, not somewhere below. it's getting messy.
  24.                 outputDebugString('* trying to spawn')
  25.                 local spawned = spawnPlayer(client, posx, posy, posz)
  26.                 if spawned then
  27.                    outputDebugString('* spawned ok')
  28.                 else
  29.                    outputDebugString('* spawn failed')
  30.                 end
  31.                   fadeCamera(client, true)
  32.                   outputChatBox("Welcome to Division Gamers RolePlay.", client)
  33.              else
  34.              outputDebugString('* no row fetched')
  35.                 -- no rows = invalid login
  36.              end
  37.              mysql_free_result(login) -- put this only when query succeed
  38.           else
  39.              outputDebugString('* query execution FAILED')
  40.           end                    
  41.       end
  42.       addEvent("submitLogin",true)
  43.       addEventHandler("submitLogin",root,loginHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement