Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local protocol = "bip"
- local pastebin = "uMfjE44t"
- -- Updating .bip.txt
- term.setTextColor(colors.green)
- print("Updating packages...\n")
- if fs.exists(".bip.txt") then
- print("Removing the old file...")
- fs.delete(".bip.txt")
- end
- shell.run("pastebin get "..pastebin.." .bip.txt")
- print("Finished updating!")
- sleep(1)
- term.clear()
- term.setCursorPos(1, 1)
- -- Creating the table
- local pkg, count = {}, 0
- local db = io.open(".bip.txt", "r")
- for line in db:lines() do
- local equals = line:find(" = ")
- pkg[line:sub(1, equals - 1)] = line:sub(equals + 3)
- count = count + 1
- end
- db:close()
- -- Managing requests
- term.setTextColor(colors.white)
- peripheral.find("modem", rednet.open)
- print("Awaiting requests...")
- local last_id, count = nil, 0
- while true do
- local id, msg, pro = rednet.receive(protocol, 5)
- -- Printing request information
- if id ~= last_id or msg == nil then
- if last_id ~= nil then
- print("Served", count, "requests from", last_id..".")
- end
- last_id = id
- count = 1
- else
- count = count + 1
- end
- -- Handling the request
- if msg ~= nil then
- if pkg[msg] ~= nil then
- rednet.send(id, pkg[msg], protocol)
- else
- rednet.send(id, "unknown package", protocol)
- end
- end
- end
- peripheral.find("modem", rednet.close)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement