Advertisement
goldfiction

ishd2

Jun 26th, 2025
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | Gaming | 0 0
  1. -- ISH Protocol (daemon)
  2.  
  3. -- Get the side of the modem
  4. write("modem side = ")
  5. modem_side = io.read()
  6. write("Hostname = ")
  7. hostname = io.read()
  8. protocol = "ISH"
  9.  
  10. -- Check the modem
  11. print("Checking modem...")
  12. local modem = peripheral.wrap(modem_side)
  13. wireless = modem.isWireless()
  14. if wireless then
  15.   print("Selected modem is wireless.")
  16. else
  17.   print("Selected modem is wired and will not work with turtles.")
  18. end
  19.  
  20. -- Check if rednet is open
  21. print("Checking if rednet is open... " .. tostring(rednet.isOpen(modem_side)))
  22. if not rednet.isOpen(modem_side) then
  23.   -- Open rednet
  24.   print("Opening rednet...")
  25.   rednet.open(modem_side)
  26. else
  27.   print("Rednet is already open...")
  28. end
  29.  
  30. -- Register hostname
  31. print("Registering hostname " .. hostname .. " on protocol " .. protocol)
  32. rednet.host(protocol, hostname)
  33.  
  34. local function run2(...)
  35.   -- First, create a window object that covers the entire screen
  36.   local win = window.create(term.current(), 1, 1, term.getSize())
  37.  
  38.   -- Then, redirect the terminal to that window
  39.   local old = term.redirect(win)
  40.  
  41.   -- Run the program, shell.run returns whether or not the program errored.
  42.   local ok = shell.run(...)
  43.  
  44.   -- Restore the old terminal
  45.   term.redirect(old)
  46.  
  47.   -- Return the window object, as well as whether or not the program errored.
  48.   return win
  49. end
  50.  
  51. -- ~Daemon Specific code~
  52. print("Start listening...")
  53. while true do
  54.   senderID, args, protocol = rednet.receive(protocol, 600)
  55.   for i,v in ipairs(args) do
  56.     write(v .. " ")
  57.   end
  58.   if args[2] == nil then
  59.     result = run2(args[1])
  60.     rednet.send(senderID, result, protocol)
  61.   elseif args[2] ~= nil then
  62.     if args[3] == nil then
  63.       result = run2(args[1], args[2])
  64.       rednet.send(senderID, result, protocol)
  65.     elseif args[4] == nil then
  66.       result = run2(args[1], args[2], args[3])
  67.       rednet.send(senderID, result, protocol)
  68.     end
  69.   else
  70.     result = run2(args[1])
  71.     rednet.send(senderID, result, protocol)
  72.   end
  73. end
  74.  
  75. rednet.close()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement