Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getDevices(deviceType) -- This function was taken from https://github.com/sandalle/minecraft_bigreactor_control and has been modified by https://github.com/Sanwi
- local deviceName = nil
- local deviceIndex = 1
- local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
- local peripheralList = peripheral.getNames() -- Get table of connected peripherals
- for peripheralIndex = 1, #peripheralList do -- Log every device found
- if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then -- Log devices found which match deviceType and which device index we give them
- deviceNames[deviceIndex] = peripheralList[peripheralIndex]
- deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
- deviceIndex = deviceIndex + 1
- end
- end -- for peripheralIndex = 1, #peripheralList do
- return deviceList, deviceNames
- end
- local function listen(modem,channels)
- --Open channels
- for i=1, #channels do
- modem.setListening(channels[i],true)
- end
- --Listen
- local event, modemSide, senderID, channel, message = os.pullEvent("lan_message")
- --Close channels
- for i=1, #channels do
- modem.setListening(channels[i],false)
- end
- local channel = tonumber(channel)
- return event, modemSide, senderID, channel, message
- end
- channels = {101,102,103,104}
- deviceList, deviceNames = getDevices("lan nic")
- modem = deviceList[1]
- modem.setPromiscuous(true)
- while true do
- local event, modemSide, senderID, channel, message = listen(modem,channels)
- print(senderID..":"..message)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement