Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem")
- rednet.open(peripheral.getName(modem))
- local function WriteFile(message)
- print("Writing received file...")
- local programName = message:match("%S+")
- local actualMsg = message:sub(#programName+2)
- if fs.exists(programName) then print("File already exists. Overwriting...") end
- local file = fs.open(programName, "w")
- file.write(actualMsg)
- file.close()
- print("Wrote file " .. programName .. ".")
- end
- local function Execute(message)
- local path = message:match("%S+")
- local args = message:sub(#path+2)
- os.run({}, path, args)
- end
- local function ProcessMessage(message)
- local cmd = message:match("%S+")
- local cmdLower = cmd:lower()
- local justMessage = message:sub(#cmd+2)
- if cmdLower == "file" then
- WriteFile(justMessage)
- end
- if cmdLower == "exec" then
- Execute(justMessage)
- end
- end
- local function AwaitMessage()
- print("\nAwaiting Message...")
- local computerId, msg, protocol = rednet.receive()
- print("Received Message..")
- ProcessMessage(msg)
- end
- while true do
- AwaitMessage()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement