Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function neton()
- Open,FreeSide=false,nil
- for n,Side in pairs(rs.getSides())do
- if peripheral.getType(Side)=="modem"then
- FreeSide=Side
- if rednet.isOpen(Side)then
- Open=true
- end
- end
- end
- if not Open then
- if FreeSide then
- rednet.open(FreeSide)
- else
- print("No modem attached")
- end
- end
- return true
- end
- function netoff()
- rednet.close(FreeSide)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function locator(acton,looking)
- line=0
- this=string.byte(looking)
- endline=string.len(acton)
- while true do
- if string.byte(acton,line)==this then
- return line
- end
- if line==endline then return end
- line=line+1
- end
- end
- a={...}
- id=(a[1])
- filename=(a[2])
- neton()
- if id==nil then
- clear()
- print("To Quit Push Q")
- print("ID: "..os.getComputerID())
- while true do
- z0,z1,z2=os.pullEvent()
- if z0=="rednet_message"then
- pos=locator(z2," ")
- name=tostring(string.sub(z2,1,pos-1))
- text=tostring(string.sub(z2,pos+1,string.len(z2)))
- file=io.open(name,"w")
- file:write(text)
- file:close()
- clear()
- print("Received: "..name)
- netoff()
- break
- end
- if z0=="char"then
- if z1=="q"then
- print("Stoping")
- sleep(1)
- netoff()
- sleep(1)
- clear()
- break
- end
- end
- end
- else
- file=io.open(filename,"r")
- text=file:read("*a")
- file:close()
- rednet.send(tonumber(id),filename.." "..text)
- clear()
- print("Sent: "..filename)
- netoff()
- end
Add Comment
Please, Sign In to add comment