Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local receiving_side = SERVER -- Which side receives the request?
- if receiving_side then
- -- Server is receiving side. Loading serverside function.
- end
- function ClientToServerLogin()
- MsgN( "Loaded ClientToServerLogin function." );
- local r_Player = {} -- Pre-cache table for query data.
- net.Recieve( "ClientToServer", function( len ) -- Receive the client query, store it and log it to the console.
- MsgN( "Receiving data. Received message of ", len, " bits." );
- r_Player.username = ToString(net.ReadString()); -- Assign sent variables to local variables.
- r_Player.password = ToString(net.ReadString());
- r_Player.ply = net.ReadEntity();
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Received login request. " ); -- Start the logging.
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Recieved username: ", r_Player.username, "" );
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Recieved password: ", r_Player.password, "" );
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Query received from entity: ", r_Player.ply, "" );
- end );
- sql.Begin() -- Start fetching userdata from the database.
- local r_Userinfo = sql.QueryRow("SELECT * FROM AccountData WHERE username = '", r_Player.username, "'")
- if(!r_Userinfo) then
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Provided username: ", r_Player.username, " is not in database. " );
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Sql errorcode included for means of maintenance: ", sql.LastError(), "" );
- -- Reset the clients loginclient. Remember to send the corresponding errormessage aswell. :3
- elseif(r_Username) then
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Found userinfo for username: ", r_Player.username, " in database. " );
- if( r_Userinfo.username === r_Player.username && r_Userinfo.password === r_Player.password) then
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] User: ", r_Player.username, " succesfully logged in. " );
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Passing user: ", r_Player.username, " through loadout. " );
- -- Load and spawn player. REMEMBER TO REMOVE LOGINCLIENT UPON SUCCESFUL LOGIN! :3
- elseif( !r_Userinfo,username === r_Player.username && !r_Userinfo.password === r_Player.password) then
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] User: ", r_Player.username, ". Password incorrect! " );
- MsgN( "[MATRIX_LOGIN][", SysTime(), "] Resetting loginclient at user: ", r_Player.username, "" );
- -- reset loginclient and flush local data. Remember to send right errorcode along :3
- end
- end
- sql.Commit(); -- Commit the sql Queries.
- end
Add Comment
Please, Sign In to add comment