Advertisement
Guest User

client

a guest
Aug 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. local tArgs = {...}
  2. tArgs[1] = tonumber(tArgs[1])
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. local channel = tArgs[1]
  6. local modems = table.pack(peripheral.find("modem"))
  7. local m = nil
  8. for i = 1,#modems do
  9.   if modems[i]["isWireless"]() then
  10.     m = modems[i]
  11.   end
  12. end
  13. if not m then
  14.   error("No Wireless Modem!")
  15. end
  16. local pullEvent = function()
  17. m.open(tArgs[1])
  18.   local args = nil
  19.   while true do
  20.     args = table.pack(os.pullEvent())
  21.     if args[1] == "modem_message" then
  22.       if string.sub(args[5],1,5) == "lua: " then
  23.         args[5] = textutils.unserialize(string.sub(args[5],6))
  24.         if string.sub(args[5][1],1,4) == "term" then
  25.           local key = string.sub(args[5][1],6)
  26.           table.remove(args[5],1)
  27.           term[key](table.unpack(args[5]))
  28.         elseif args[5][1] == "print" then
  29.           table.remove(args[5],1)
  30.           print(table.unpack(args[5]))
  31.         end
  32.       end
  33.     else
  34.       break
  35.     end
  36.   end
  37.   return table.unpack(args)
  38. end
  39. while true do
  40.   m.transmit(5,5,"command: "..textutils.serialize(table.pack(pullEvent())))
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement