Jump to content




Ctrl+T


14 replies to this topic

#1 EurypteriD

  • New Members
  • 10 posts

Posted 09 February 2012 - 10:11 PM

Hey.

ive been looking around both on the net and in my local files.
On how to disabled CTRL+t on a single terminal without install redworks (working on my own OS)

Reason i need this is.. Else you can pass the user logon.

#2 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 09 February 2012 - 10:38 PM

CTRL+T throws the 'terminate' error and this stops program execution.
To prevent this from happening you have to catch the error, telling LUA to carry on with your program regardless of the error.
To do this you can make use of the pcall() function ("Protected Call").

So instead of e.g. ...
local password = "secret"
repeat
	write("Password: ")	 -- write without line break
	local input = read()	  -- read input
until input == password	-- repeat until the input matches the password
... you could encase the read() function within a pcall() and write this:
local password = "secret"
repeat
	write("Password: ")	 -- write without line break
	local status, input = pcall( read ) 	 -- read input
until input == password	-- repeat until the input matches the password

So as long as read() has not returned, you cannot terminate the input with CTRL+T.
Since nothing else happens outside of the read() in my example I chose to encase just the read() function.
But if you had more going on, then it might be a good idea to encase everything in a new function and then call that whole function via pcall().
Also note the missing () of the read function. That's because we passed the function to pcall() as an argument.

Further links:
http://www.lua.org/pil/8.4.html
http://www.lua.org/m...manual.html#2.7
http://www.lua.org/m....html#pdf-pcall

EDIT: Sorry but I forgot something. When read is called by pcall() then it returns a status value along with the values of the called function.
That means instead of ...
local input = pcall( read )
... it should've been ...
local status, input = pcall( read )
Otherwise I'm checking the wrong value and even the correctly entered password wouldn't have worked.
Also: status returns true if there wasn't an error during read, and false if there was (like CTRL+T).
In my code I just ignore the status, but you could do different thing depending on its value, of course.

Sorry again, I correct the code above. ;)/>

Edited by Espen, 09 February 2012 - 11:18 PM.


#3 arongy

  • New Members
  • 37 posts
  • LocationQuebec, Canada

Posted 10 February 2012 - 01:05 AM

You can also add this code into your script:

function os.pullEvent()
	local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
	if event == "terminate" then
		os.reboot() -- Remove this for do not reboot on Ctrl+T
	end
	return event, p1, p2, p3, p4, p5
end

From http://mccraftcpl.pr...splay&thread=78

#4 FuzzyPurp

    Part-Time Ninja

  • Members
  • 510 posts
  • LocationHarlem, NY

Posted 10 February 2012 - 01:19 AM

Redworks prevents ctrl+t. One could just look at the source of the Redworks API to see how we did that, the code above works just fine.

#5 EurypteriD

  • New Members
  • 10 posts

Posted 10 February 2012 - 05:54 AM

Hey Tanks for the replys.

Ill test both out. But i think the one that turns terminate to shutdown would be the best
As i have put in encrypted debug password so i can get into the terminal even though its messing up.

Im using this trying to replicate a chicken farm i saw on you tube (without Ic as i just use redpower)
its made by Cookiebal, But im gonna write my own just to get into the scripting more.

ยจ@fuzzy I already looked at the redworks api. But its very complicated in there. Its way to advanced for me at this state XD

#6 FuzzyPurp

    Part-Time Ninja

  • Members
  • 510 posts
  • LocationHarlem, NY

Posted 10 February 2012 - 06:15 AM

Snippet from Redworks API:
local falt, sEvent, param = nil,nil,nil
while not bExit do
if disableTerm then
falt, sEvent, param = pcall(os.pullEvent)
else
sEvent, param = os.pullEvent()
falt=false
end


#7 EurypteriD

  • New Members
  • 10 posts

Posted 10 February 2012 - 04:05 PM

@arongy
Tried that code. and it worked. Just one note. It have to be in the start else it will mess up

@fuzzy that one didnt work for me. But as long it works for redworks its good ;)/>

Thanks both for the replies. Nice to have community like this

#8 Cookiebal

  • Members
  • 82 posts

Posted 10 February 2012 - 07:57 PM

Another way to stop ctrl+T is to run the program in another program with a loop. The drawback of this is that it resets the program after using ctrl+T.

while true do
shell.run("program")
if programended = true then break end
end

Here the program only ends if somewhere inside the programended is set to true, else it just restarts the program again.
Do note that variables won't get reset.

This is what I use for CookieSystem, there it works pretty good and I don't have to worry about any pcall stuff or other things.

#9 Advert

    Custom Title

  • Moderators
  • 459 posts
  • LocationLondon

Posted 10 February 2012 - 08:46 PM

View PostCookiebal, on 10 February 2012 - 07:57 PM, said:

Another way to stop ctrl+T is to run the program in another program with a loop. The drawback of this is that it resets the program after using ctrl+T.

while true do
shell.run("program")
if programended = true then break end
end

Here the program only ends if somewhere inside the programended is set to true, else it just restarts the program again.
Do note that variables won't get reset.

This is what I use for CookieSystem, there it works pretty good and I don't have to worry about any pcall stuff or other things.

Why would you have to worry about pcall? D:

#10 Cookiebal

  • Members
  • 82 posts

Posted 10 February 2012 - 09:51 PM

View PostAdvert, on 10 February 2012 - 08:46 PM, said:

Why would you have to worry about pcall? D:

Depends on the method you use. I never tried any others myself (never needed to), but I often hear about confusion with pcall :D/>

#11 Advert

    Custom Title

  • Moderators
  • 459 posts
  • LocationLondon

Posted 10 February 2012 - 09:56 PM

View PostCookiebal, on 10 February 2012 - 09:51 PM, said:

View PostAdvert, on 10 February 2012 - 08:46 PM, said:

Why would you have to worry about pcall? D:

Depends on the method you use. I never tried any others myself (never needed to), but I often hear about confusion with pcall :D/>

pcall's syntax is quite simple:
local isSuccessful, returnValue, returnValue2 [...] = pcall(function, arg1, arg2, ...)

if not isSuccessful then
 print("Error: ", returnValue)
end


#12 FuzzyPurp

    Part-Time Ninja

  • Members
  • 510 posts
  • LocationHarlem, NY

Posted 10 February 2012 - 11:53 PM

View PostEurypteriD, on 10 February 2012 - 04:05 PM, said:

@arongy
Tried that code. and it worked. Just one note. It have to be in the start else it will mess up

@fuzzy that one didnt work for me. But as long it works for redworks its good :D/>

Thanks both for the replies. Nice to have community like this

Yea it wouldn't work for you because its has redworks variables in it ^_^/>

Here's one that would work with a bypass key set to the number 2 key..

while true do
fault, event, param1, param2, param3 = pcall(os.pullEvent)
  if fault == false then
  elseif event == "key" and param1 == 2 then
  break end
end


#13 arongy

  • New Members
  • 37 posts
  • LocationQuebec, Canada

Posted 13 February 2012 - 01:38 AM

Just put this at the end of your script to reactivate the Terminate command!

function os.pullEvent()
	    local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
	    if event == "terminate" then
			    error( "Terminated" )
	    end
	    return event, p1, p2, p3, p4, p5
end


#14 spyman68

  • Members
  • 155 posts

Posted 20 March 2013 - 07:13 AM

Guys, at the very top of your program just type
os.pullEvent = os.pullEventRaw


#15 Cruor

  • Members
  • 413 posts
  • LocationNorway

Posted 20 March 2013 - 07:16 AM

Please refrain from using the foul art of necromancy.
Locked.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users