Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m_FolderName = "."..shell.getRunningProgram()
- -- Interaction code
- function AskForInput(msg)
- write(msg)
- l_Input = read()
- return l_Input
- end
- -- Data stuff
- function Store(Data, Filename)
- l_File = fs.open(m_FolderName.."/"..Filename, "w")
- l_File.write(Data)
- l_File.close()
- end
- function Read(Filename)
- l_File = fs.open(m_FolderName.."/"..Filename, "r")
- l_ReturnText = l_File.readAll()
- l_File.close()
- return l_ReturnText
- end
- function Exists(Filename)
- return fs.exists(m_FolderName.."/"..Filename)
- end
- -- Screen Visuals
- function ResetCursor()
- term.setCursorPos(1,1)
- end
- function DisplayInfo(Message)
- term.clear()
- ResetCursor()
- write(Message)
- end
- -- Computer Configuration at Startup
- function ConfigureRouter()
- l_Value = AskForInput("Enter the router side:")
- Store(l_Value, "rtsd")
- l_Value = AskForInput("Enter the redstone side:")
- Store(l_Value, "rssd")
- end
- function ConfigureComputer()
- l_Value = AskForInput("Enter the REMOTE computer ID: ")
- Store(l_Value, "rmid")
- l_Value = AskForInput("Enter the PASSWORD to unlock the REMOTE computer.")
- Store(l_Value, "rmpw")
- end
- function AutoSetup() --Autosetups the user and the password upon first execution.
- rmid, rmpw = rednet.receive()
- end
- -- Main Iteration
- function CheckForMessages()
- rmid, rmpw = rednet.receive()
- return IsUser(rmpw, rmid)
- end
- -- Security??? stuff?
- function IsUser(PW, ID)
- rmid = tonumber(Read("rmid"))
- rmpw = Read("rmpw")
- return rmid == ID and rmpw == PW
- end
- -- Small Code.
- function ToggleRedstone(Enabled)
- redstone.setOutput(Read("rssd"), Enabled)
- end
- -- Start of main program.
- function main()
- m_Running = true
- if not fs.exists(m_FolderName) then
- ConfigureRouter()
- ConfigureComputer()
- DisplayInfo("All set!")
- sleep(2)
- os.reboot()
- else if not Exists("rmid") then --Do the autosetup if it hasnt been done before.
- while(not Exists("rmid")) do
- AutoSetup()
- end
- DisplayInfo("All setup!")
- read()
- else -- Enter here when its all setup
- local l_Router = Read("rtsd")
- rednet.open(l_Router)
- while m_Running do
- DisplayInfo("Running!")
- if CheckForMessages() then
- DisplayInfo("User Confirmed!")
- ToggleRedstone(true)
- sleep(3)
- ToggleRedstone(false)
- end
- end
- end
- end
- end
- -- Actual Code Executing ---
- local no_error, errorMSG = pcall(main)
- if not no_error then
- DisplayInfo(errorMSG)
- end
- -- Pretty clean huh? -------
Advertisement
Add Comment
Please, Sign In to add comment