Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
mmuziek

prevent control alt C

Question

Hi there i have a long code to protect a area with a password.

the only problem is that the soft termination is off but the hard termination using control alt c is bypassing my door protection

and terminating my program so they can hack in my door

 

how can i prevent that from happening?

 

here is my code:

local component=require("component")
local event = require("event")
local r=component.redstone
local gpu=component.gpu
local term=require("term")
local password="21013"
local password2="mmuziek21013"
local delay=5
local c = require("computer")
local side=4
local wrong=false
event.shouldInterrupt(false)
while true do

term.clear()
gpu.set(1,1,"please enter ADMIN CODE")
if wrong then
gpu.set(1,1,"Wrong admin code given!")
wrong=false
end

term.setCursor(1,2)
local input=io.read()
if input==password then
r.setOutput(side,15)
os.sleep(delay)
r.setOutput(side,0)
elseif input==password2 then
gpu.set(1,2,"Root access granted")
os.exit()
else
wrong=true
end
if event.onError(interrupted) then
c.shutdown(true)
end
end
Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  • Solution

First, these two chunks of code are completely unnecessary.

if event.onError(interrupted) then
c.shutdown(true)
end
event.shouldInterrupt(false)

Second, to prevent program interruption by pressing the key combination you mentioned in the title, you'll need to override the event.shouldInterrupt function to make it always return false. This can be done the following way:

event.shouldInterrupt = function()
  return false
end

This code should be run after requiring event library.

 

On the final note, I'd recommend you to learn about code indentation. It makes code look cleaner, nicer, and easier-to-read, especially a large and complex one.

Link to post
Share on other sites
  • 0

First, these two chunks of code are completely unnecessary.

if event.onError(interrupted) then
c.shutdown(true)
end
event.shouldInterrupt(false)

Second, to prevent program interruption by pressing the key combination you mentioned in the title, you'll need to override the event.shouldInterrupt function to make it always return false. This can be done the following way:

event.shouldInterrupt = function()
  return false
end

This code should be run after requiring event library.

 

On the final note, I'd recommend you to learn about code intentation. It makes code look cleaner, nicer, and easier-to-read, especially a large and complex one.

thanks for the help. i know the indentation sucks im still learning but thanks for the advice and the example.

 

greetings mmuziek

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.