Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("bottom")
- iniOpts = {"Reboot All PCs","Change Password","Add Door","Remove Door","Lock All Doors","Open All Doors","Reset All Doors","Custom Message","Turtle Run"}
- lime = colors.lime
- black = colors.black
- modem.open(324)
- msgTab = {}
- turtle = {}
- turtleNum = {}
- turtleDetails = {}
- notNum = true
- secretPass = "Ehfks87-i"
- secretPass2 = "sgxyg&%UI33%^&HS34DH-N"
- turtlePort = 512
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function makeString(l)
- if l < 1 then return nil end -- Check for l < 1
- local s = "" -- Start string
- for i = 1, l do
- s = s .. string.char(math.random(32, 126)) -- Generate random number from 32 to 126, turn it into character and add to string
- end
- return s -- Return string
- end
- function menu(opts)
- doIt = true
- currSelect = 1
- while doIt do
- x,y = term.getSize()
- clear()
- term.setCursorPos(x,1)
- term.setBackgroundColor(lime)
- print("^")
- term.setBackgroundColor(black)
- if #opts <= y - 4 then
- for i,v in pairs(opts) do
- yPos = 2 + i
- term.setCursorPos(math.floor(x - #v-4)/2,yPos)
- if currSelect == i then
- print("[["..v.."]]")
- else
- print(" "..v.." ")
- end
- end
- event , button , xPos , yPos = os.pullEvent()
- if event == "key" then
- if button == keys.up then
- currSelect = currSelect - 1
- elseif button == keys.down then
- currSelect = currSelect + 1
- elseif button == keys.enter then
- doIt = false
- clear()
- end
- elseif event == "mouse_click" then
- clear()
- doIt = false
- currSelect = yPos - 2
- clear()
- elseif event == "monitor_touch" then
- clear()
- doIt = false
- currSelect = yPos - 2
- clear()
- end
- if currSelect == 0 then
- currSelect = #opts
- elseif currSelect == math.floor(#opts + 1) then
- currSelect = 1
- end
- else
- for i,v in pairs(opts) do
- yPos = math.floor(y/2) - currSelect + i
- term.setCursorPos(math.floor(x - #v-4)/2,yPos)
- if currSelect == i then
- print("[["..v.."]]"..i)
- else
- print(" "..v.." "..i)
- end
- end
- event , button , xPos , yPos = os.pullEvent()
- if event == "key" then
- if button == keys.up then
- currSelect = currSelect + 1
- elseif button == keys.down then
- currSelect = currSelect - 1
- elseif button == keys.enter then
- doIt = false
- clear()
- end
- elseif event == "mouse_click" then
- doIt = false
- currSelect = yPos - currSelect + math.floor(y/2)
- clear()
- elseif event == "monitor_touch" then
- doIt = false
- currSelect = yPos - math.floor(y/2) + currSelect
- clear()
- end
- if currSelect == 0 then
- currSelect = 1
- elseif currSelect == #opts + 1 then
- currSelect = #opts
- end
- if currSelect < 1 then
- currSelect = 1
- doIt = true
- elseif currSelect > #opts then
- currSelect = #opts
- doIt = true
- end
- end
- end
- return currSelect
- end
- function rebootPc()
- modem.transmit(3721,1,"reboot")
- end
- function changePass()
- clear()
- print("These are the available doors:")
- print()
- fil = {}
- fil = fs.list("disk")
- print("What password do you wish to change? ")
- sel = menu(fil)
- clear()
- if fs.exists("disk/"..fil[sel]) then
- files = fs.open("disk/"..fil[sel], "r")
- print("Current password is: "..files.readAll())
- files.close()
- files = fs.open("disk/"..fil[sel], "w")
- write("Input new password: ")
- files.write(read())
- files.close()
- rebootPc()
- else
- print("This door does not exist!")
- sleep(3)
- changePass()
- end
- end
- function addDoor()
- clear()
- print("What is the name of the new door? ")
- print("(Type <nodoor> if you do not want to create a door.) ")
- write(">")
- desDoor = read()
- if fs.exists("disk/"..desDoor) then
- print("Door does already exist....")
- sleep(2)
- addDoor()
- elseif desDoor == "nodoor" then
- clear()
- else
- clear()
- write("Input desired password: ")
- doorN = fs.open("disk/"..desDoor,"w")
- newP = read()
- doorN.write(newP)
- doorN.close()
- shell.run("startup")
- end
- end
- function deleteDoor()
- clear()
- listF = fs.list("disk")
- delD = menu(listF)
- write("Are you sure you want to delete door "..listF[delD].."? (y/n)")
- sureOrNot = read()
- if sureOrNot == "y" then
- fs.delete("disk/"..listF[delD])
- end
- end
- function lock()
- modem.transmit(3721,1,"lock")
- end
- function rst()
- modem.transmit(3721,1,"reset")
- end
- function openD()
- modem.transmit(3721,1,"open")
- end
- function customMsg()
- clear()
- term.write("Do you want to encrypt the message? <y/n> ")
- answerToQ = read()
- if answerToQ == "n" then
- while notNum do
- clear()
- term.write("Input channel: ")
- chan = tonumber(read())
- if type(chan) == "number" then
- notNum = false
- end
- end
- term.write("Input message: ")
- messa = read()
- modem.transmit(57, tonumber(chan), messa)
- elseif answerToQ == "y" then
- notNum = true
- while notNum do
- clear()
- term.write("Input channel: ")
- chan = tonumber(read())
- if type(chan) == "number" then
- notNum = false
- end
- end
- notNum = true
- term.write("Input message: ")
- messa = read()
- while notNum do
- term.write("Input password: <longer than 4 > ")
- passEncr = read()
- if #passEncr > 3 then
- notNum = false
- end
- end
- messa = encrypt.encrypt(messa,passEncr)
- modem.transmit(57, tonumber(chan), messa)
- end
- end
- function turtleRun()
- local turtle = {}
- local turtleNum = {}
- clear()
- modem.transmit(93,2,textutils.serialize({"turtle"}))
- print("Getting information...")
- local event, side, ch1, ch2, msg = os.pullEvent("modem_message")
- msgTab = textutils.unserialize(msg)
- for i,v in pairs(msgTab) do
- turtleDetails = textutils.unserialize(v)
- turtle[i] = turtleDetails
- turtleNum[i] = tostring(turtleDetails[1])
- end
- selectedTurtle = menu(turtleNum)
- print("ID: "..turtle[selectedTurtle][1])
- print("X: "..turtle[selectedTurtle][2])
- print("Y: "..turtle[selectedTurtle][3])
- print("Z: "..turtle[selectedTurtle][4])
- write("Did you select the right turtle? <y/n>")
- local answer = read()
- if answer == "y" then
- clear()
- write("What program would you like to run? ")
- modem.transmit(57,512,textutils.serialize({"run",tonumber(turtle[selectedTurtle][1]),read()}))
- --qevent, qside, qch1, qch2, qmsg = os.pullEvent("modem_message")
- --print("msg")
- --sleep(3)
- --modem.transmit(57,turtlePort,encrypt.encrypt(encrypt.decrypt(qmsg,secretPass),secretPass2))
- else
- return false
- end
- end
- function options()
- if iniSelect == 1 then
- rebootPc()
- elseif iniSelect == 2 then
- changePass()
- elseif iniSelect == 3 then
- addDoor()
- elseif iniSelect == 4 then
- deleteDoor()
- elseif iniSelect == 5 then
- lock()
- elseif iniSelect == 6 then
- openD()
- elseif iniSelect == 7 then
- rst()
- elseif iniSelect == 8 then
- customMsg()
- elseif iniSelect == 9 then
- turtleRun()
- end
- end
- iniSelect = menu(iniOpts)
- clear()
- options()
- shell.run("startup")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement