SHOW:
|
|
- or go back to the newest paste.
| 1 | --remote | |
| 2 | clients = {}
| |
| 3 | ||
| 4 | function clr() | |
| 5 | term.clear() | |
| 6 | term.setCursorPos(1,1) | |
| 7 | end | |
| 8 | ||
| 9 | local function openRednet() | |
| 10 | for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
| |
| 11 | if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then | |
| 12 | rednet.open(side) | |
| 13 | return side | |
| 14 | end | |
| 15 | end | |
| 16 | print("no modem present")
| |
| 17 | end | |
| 18 | ||
| 19 | local function searchForNewClients() | |
| 20 | while true do | |
| 21 | rednet.broadcast("newhost")
| |
| 22 | os.startTimer(15) | |
| 23 | local event, id, message, distance = os.pullEvent() | |
| 24 | if event == "rednet_message" and message == "pairing" then | |
| 25 | rednet.send(id,"connected " .. os.getComputerID()) | |
| 26 | clients[table.getn(clients)] = id | |
| 27 | return true | |
| 28 | elseif event == "timer" then | |
| 29 | return false | |
| 30 | end | |
| 31 | end | |
| 32 | end | |
| 33 | ||
| 34 | local function main() | |
| 35 | while true do | |
| 36 | clr() | |
| 37 | ||
| 38 | ||
| 39 | sleep(5) | |
| 40 | end | |
| 41 | end | |
| 42 | ||
| 43 | local function background() | |
| 44 | while true do | |
| 45 | searchForNewClients() | |
| 46 | os.sleep(10) | |
| 47 | end | |
| 48 | end | |
| 49 | ||
| 50 | --Main | |
| 51 | side = openRednet() | |
| 52 | if side == nil then | |
| 53 | print("no modem found")
| |
| 54 | else | |
| 55 | parallel.waitForAll(main(), background()) | |
| 56 | while true do | |
| 57 | clr() | |
| 58 | print("Enter the command")
| |
| 59 | term.setCursorPos(2,3) | |
| 60 | local command = read() | |
| 61 | rednet.broadcast(command) | |
| 62 | term.setCursorPos(2,5) | |
| 63 | print("Sending ...")
| |
| 64 | sleep(0.25) | |
| 65 | end | |
| 66 | end |