Advertisement
melzneni

sys_service_terminal

Feb 9th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. args = { ... }
  2. local rootId = tonumber(args[1])
  3.  
  4. function string:split(s, delimiter)
  5. local result = {};
  6. for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
  7. table.insert(result, match);
  8. end
  9. return result;
  10. end
  11.  
  12. function getMsgData(msg)
  13. local i, j = string.find(msg, ":")
  14. local tag = string.sub(msg, 1, i - 1)
  15. local pts = string:split(string.sub(msg, i + 1, -1), ",")
  16. return tag, pts
  17. end
  18.  
  19. --syslib end
  20.  
  21. rednet.open("back")
  22.  
  23. local done = false
  24. while not done do
  25. io.write("local-network>")
  26. local input = read()
  27. local id, msg = rednet.receive(0.1)
  28. if id ~= nil then
  29. local tag, pts = getMsgData(msg)
  30. if tag == "@programs" then
  31. if pts[1] == "terminate" then
  32. done = true
  33. break
  34. else print("unknown message: ", msg)
  35. end
  36. end
  37. end
  38.  
  39. if input ~= nil then
  40. local pts = string:split(input, " ")
  41. if pts[1] == "reboot" then --todo maybe with password
  42. rednet.send(rootId, "@root:reboot")
  43. done = true
  44. else print("unknown command: " .. pts[1])
  45. end
  46. end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement