--[[Variables]]--
w,h = term.getSize()
x = 0
y = 0
z = 0
f2 = 0
f = 0
g = 0
--[[Functions]]--
function clear()
term.clear()
end
function write(str,x2,y2)
term.setCursorPos(x2,y2)
term.write(str)
end
function cwrite(str,y2)
term.setCursorPos(w/2 - #str/2,y2)
term.write(str)
end
function title(str)
cwrite(string.rep("-",w),1)
cwrite(str,2)
cwrite(string.rep("-",w),3)
end
function firstBootTitle()
cwrite(string.rep("-",w),1)
cwrite("<Installer Setup>",2)
cwrite(string.rep("-",w),3)
end
function optionsTitle()
cwrite(string.rep("-",w),1)
cwrite("<Options>",2)
cwrite(string.rep("-",w),3)
end
function DoTOptions()
cwrite("What will you be locking today?",5)
cwrite("Press 'A' for 'Computer'.",7)
cwrite("Press 'B' for 'Door'.",8)
while x == 0 do
eva,p1a = os.pullEvent("char")
if p1a == "a" then
hel = fs.open("PassLockFiles/DoT","w")
hel.write("term")
hel.close()
x = x + 1
elseif p1a == "b" then
hel = fs.open("PassLockFiles/DoT","w")
hel.write("door")
hel.close()
x = x + 1
end
end
end
function doorSideOption()
cwrite("What side is your door on?",5)
cwrite("Press 'A' for 'Left'.",7)
cwrite("Press 'B' for 'Right'.",8)
cwrite("Press 'C' for 'Top'.",9)
cwrite("Press 'D' for 'Bottom'.",10)
hbl = fs.open("PassLockFiles/doorSide","w")
while y == 0 do
ev,p1 = os.pullEvent("char")
if p1 == "a" then
hbl.write("left")
y = y + 1
elseif p1 == "b" then
hbl.write("right")
y = y + 1
elseif p1 == "c" then
hbl.write("top")
y = y + 1
elseif p1 == "d" then
hbl.write("bottom")
y = y + 1
end
end
hbl.close()
end
function passwordOption()
while z == 0 do
clear()
title("<PASSWORD CENTER>")
term.setCursorPos(3,7)
term.write("NEW PASSWORD: ")
chpass = read("*")
term.setCursorPos(3,9)
term.write("RETYPE PASSWORD: ")
ch2pass = read("*")
if chpass == ch2pass then
clear()
title("<PASSWORD SET!>")
hb = fs.open("PassLockFiles/PWFile","w")
hb.write(ch2pass)
hb.close()
sleep(2)
clear()
z = z + 1
else
clear()
title("<PASSWORDS DON'T MATCH. TRY AGAIN.>")
sleep(2)
clear()
end
end
z = z - 1
end
function optionMenu()
while f2 == 0 do
clear()
title("<OPTIONS>")
cwrite("Press 'A' to change password.",7)
cwrite("Press 'E' to exit.",9)
ev,p1 = os.pullEvent("char")
if p1 == "a" then
passwordOption()
clear()
elseif p1 == "e" then
f2 = f2 + 1
clear()
end
end
f2 = f2 - 1
end
function openDoor(side)
rs.setOutput(side,true)
sleep(2)
rs.setOutput(side,false)
end
--[[Startup Checks]]--
if fs.exists("PassLockBasic") == false then
fs.copy(shell.getRunningProgram(),"PassLockBasic")
su = fs.open("startup","w")
su.write("shell.run(\"PassLockBasic\")")
su.close()
un = fs.open("uninstallPLB","w")
un.writeLine("--[[Variables]]--")
un.writeLine("w,h = term.getSize()")
un.writeLine("--[[Functions]]--")
un.writeLine("function cwrite(str,y)")
un.writeLine(" term.setCursorPos(w/2 - #str/2,y)")
un.writeLine(" term.write(str)")
un.writeLine("end")
un.writeLine("term.clear()")
un.writeLine("cwrite(\"Uninstalling...\",8)")
un.writeLine("fs.delete(\"PassLockBasic\")")
un.writeLine("fs.delete(\"PassLockFiles\")")
un.writeLine("fs.delete(\"startup\")")
un.writeLine("sleep(3)")
un.writeLine("term.clear()")
un.writeLine("cwrite(\"Uninstalled!\",8)")
un.writeLine("sleep(1.5)")
un.writeLine("term.clear()")
un.writeLine("term.setCursorPos(1,1)")
un.close()
end
if fs.exists("PassLockFiles") == false then
fs.makeDir("PassLockFiles")
end
if fs.exists("PassLockFiles/DoT") == false then
h15 = fs.open("PassLockFiles/DoT","w")
h15.close()
end
if fs.exists("PassLockFiles/firstBoot") == false then
h = fs.open("PassLockFiles/firstBoot","w")
h.write("1")
h.close()
end
if fs.exists("PassLockFiles/doorSide") == false then
h13 = fs.open("PassLockFiles/doorSide","w")
h13.close()
end
if fs.exists("PassLockFiles/PWFile") == false then
h14 = fs.open("PassLockFiles/PWFile","w")
h14.close()
end
ha = fs.open("PassLockFiles/firstBoot","r")
if ha.readAll() == "1" then
ha.close()
ha2 = fs.open("PassLockFiles/firstBoot","w")
ha2.write("0")
ha2.close()
clear()
firstBootTitle()
DoTOptions()
clear()
ha3 = fs.open("PassLockFiles/DoT","r")
if ha3.readAll() == "door" then
ha3.close()
firstBootTitle()
doorSideOption()
end
passwordOption()
end
clear()
term.setCursorPos(1,1)
--[[Locking Code]]--
while f == 0 do
d3 = fs.open("PassLockFiles/DoT","r")
h3 = fs.open("PassLockFiles/PWFile","r")
if d3.readAll() == "term" then
title("<LOCKED TERMINAL>")
elseif d3.readAll() == "door" then
title("<LOCKED DOOR>")
else
title("<DEBUG MENU>")
end
d3.close()
term.setCursorPos(3,7)
term.write("PASSWORD: ")
pass = read("*")
if pass == h3.readAll() then
h3.close()
while g == 0 do
clear()
title("<PASS LOCK MENU>")
cwrite("Press 'U' to unlock.",7)
cwrite("Press 'O' to goto options.",8)
ev,p1 = os.pullEvent("char")
if p1 == "u" then
g = g + 1
k2 = fs.open("PassLockFiles/DoT","r")
ds2 = fs.open("PassLockFiles/doorSide","r")
if k2.readAll() == "term" then
f = f + 1
clear()
title("<TERMINAL UNLOCKED>")
sleep(2)
clear()
term.setCursorPos(1,1)
elseif k2.readAll() == "door" then
title("<DOOR UNLOCKED>")
if ds2.readAll() == "left" then
rs.setOutput("left",true)
sleep(2)
rs.setOutput("left",false)
elseif ds2.readAll() == "right" then
rs.setOutput("right",true)
sleep(2)
rs.setOutput("right",false)
elseif ds2.readAll() == "top" then
rs.setOutput("top",true)
sleep(2)
rs.setOutput("top",false)
elseif ds2.readAll() == "bottom" then
rs.setOutput("bottom",true)
sleep(2)
rs.setOutput("bottom",false)
else
cwrite("DOORSIDE ERROR.",7)
end
ds2.close()
end
k2.close()
clear()
elseif p1 == "o" then
optionMenu()
end
end
else
clear()
cwrite("[ERROR]",9)
end
end
clear()
title("<Booting Up CraftOS...>")
sleep(1.5)
cwrite("Welcome, User!",8)
sleep(1)
clear()
term.setCursorPos(1,1)