Advertisement
Eliaslb584

Remoteterm

Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. local tArgs = {...}
  2. --1 = /c or /h, 2 = Channel
  3.  
  4. if tArgs[1] == nil or tArgs[2] == nil then
  5.     print("Usage: Remoteterm /c or /h, Channel")
  6.     return
  7. end
  8.  
  9. local modem = nil
  10.  
  11. for _, name in pairs(peripheral.getNames()) do
  12.   if peripheral.getType(name) == "modem" then
  13.     modem = peripheral.wrap(name)
  14.   end
  15. end
  16.  
  17. if modem == nil then
  18.     print("Could not find modem")
  19. end
  20.  
  21. local command = ""
  22.  
  23. if tArgs[1] == "/h" then
  24.    
  25.     modem.open(tonumber(tArgs[2]))
  26.  
  27.     while true do
  28.         local evt, p1, p2, p3, p4, p5 = os.pullEvent()
  29.  
  30.         if evt == "key" then
  31.             if p1 == 28 then
  32.                 shell.run(command)
  33.                 command = ""
  34.             end
  35.         end
  36.  
  37.         if evt == "char" then
  38.             command = command ..p1
  39.         end
  40.  
  41.         if evt == "modem_message" then
  42.             if p2 == tArgs[2] then
  43.                 command = p4
  44.                 shell.run(command)
  45.                 command = ""
  46.             end
  47.         end
  48.     end
  49. elseif tArgs[1] == "/c" then
  50.     while true do
  51.         print("Send command: ")
  52.         command = read()
  53.         modem.transmit(tonumber(tArgs[2]),tonumber(tArgs[2]+1),command)
  54.         command = ""
  55.     end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement