Jump to content




Am I no longer able to block the 'Terminate' event?

computer

5 replies to this topic

#1 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

Posted 12 March 2013 - 05:14 PM

On a previous script I wrote for a door lock, I was able to negate the user from activating 'Terminate' and getting past my password. I haven't ued CC in close to a year possibly (I might be exagerating but it really had been a while, maybe like 4 to 6 months)

Anywho this was the original script:
function clear()
term.clear()
term.setCursorPos(1,1)
end
function lock()
local PASSWORD = "PASSWORD GOES HERE"
local temp = os.pullEvent
local function dkeys(swap)
  disable = {
  [0] = function() os.pullEvent = temp end,
  [1] = function() os.pullEvent = os.pullEventRaw end
}
disable[swap]()
end
clear()
dkeys(0)
print("Enter password:")
write("> ")
local input = read("*")
if input == PASSWORD then
  clear()
  dkeys(0)
  print("Access granted!")
  sleep(1)
  clear()
  textutils.slowPrint("Unlocking...")
  print("Welcome!")
  redstone.setOutput("back", true)
  sleep(4)
  redstone.setOutput("back", false)
  os.reboot()
else
  clear()
  print("Access denied!")
  textutils.slowPrint("Logging username...")
  sleep(1)
  os.reboot()
end
end
lock()

This section in specific allowed me to stop a user from terminating my 'startup' program.
local function dkeys(swap)
  disable = {
  [0] = function() os.pullEvent = temp end,
  [1] = function() os.pullEvent = os.pullEventRaw end
}
disable[swap]()

Have there been changes to the terminate event? My script use to work like a charm, is there some new way to block the user from terminating my program?

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 12 March 2013 - 05:22 PM

Nope. That has not changed. Preventing terminate is still os.pullEvent = os.pullEventRaw in one way or another.

#3 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

Posted 12 March 2013 - 05:27 PM

For some reason I am fully able to simply CTRL + T and terminate my startup, is there somethign wrong with my script? If it helps I'm using advanced computers.

#4 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 12 March 2013 - 05:38 PM

It's cause you want to put the items within that function outside of a function so it gets called first.
local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
--at the end of your code:
os.pullEvent = oldPull


#5 eleure

  • Members
  • 41 posts

Posted 12 March 2013 - 05:57 PM

a cleaner version of your code for cranium's benefit.
function clear()
  term.clear()
  term.setCursorPos(1,1)
end

function lock()
  local PASSWORD = "PASSWORD GOES HERE"
  local temp = os.pullEvent
  local function dkeys(swap)
	disable = {
	  [0] = function() os.pullEvent = temp end,
	  [1] = function() os.pullEvent = os.pullEventRaw end
	}
  disable[swap]()
  end

  clear()
  dkeys(0)
  print("Enter password:")
  write("> ")
  local input = read("*")

  if input == PASSWORD then
	clear()
	dkeys(0)
	print("Access granted!")
	sleep(1)
	clear()
	textutils.slowPrint("Unlocking...")
	print("Welcome!")
	redstone.setOutput("back", true)
	sleep(4)
	redstone.setOutput("back", false)
	os.reboot()
  else
	clear()
	print("Access denied!")
	textutils.slowPrint("Logging username...")
	sleep(1)
	os.reboot()
  end
end
lock()

your only issue is that you're mixing up what dkeys(0) and dkeys(1) do. you should be calling dkeys(1) to disable terminate and dkeys(0) to enable it again.

edit: wow, the spacing is wrong for me because of some formatting applied after submit. that's a terrible feature

#6 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

Posted 12 March 2013 - 06:09 PM

Thanks, I was mixing them up.

clear()
  dkeys(1)
  print("Enter password:")
  write("> ")
  local input = read("*")
  if input == PASSWORD then
		clear()
		dkeys(0)
		print("Access granted!")
		sleep(1)
		clear()
		textutils.slowPrint("Unlocking...")
		print("Welcome!")
		redstone.setOutput("back", true)
		sleep(4)
		redstone.setOutput("back", false)
		os.reboot()

Fixed it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users