Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(input, maxSplits, sep)
- if sep == nil then
- sep = ";"
- end
- splits = {}
- splitCount = 0
- for str in string.gmatch(input, "([^"..sep.."]+)") do
- if maxSplits ~= nil and splitCount > maxSplits then
- splits[splitCount] = splits[splitCount]..sep..str
- else
- table.insert(splits, str)
- splitCount = splitCount + 1
- end
- end
- return splits
- end
- peripheral.find("modem", rednet.open)
- write("Finding database server ID...")
- rednet.broadcast("database", "dns-lookup")
- _, body = rednet.receive("dns-record-database")
- serverId = tonumber(body)
- print(" Done!")
- while true do
- rednet.send(serverId, "news", "database-dir-request")
- _, body = rednet.receive("database-dir-response")
- code, body = table.unpack(split(body, 2))
- filenames = split(body)
- term.clear()
- term.setCursorPos(1, 1)
- if code == "200" then
- for i, filename in pairs(filenames) do
- local path = "news/"..filename
- rednet.send(serverId, path, "database-file-request")
- _, file_response = rednet.receive("database-file-response", 5)
- file_code, file_body = table.unpack(split(file_response, 2))
- if file_code == "200" then
- print(file_body)
- else
- print("ERROR "..file_code..": "..file_body.." ("..path..")")
- end
- end
- else
- print("ERROR "..code..": "..body)
- end
- rednet.receive("news-update")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement