Advertisement
DOGGYWOOF

Untitled

Aug 28th, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. -- List of required files
  2. local requiredFiles = {
  3. "/disk/bootloader/VA11-ILLA.lua",
  4. "/disk/os/home.lua",
  5. "/disk/os/lock.lua",
  6. "/disk/boot/boot-animation",
  7. "/disk/error/BSOD.lua",
  8. -- Add more file names as needed
  9. }
  10.  
  11. -- Function to check if all required files exist
  12. local function checkFiles()
  13. local missingFiles = {}
  14.  
  15. for _, fileName in ipairs(requiredFiles) do
  16. if not fs.exists(fileName) then
  17. table.insert(missingFiles, fileName)
  18. end
  19. end
  20.  
  21. return missingFiles
  22. end
  23.  
  24. -- Function to handle incoming commands
  25. local function handleCommand(command)
  26. if command == "/disk/ACPI/shutdown" then
  27. print("[INFO] Shutdown command received.")
  28. os.shutdown()
  29. elseif command == "/disk/ACPI/reboot" then
  30. print("[INFO] Reboot command received.")
  31. os.reboot()
  32. elseif command == "/disk/ACPI/logoff" then
  33. print("[INFO] Logoff command received.")
  34. -- Implement logoff behavior if needed, or shutdown/reboot as an alternative
  35. print("Logoff command is not supported. Please use shutdown or reboot.")
  36. else
  37. print("[ERROR] Unknown command: " .. command)
  38. end
  39. end
  40.  
  41. -- Function to start the client and listen for commands
  42. local function startClient()
  43. -- Automatically detect a modem and open rednet
  44. local modemSide
  45. for _, side in ipairs({"left", "right", "top", "bottom", "front", "back"}) do
  46. if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  47. modemSide = side
  48. break
  49. end
  50. end
  51.  
  52. if modemSide then
  53. rednet.open(modemSide)
  54. print("[INFO] Modem found and opened on side: " .. modemSide)
  55.  
  56. -- Set the ID for this computer (this ID should match the ID used in the server script)
  57. local computerID = os.getComputerID()
  58.  
  59. print("[INFO] Listening for commands on ID: " .. computerID)
  60. while true do
  61. local senderID, command = rednet.receive("control")
  62. if senderID then
  63. print("[INFO] Command received from ID: " .. senderID)
  64. handleCommand(command)
  65. end
  66. end
  67.  
  68. -- Close the modem (though this is never reached in this loop)
  69. rednet.close(modemSide)
  70. else
  71. print("[ERROR] No modem found. Please connect a modem to run the client.")
  72. end
  73. end
  74.  
  75. -- Coroutine to run the client in the background
  76. local function clientCoroutine()
  77. local co = coroutine.create(startClient)
  78. coroutine.resume(co)
  79. end
  80.  
  81. -- Main function to execute file checks and start the client in the background
  82. local function main()
  83. -- Start the client coroutine
  84. clientCoroutine()
  85.  
  86. -- Check for required files
  87. local missing = checkFiles()
  88.  
  89. if #missing > 0 then
  90. -- Execute repair-loader if any files are missing
  91. shell.run("repair-loader")
  92. else
  93. -- All files exist, continue with starting the normal process
  94. shell.run("/disk/boot/start-check.lua")
  95. end
  96. end
  97.  
  98. -- Run the main function
  99. main()
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement