Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mProt = "masterRC"
- rednet.open("right")
- -- mProt is the protocol the computer will be using. You can also configure what side the wireless modem is on
- status = {scan = 1,upload = 1,download = 1, fileList = 1,redstone = 1}
- -- Easily configure which programs you want running and which ones you don't by simply setting 1 for those you want running
- helpTable = {scan = "scan + log players nearby",upload = "upload a file to connected computer", download = "download a file from connected computer", fileList = "list files on connected computer", redstone = "control sides of connected computer to emit redstone on"}
- -- Default help messages for each program
- scannerDir = "baseChecker/"
- myFunction = "scanner computer!"
- -- Called when the remote computer lists available computers it can connect with
- help = ""
- for program, progHelp in pairs(helpTable) do
- if status[program] == 1 then
- help = help .. program .. " - " .. progHelp .. "\n"
- end
- end
- help = help:sub(1,string.len(help) - 1)
- -- Creates the help variable from the programs that are active
- while true do
- sendID, msg = rednet.receive(mProt)
- if msg == "list" then
- rednet.send(sendID, myFunction, mProt)
- -- Will respond to computers that are running list unless running connect
- elseif msg == "connect" then
- rednet.send(sendID, {"Connected!",status}, mProt)
- -- Making the link from the mRemote program to the mControl program
- while true do
- connectID, msg = rednet.receive(mProt)
- if connectID == sendID then
- if msg == "exit" then
- rednet.send(connectID, "Successfully exited the program", mProt)
- break
- -- Exits the connect cycle so that it will respond to list and for other computers to connect to it
- elseif msg[1] == "help" then
- rednet.send(connectID, help, mProt)
- -- Sends the help variable through
- elseif msg[1] == "upload" then
- if fs.exists(msg[3]) == false then
- rednet.send(connectID, "send", mProt)
- uselessID, downloadedFile = rednet.receive(mProt)
- openFile = fs.open(msg[3], 'w')
- openFile.write(downloadedFile)
- openFile.close()
- else
- rednet.send(connectID, "File already exists on connected computer.", mProt)
- end
- -- Handles the upload function
- elseif msg[1] == "download" then
- if fs.exists(msg[2]) == true and fs.isDir(msg[2]) == false then
- fileOpen = fs.open(msg[2], 'r')
- stringSend = fileOpen.readAll()
- fileOpen.close()
- tableSend = {stringSend, "Successfully downloaded file."}
- rednet.send(connectID, tableSend, mProt)
- else
- rednet.send(connectID, "File does not exist on connected computer.", mProt)
- end
- -- Handles the download function
- elseif msg[1] == "fileList" then
- programList = fs.list("")
- files = ""
- for i=1,#programList do
- if fs.isDir(programList[i]) == false then
- if files == "" then
- files = programList[i]
- else
- files = files .. ", " .. programList[i]
- end
- end
- end
- -- Handles the fileList function by sending a list of files (not directories) through
- rednet.send(connectID, files, mProt)
- elseif msg[1] == "redstone" and status.redstone == 1 then
- if msg[2] == "up" or msg[2] == "down" or msg[2] == "back" or msg[2] == "front" or msg[2] == "left" or msg[2] == "right" then
- if msg[3] == "on" then
- -- First checks to see if msg[2] is a valid side then checks if msg[3] is a valid state
- redstone.setOutput(msg[2], true)
- rednet.send(connectID, "Set output " .. msg[2] .. " to " .. msg[3], mProt)
- -- Turns the side in msg[2] on
- elseif msg[3] == "off" then
- redstone.setOutput(msg[2], false)
- rednet.send(connectID, "Set the redstone on the " .. msg[2] .. " to " .. msg[3], mProt)
- -- Turns the side in msg[2] off
- else
- rednet.send(connectID, 'Invalid syntax. Use "redstone [side] [on/off]"', mProt)
- end
- else
- rednet.send(connectID, 'Invalid side. Available sides are: up, down, back, front, left, right', mProt)
- end
- -- Error messages to catch every combination
- elseif msg[1] == "scan" then
- function toSRC(item)
- openSRC = fs.open(scannerDir .. "src", "w")
- openSRC.write(item)
- openSRC.close()
- end
- if msg[2] == "start" then
- toSRC("[0/0/0]")
- shell.run("bg " .. scannerDir .. "scanner")
- rednet.send(connectID, "Starting the scanner program.", mProt)
- elseif msg[2] == "stop" then
- readFile = fs.open(scannerDir .. "src","r")
- contents = readfile.readAll()
- readfile.close()
- toSRC("[0/0/0] stop")
- rednet.send(connectID, "Stopping the scanner program at " .. contents,mProt)
- else
- rednet.send(connectID, 'Invalid syntax. Use "scan start" or "scan stop"')
- end
- else
- rednet.send(connectID, 'Invalid command. Type "help" for options.', mProt)
- -- Default path if msg[1] doesn't get caught by any of the above functions
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement