Advertisement
ecco7777

CC Wireless Network

Sep 29th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. sides={"top","bottom","back","front","left","right"}
  2. for i=1,6 do if peripheral.getType(sides[i]) == "modem" then rednet.open(sides[i]) end end
  3. message="talk1"
  4.  
  5. function send()
  6.     rednet.broadcast(io.read())
  7. end
  8.  
  9. function recieve()
  10.     e,modemSide,channel,id,modemMessage =os.pullEvent()
  11.     if e=="modem_message" then
  12.         if modemMessage.sProtocol == "string" then
  13.             if modemMessage.message == "getComputers" then
  14.                 rednet.send(id,os.getComputerID(),"number")
  15.             end
  16.         end
  17.     end
  18. end
  19.  
  20. function getComputers()
  21.     computerIds={}
  22.     e=""
  23.     os.startTimer(1)
  24.     rednet.broadcast("getComputers","string")
  25.     while e~="timer" do
  26.         e,modemSide,channel,id,modemMessage =os.pullEvent()
  27.         if e=="modem_message" then
  28.             computerIds[#computerIds+1]=id
  29.         end
  30.     end
  31.     return computerIds
  32. end
  33.  
  34. function host()
  35.     while true do
  36.         recieve()
  37.     end
  38. end
  39.  
  40. host()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement