Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Pocket Recovery Server
- local diskPath = "/disk/"
- local recoveryPath = "/recovery/"
- local function handleRequest(path, response)
- local fullPath = shell.resolve(path)
- if fs.exists(fullPath) then
- local file = fs.open(fullPath, "r")
- response.write(file.readAll())
- file.close()
- else
- response.setStatus(404)
- response.write("File not found.")
- end
- end
- local function startServer()
- local modemSide = "back" -- Change this to the side where the modem is connected
- local modem = peripheral.wrap(modemSide)
- local serverID = os.getComputerID()
- print("Doggy OS Pocket Recovery Server")
- print("ID: " .. serverID)
- while true do
- local event, modemSide, senderChannel, replyChannel, message = os.pullEvent("modem_message")
- if senderChannel == tonumber(serverID) then
- if message == "GET /disk/" then
- handleRequest(diskPath, modem)
- elseif message == "GET /recovery/" then
- handleRequest(recoveryPath, modem)
- end
- end
- end
- end
- startServer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement