Advertisement
Marlingaming

AFIDOS - Primary Module - Task Manager

May 6th, 2022 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local computer = require("computer")
  4. local io = require("io")
  5. local filesystem = require("filesystem")
  6. local m = component.modem -- get primary modem component
  7.  
  8.  
  9. function RunTasks(target)
  10. local file = io.open(target,"r")
  11. local content
  12. repeat
  13. content = file.readLine()
  14. if content ~= nil then shell.run(content) end
  15. until content == nil
  16. file.close()
  17. print("tasks Completed")
  18. end
  19.  
  20. function CheckLocalStability()
  21. if computer.energy() < 8 then
  22. error("insignificant power for operations")
  23. elseif filesystem.exists("AFIDOS/StartupTasks.txt") == false then
  24. error("starting tasks missing")
  25. elseif filesystem.exists("AFIDOS/RoutineTasks.txt") == false then
  26. error("routine tasks missing")
  27. else
  28. Loop()
  29. end
  30. end
  31.  
  32. function TranslateMessage(a,b,c,d,e,f, g)
  33. if e == "Alert" then
  34.  
  35. elseif e == "update" then
  36.  
  37. elseif e == "admin" then
  38. if f == "shutdown" then
  39. computer.shutdown()
  40. elseif f == "reboot" then
  41. computer.shutdown(true)
  42. elseif f == "diagnostics" then
  43.  
  44. end
  45. elseif e == "system" then
  46.  
  47. elseif e == "runTasks" then
  48. RunTasks(f)
  49. elseif e == "upload" then
  50. local file = io.open(g,"w")
  51. file.write(f)
  52. file.close()
  53. elseif e == "download" then
  54. local file = io.open(f,"r")
  55. m.send(a,c,file.readAll())
  56. file.close()
  57. end
  58. end
  59.  
  60. function Loop()
  61. RunTasks("AFIDOS/StartupTasks.txt")
  62. m.open(53)
  63. local Reboot = false
  64. while true do
  65. local a, b, c, d, e, f, g, h = event.pull([timer: 5])
  66. RunTasks("AFIDOS/RoutineTasks.txt")
  67. if a == "modem_message" then
  68. TranslateMessage(b,c,d,e,f,g,h)
  69. elseif computer.energy() < 8 then
  70. Reboot = false
  71. break
  72. elseif computer.runtime() > 10800 then
  73. Reboot = true
  74. break
  75. end
  76. end
  77. computer.beep()
  78. computer.shutdown(Reboot)
  79. end
  80.  
  81. CheckLocalStability()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement