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

"Goto" command?

Started by Dark Shadow, 08 November 2012 - 09:12 AM
Dark Shadow #1
Posted 08 November 2012 - 10:12 AM
I'm trying to make a nuclear reactor controller but I have problems with a password protecting it.

When i run my code it first updates to the newest pastebin version (thanks Cranium).
After that it asks for a password, and after bypassing the password I would like the user to be able to type "lock" and then lock the computer, although I can't figure it out…

I miss a goto command, I know there is something called "functions" but I can't seem to figure it out, also while I'm at it, will it be possible to let the computer process redstone input/output while locked?

Thanks in advantage :P/>/>

Code:
Spoiler


local version =
0.01
local pastebinlink = "5rALib9G" --The pastebin "code"
local password = "123bacon" -- The password required to unlock the computer
trys = 3 -- The number of trys before anti bruteforce
bruteforcetime = 18 -- The amount of time the antibruteforce should take


--check version by Cranium
term.clear()
term.setCursorPos(1,1)
print("Program loading...")
print("Current version: "..version)
local updateSite = http.get("http://pastebin.com/raw.php?i="..pastebinlink)
updateSite.readLine()
local coding = updateSite.readLine()
local newVersion = (tonumber(coding))
sleep(2)
if tonumber(newVersion) > version then
		print("Newest version is: "..newVersion)
		print("Update required. Updating now...")
		local updateSite = http.get("http://pastebin.com/raw.php?i="..pastebinlink)
		local siteFile = updateSite.readAll()
		local writeFile = fs.open(shell.getRunningProgram(),"w")
		writeFile.write(siteFile)
		writeFile.close()
		print("The program will now restart your computer.")
		sleep(2)
		os.reboot()
end

--Password protection
tryerror = trys
locked = true
while locked == true do
		term.clear()
		term.setCursorPos(1,1)
		print("Please enter the password:")
		input = read("*")
		if input == password then
				print("Welcome")
				tryerror = trys
				sleep(1)
				locked = false
		else
				print("PASSWORD INCORRECT!")
				tryerror = tryerror - 1
				sleep(2)
				if tryerror < 1 then
						print("Brute Force Detected")
						sleep(bruteforcetime)
						tryerror = trys
				end
		end
end

--Beyond protection
term.clear()
term.setCursorPos(1,1)
print("+--------------------{NewkOS}--------------------+\n")

input = read()
if input == "version" then
		print("Current version: "..version)
elseif input == "lock" then
		locked = true
end
Dark Shadow #2
Posted 08 November 2012 - 10:55 AM
Spoiler

local version =
0.06
local pastebinlink = "5rALib9G" --The pastebin "code"
local password = "123bacon" -- The password required to unlock the computer
trys = 3 -- The number of trys before anti bruteforce
bruteforcetime = 18 -- The amount of time the antibruteforce should take


--==check version by Cranium==--
function versioncheck()
		term.clear()
		term.setCursorPos(1,1)
		print("Program loading...")
		print("Current version: "..version)
		local updateSite = http.get("http://pastebin.com/raw.php?i="..pastebinlink)
		updateSite.readLine()
		local coding = updateSite.readLine()
		local newVersion = (tonumber(coding))
		sleep(2)
		if tonumber(newVersion) > version then
				print("Newest version is: "..newVersion)
				print("Update required. Updating now...")
				local updateSite = http.get("http://pastebin.com/raw.php?i="..pastebinlink)
				local siteFile = updateSite.readAll()
				local writeFile = fs.open(shell.getRunningProgram(),"w")
				writeFile.write(siteFile)
				writeFile.close()
				print("The program will now restart your computer.")
				sleep(2)
				os.reboot()
		end
end


--==Password protection function==--
function locked()
		tryerror = trys
		locked = true
		while locked == true do
				term.clear()
				term.setCursorPos(1,1)
				print("Please enter the password:")
				input = read("*")
				if input == password then
						print("Welcome")
						tryerror = trys
						sleep(1)
						locked = false
						term.clear()
						term.setCursorPos(1,1)
						print("+--------------------{NewkOS}--------------------+n")
						unlocked()
				else
						print("PASSWORD INCORRECT!")
						tryerror = tryerror - 1
						sleep(2)
						if tryerror < 1 then
								print("Brute Force Detected")
								sleep(bruteforcetime)
								tryerror = trys
						end
				end
		end
end


--==Beyond protection function==--
function unlocked()
		input = read()
		if input == "version" then
				print("Current version: "..version)
				unlocked()
		elseif input == "lock" then
				locked = true
		elseif input == "shutdown" then
				os.shutdown()
		elseif input == "reboot" then
				os.reboot()
		end
end


--==starting==--
versioncheck()
locked()

Okay, I think I fixed the goto problem, by making them a function… (I hope this is the right way of doing it)
Now, does anyone know if its possible to get redstone input and send out redstone output while inside the password lock loop?

EDIT: I'm affraid that there is a whole load of loops going on on top if each other when I do it like this
Edited on 08 November 2012 - 09:59 AM