Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to handle incoming commands
- 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
- 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
- -- Run the client program
- startClient()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement