Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- privChan = 31000 + os.getComputerID()
- pubChan = 31000
- continue = false
- modemFound = peripheral.find("modem")
- if modemFound then
- modem = modemFound
- modem.open(privChan)
- modem.open(pubChan)
- continue = true
- end
- while continue do
- e = {os.pullEvent("modem_message")}
- msg = textutils.unserialize(e[5])
- chan = e[3]
- if chan == pubChan then
- cmd = msg[1]
- args = msg[2]
- if cmd == "Find" then
- if fs.exists(args) then
- modem.transmit(e[4],privChan, textutils.serialize({"success","File found"}))
- end
- elseif cmd == "getFreeSpace" then
- freeSpace = fs.getFreeSpace("/")
- modem.transmit(e[4],privChan, textutils.serialize({"success",freeSpace}))
- end
- elseif chan == privChan then
- cmd = msg[1]
- args = msg[2]
- if cmd == "Request" then
- if fs.exists(args) then
- f = fs.open(args,"r")
- modem.transmit(e[4],privChan, f.readAll())
- f.close()
- else
- modem.transmit(e[4],privChan,textutils.serialize({"error","File not found"}))
- end
- elseif cmd == "SaveFile" then
- f = fs.open(args,"w")
- f.write(msg[3])
- f.close()
- modem.transmit(e[4],privChan, textutils.serialize({"success","File saved"}))
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment