Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- List of required files
- local requiredFiles = {
- "/disk/bootloader/VA11-ILLA.lua",
- "/disk/os/home.lua",
- "/disk/os/lock.lua",
- "/disk/boot/boot-animation",
- "/disk/error/BSOD.lua",
- -- Add more file names as needed
- }
- -- Function to check if all required files exist
- local function checkFiles()
- local missingFiles = {}
- for _, fileName in ipairs(requiredFiles) do
- if not fs.exists(fileName) then
- table.insert(missingFiles, fileName)
- end
- end
- return missingFiles
- end
- -- Function to handle incoming commands
- local function handleCommand(command)
- if command == "/disk/ACPI/shutdown" then
- print("[INFO] Shutdown command received.")
- os.shutdown()
- elseif command == "/disk/ACPI/reboot" then
- print("[INFO] Reboot command received.")
- os.reboot()
- elseif command == "/disk/ACPI/logoff" then
- print("[INFO] Logoff command received.")
- -- Implement logoff behavior if needed, or shutdown/reboot as an alternative
- print("Logoff command is not supported. Please use shutdown or reboot.")
- else
- print("[ERROR] Unknown command: " .. command)
- end
- end
- -- Function to start the client and listen for commands
- local function startClient()
- -- Automatically detect a modem and open rednet
- local modemSide
- for _, side in ipairs({"left", "right", "top", "bottom", "front", "back"}) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- modemSide = side
- break
- end
- end
- if modemSide then
- rednet.open(modemSide)
- print("[INFO] Modem found and opened on side: " .. modemSide)
- -- Set the ID for this computer (this ID should match the ID used in the server script)
- local computerID = os.getComputerID()
- print("[INFO] Listening for commands on ID: " .. computerID)
- while true do
- local senderID, command = rednet.receive("control")
- if senderID then
- print("[INFO] Command received from ID: " .. senderID)
- handleCommand(command)
- end
- end
- -- Close the modem (though this is never reached in this loop)
- rednet.close(modemSide)
- else
- print("[ERROR] No modem found. Please connect a modem to run the client.")
- end
- end
- -- Coroutine to run the client in the background
- local function clientCoroutine()
- local co = coroutine.create(startClient)
- coroutine.resume(co)
- end
- -- Main function to execute file checks and start the client in the background
- local function main()
- -- Start the client coroutine
- clientCoroutine()
- -- Check for required files
- local missing = checkFiles()
- if #missing > 0 then
- -- Execute repair-loader if any files are missing
- shell.run("repair-loader")
- else
- -- All files exist, continue with starting the normal process
- shell.run("/disk/boot/start-check.lua")
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement