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

[Solved] A few things regarding the disk boot priority.

Started by Nhorr, 21 October 2014 - 02:06 PM
Nhorr #1
Posted 21 October 2014 - 04:06 PM
I know for a fact that no matter what is done, a startup file on a loaded disk will (without changing the mod's settings) always overwrite the computer's own (with a drive placed on the top of the computer having the #1 priority). I've heard it in every forum, and I've tested it myself, but I've been really loving the whole password-protected computers subject recently and I just couldn't put this one to rest.

Knowing this, without external (not-in-Minecraft) editing, is there any way to make a program that detects a startup program - either the Computer's or the Disk's - and then if it detects one, runs a password program (most likely using an if then statement)? In other words, once you turn on a computer w/ or w/o the disk, is there a program that could detect a startup program (or even a disk/disk drive), and in response return a program of any type/name? Or a way to make the editing of any programs require a password instead?

I know the subject's been opened plenty of times, but I'd appreciate some closure on the subject before I go on with Espen's tutorial and edit my server's CC files.

TL;DR (even though it's pretty short): is there 1) a way (without outside editing) to make a program that automatically runs after any startup program or when it detects a disk? or 2) a way (without outside editing) to make the editing of any programs (or the edit program itself) require a password?

Like I said, I suspect that if this is possible, it will involve some if then statements. Let me know if I need to clarify anything.

Thanks!
Edited on 21 October 2014 - 09:50 PM
Lyqyd #2
Posted 21 October 2014 - 05:45 PM
1. No.

2. Not cleanly. Essentially, no.
KingofGamesYami #3
Posted 21 October 2014 - 06:18 PM
I've never attempted this, but this makes it at least difficult (if written as startup)

os.pullEvent = os.pullEventRaw --#no termination
os.shutdown = os.reboot --#computer cant be turned off
local function scan()
  while true do
    local event = { os.pullEvent() }
    if event[ 1 ] == "disk" and fs.exists( fs.combine( disk.getMountPath( event[ 2 ] ), "startup" ) ) then
      disk.eject( event[ 2 ] )
    end
  end
end
while true do
  parallel.waitForAny( scan, function() shell.run( "shell" ) end )
end
Nhorr #4
Posted 21 October 2014 - 08:49 PM
1. No.

2. Not cleanly. Essentially, no.

Ok, thanks for the validation.

I've never attempted this, but this makes it at least difficult (if written as startup)

os.pullEvent = os.pullEventRaw --#no termination
os.shutdown = os.reboot --#computer cant be turned off
local function scan()
  while true do
	local event = { os.pullEvent() }
	if event[ 1 ] == "disk" and fs.exists( fs.combine( disk.getMountPath( event[ 2 ] ), "startup" ) ) then
	  disk.eject( event[ 2 ] )
	end
  end
end
while true do
  parallel.waitForAny( scan, function() shell.run( "shell" ) end )
end

I'll try your code in a sec and I'll update this with the results.
Guess I'll go through with Espen's thread if it doesn't end up fully working. I appreciate the code though - I was honestly open to any suggestions.

Thanks for the responses!

EDIT: I ran the code on a our server (running 1.5) - it doesn't seem anything happened, and I could still shutdown the computer. Does it only work for 1.6? And if you don't mind briefly explaining, what specifically does the program do (I'm still in the process in learning lua in general)?

EDIT2: Just ran it on the emulator, but it didn't seem to do anything. I could still shut the computer down, and it wouldn't reboot itself (which is what I'm guessing os.shutdown = os.reboot is supposed to do). Oh well - I at least have some inspiration for an alternate approach to a preliminary password screen. Thanks!
Edited on 21 October 2014 - 07:57 PM
KingofGamesYami #5
Posted 21 October 2014 - 09:57 PM
Sure!

os.pullEvent = os.pullEventRaw --#no termination
os.shutdown = os.reboot --#when computer would be shut down, reboot instead.
local function scan() --#define a function
  while true do
		local event = { os.pullEvent() } --#pull an event
		if event[ 1 ] == "disk" and fs.exists( fs.combine( disk.getMountPath( event[ 2 ] ), "startup" ) ) then --#if a disk was inserted, and it has a startup script,
		  disk.eject( event[ 2 ] ) --#eject the disk
		end
  end
end
while true do
  parallel.waitForAny( scan, function() shell.run( "shell" ) end ) --#run scan in parallel with a new instance of shell.  (this may be why you can shut it down, try inserting your program name instead)
end
Edited on 21 October 2014 - 07:57 PM
Lyqyd #6
Posted 21 October 2014 - 10:23 PM
That might help against the shutdown program, but Ctrl-S (and -R) cannot be bypassed or modified in any way. Without editing the ROM, there is no way to prevent or control Ctrl-S, insert disk with blank startup, boot.
Nhorr #7
Posted 21 October 2014 - 11:11 PM
Sure!

os.pullEvent = os.pullEventRaw --#no termination
os.shutdown = os.reboot --#when computer would be shut down, reboot instead.
local function scan() --#define a function
  while true do
		local event = { os.pullEvent() } --#pull an event
		if event[ 1 ] == "disk" and fs.exists( fs.combine( disk.getMountPath( event[ 2 ] ), "startup" ) ) then --#if a disk was inserted, and it has a startup script,
		  disk.eject( event[ 2 ] ) --#eject the disk
		end
  end
end
while true do
  parallel.waitForAny( scan, function() shell.run( "shell" ) end ) --#run scan in parallel with a new instance of shell.  (this may be why you can shut it down, try inserting your program name instead)
end

Thank you very much! I was testing the os.shutdown = os.reboot with CTRL-S (which…

That might help against the shutdown program, but Ctrl-S (and -R) cannot be bypassed or modified in any way. Without editing the ROM, there is no way to prevent or control Ctrl-S, insert disk with blank startup, boot.

… apparently can't be disabled at all unlike CTRL-T). I also forgot to insert a program name instead…
Thanks again to both of you - I'll be reading up on the other thread :)/>
Edited on 21 October 2014 - 09:44 PM
Cranium #8
Posted 21 October 2014 - 11:42 PM
Ctrl+S and Ctrl+R are hardcoded into the java side, to prevent scripts from being non-terminable. The best you can do is modify the ROM with a resource pack to change how things work upon startup to prevent disk booting.
Nhorr #9
Posted 21 October 2014 - 11:48 PM
Ctrl+S and Ctrl+R are hardcoded into the java side, to prevent scripts from being non-terminable. The best you can do is modify the ROM with a resource pack to change how things work upon startup to prevent disk booting.

It's nice to know that that's the case, and I can see why it is. Disk drives are a great way to recover a PC corrupted due to a badly programmed startup file, but unfortunately makes Login startup programs kind of useless.

Oh well, I guess I can stop trying on the subject. I'd consider my original question answered :)/>
Bomb Bloke #10
Posted 22 October 2014 - 01:49 AM
The trick is to rig things such that your computer can't be interfered with in ways you don't want.

For example, if you surround a computer with warded blocks, and only allow access to it via an advanced monitor (either with or without a Moarperipherals keyboard), then you no longer need to worry about people hooking up malicious startup disks.
Nhorr #11
Posted 23 October 2014 - 12:33 AM
The trick is to rig things such that your computer can't be interfered with in ways you don't want.

For example, if you surround a computer with warded blocks, and only allow access to it via an advanced monitor (either with or without a Moarperipherals keyboard), then you no longer need to worry about people hooking up malicious startup disks.

I've considered it for a while, and the more I think about it the more likely I think I'll just end up doing this to prevent physical hacking rather than editing the ROM. Between my friend and I I'm advancing our base more in the tech department (since I'm a bit inexperienced with the magic-related mods), so I'll make him create some for me :D/>
Kazza #12
Posted 25 October 2014 - 08:43 PM
Why not just place your password program inside your startup program.
KingofGamesYami #13
Posted 26 October 2014 - 01:22 AM
Why not just place your password program inside your startup program.
Because of disk boot priority, that is if there is a startup program on a disk, it will use that instead of the startup program on the computer… If you mean, put your startup program on a disk, yes, you can do that, but if someone can access the computer in the first place, they can probably access the disk drive.