Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- File Updater Program
- -- Varibles
- local filesrv = 57 -- Your update server ID.
- local cmptype = "client"
- -- setup rednet
- local sModemSide = nil
- for n,sSide in ipairs(rs.getSides()) do
- if peripheral.getType(sSide) == "modem" then
- sModemSide = sSide
- break
- end
- end
- if sModemSide == nil then
- print("No wireless modem attached")
- return
- end
- rednet.open(sModemSide)
- -- end setup rednet
- -- *************
- -- * Functions *
- -- *************
- -- Receive File.
- local function receiveFile()
- shell.run("id")
- print("Waiting for a bt connection...")
- rednet.send(filesrv,"update_client")
- while true do
- local id,msg
- local id,msg,p3 = rednet.receive()
- if msg == "bt.eol" then printError("Finished file update") shell.run("delete fileupdate") shell.run("rename fileupdater fileupdate") shell.run("startup") error() end
- if msg == "bt.con" then
- print("Connected to " .. id .. "!")
- local remoteID = id
- rednet.send(id, "bt.acc")
- local fileName
- print("Getting the file name...")
- local id,msg = "",""
- while true do
- id,msg = rednet.receive()
- if id == remoteID and string.sub(msg, 1, #"bt.fn:") == "bt.fn:" then
- fileName = string.sub(msg, #"bt.fn:" + 1)
- break
- end
- end
- if fs.exists(fileName) then
- print("File already exists, Deleting old file... " .. fileName)
- fs.delete(fileName)
- end
- print("Receiving file: " .. fileName)
- local file = fs.open(fileName, "w")
- local id,msg
- while true do
- id,msg = rednet.receive()
- if id == remoteID then
- if string.sub(msg, 1, #"bt.file:") == "bt.file:" then
- local subbedData = string.sub(msg, #"bt.file:" + 1)
- if term.isColor() then
- term.setTextColor(colors.lightBlue)
- end
- file.writeLine(subbedData)
- elseif msg == "bt.done" then
- file.flush()
- file.close()
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- print("Received file!")
- break
- end
- end
- end
- end
- end
- end
- -- Main Program
- print("updating files")
- receiveFile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement