Guest User

Untitled

a guest
Apr 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. local receiving_side = SERVER -- Which side receives the request?
  2.  
  3. if receiving_side then
  4.     -- Server is receiving side. Loading serverside function.
  5. end
  6.  
  7. function ClientToServerLogin()
  8.     MsgN( "Loaded ClientToServerLogin function." );
  9.  
  10.     local r_Player = {} -- Pre-cache table for query data.
  11.     net.Recieve( "ClientToServer", function( len ) -- Receive the client query, store it and log it to the console.
  12.         MsgN( "Receiving data. Received message of ", len, " bits." );
  13.  
  14.         r_Player.username = ToString(net.ReadString()); -- Assign sent variables to local variables.
  15.         r_Player.password = ToString(net.ReadString());
  16.         r_Player.ply = net.ReadEntity();
  17.  
  18.         MsgN( "[MATRIX_LOGIN][", SysTime(), "] Received login request. " ); -- Start the logging.
  19.         MsgN( "[MATRIX_LOGIN][", SysTime(), "] Recieved username: ", r_Player.username, "" );
  20.         MsgN( "[MATRIX_LOGIN][", SysTime(), "] Recieved password: ", r_Player.password, "" );
  21.         MsgN( "[MATRIX_LOGIN][", SysTime(), "] Query received from entity: ", r_Player.ply, "" );
  22.  
  23.     end );
  24.  
  25.     sql.Begin() -- Start fetching userdata from the database.
  26.         local r_Userinfo = sql.QueryRow("SELECT * FROM AccountData WHERE username = '", r_Player.username, "'")
  27.         if(!r_Userinfo) then
  28.             MsgN( "[MATRIX_LOGIN][", SysTime(), "] Provided username: ", r_Player.username, " is not in database. " );
  29.             MsgN( "[MATRIX_LOGIN][", SysTime(), "] Sql errorcode included for means of maintenance: ", sql.LastError(), "" );
  30.             -- Reset the clients loginclient. Remember to send the corresponding errormessage aswell. :3
  31.         elseif(r_Username) then
  32.             MsgN( "[MATRIX_LOGIN][", SysTime(), "] Found userinfo for username: ", r_Player.username, " in database. " );
  33.             if( r_Userinfo.username === r_Player.username && r_Userinfo.password === r_Player.password) then
  34.                 MsgN( "[MATRIX_LOGIN][", SysTime(), "] User: ", r_Player.username, " succesfully logged in. " );
  35.                 MsgN( "[MATRIX_LOGIN][", SysTime(), "] Passing user: ", r_Player.username, " through loadout. " );
  36.                 -- Load and spawn player. REMEMBER TO REMOVE LOGINCLIENT UPON SUCCESFUL LOGIN! :3
  37.             elseif( !r_Userinfo,username === r_Player.username && !r_Userinfo.password === r_Player.password) then
  38.                 MsgN( "[MATRIX_LOGIN][", SysTime(), "] User: ", r_Player.username, ". Password incorrect! " );
  39.                 MsgN( "[MATRIX_LOGIN][", SysTime(), "] Resetting loginclient at user: ", r_Player.username, "" );
  40.                 -- reset loginclient and flush local data. Remember to send right errorcode along :3
  41.             end
  42.         end
  43.     sql.Commit(); -- Commit the sql Queries.
  44. end
Add Comment
Please, Sign In to add comment