Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if turtle then
- function CmdLoop()
- local event, modemSide, senderChannel,
- replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message == "exit" then
- peripheral.call("right", "transmit", sChan, rChan, "Disconnecting.")
- peripheral.call("right", "closeAll")
- os.reboot()
- end
- if message == "send file" then
- local event, modemSide, senderChannel,
- replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local file = fs.open("file_received", "w")
- file.write(message)
- file.close()
- CmdLoop()
- end
- if message ~= "exit" or "send file" then
- shell.run(message)
- os.sleep(3)
- peripheral.call("right","transmit", sChan, rChan, "Command complete")
- CmdLoop()
- end
- end
- print("Turtle Remote - Turtle Version")
- print("What channel to broadcast returns on?")
- sChan = io.read()
- sChan = tonumber(sChan)
- print("What channel should commands be received on?")
- rChan = io.read()
- rChan = tonumber(rChan)
- print("Receiving commands...")
- peripheral.call("right", "open", rChan)
- CmdLoop()
- end
- if not turtle then
- function sendFile()
- print("What file to send?")
- sFile = io.read()
- --Confirm file exists
- local sPath = shell.resolve(sFile)
- if not fs.exists(sPath) or fs.isDir(sPath) then
- print("No such file")
- return
- end
- --Read the entire file
- sName = fs.getName(sPath)
- file = fs.open(sPath, "r")
- message = file.readAll()
- file.close()
- --Send file through Modem
- peripheral.call(mSide, "transmit", sChan, rChan, message)
- print("Sent file. File is saved as "..sName.." in the root directory.")
- os.sleep(1)
- peripheral.call(mSide, "transmit", sChan, rChan, "rename file_received "..sName.."")
- sLoop()
- end
- function sLoop()
- print("Type command: (Note: Send files with 'send file')")
- cmd = io.read()
- if cmd == "remote" then
- print("Remote session already open")
- end
- peripheral.call(mSide, "transmit", sChan, rChan, cmd)
- if cmd == "exit" then
- peripheral.call(mSide, "closeAll")
- os.reboot()
- end
- if cmd == "send file" then
- sendFile()
- end
- if cmd ~= "send file" or "exit" then
- print("Sending command...")
- rLoop()
- end
- end
- function rLoop()
- print("Receiving return...")
- local event, modemSide, senderChannel,
- replyChannel, message, senderDistance = os.pullEvent("modem_message")
- print("Turtle on channel "..senderChannel.." says: "..message)
- print("The turtle is: "..senderDistance.." blocks away from me.")
- if message == "Disconnecting." then
- peripheral.call(mSide, "closeAll")
- os.reboot()
- end
- if cmd ~= "Disconnecting." then
- sLoop()
- end
- end
- print("Turtle Remote - Computer Version")
- print("What side is the modem on?")
- mSide = io.read()
- print("What channel to transmit commands?")
- sChan = io.read()
- sChan = tonumber(sChan)
- print("What channel should returns be received on?")
- rChan = io.read()
- rChan = tonumber(rChan)
- peripheral.call(mSide, "open", rChan)
- sLoop()
- end
Advertisement
Add Comment
Please, Sign In to add comment