This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mark0099's profile picture

Making a cd .. Block on login to computer

Started by mark0099, 19 June 2014 - 07:31 PM
mark0099 #1
Posted 19 June 2014 - 09:31 PM
Ok, so I have code on startup which asks for the username and depending on the username given you will have to give your correct password, how can I make it so that when someone enters their password it'll put them in a directory and lock them into it so they cannot cd .. out?

I'm using CraftOS 1.3
Lignum #2
Posted 19 June 2014 - 10:29 PM
You would be better off making your own shell but you could overwrite shell.setDir.
Assuming ".." is referring to root:


local oldSetDir = shell.setDir --# Keep a copy of the old shell.setDir.

shell.setDir = function(path)
     local prev = shell.dir() --# The dir we're in right now.
     oldSetDir(path) --# Set the dir.

     if shell.dir() == "" then
          oldSetDir(prev) --# If the current dir is root, reset.
          error("Access Denied") --# This will make it behave like attempting to delete rom.
     end
end

Keep in mind that you can still access files in the previous directory like so: ../afile. You could override shell.resolve and shell.resolveProgram for that.
Also, your own program will also have no access to root, so use oldSetDir instead of shell.setDir.