Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- comp = {} --table of all known terminals. "name":id
- rednet.open("back")
- rednet.host("BASE", "master")
- --sends the packets to their correct locations
- function route(source, packet)
- if cotains(comp, packet.dest) then
- rednet.send(comp[packet.dest], packet)
- else
- rednet.send(source, "that is not a valid adress")
- end
- end
- --handles what to do with recieved packets
- function recieve()
- local id, message = rednet.receive()
- if message.message == "connect" then
- update(id, message.id)
- return
- end
- if not contains(comp, message.id) then
- udpade(id, message.id)
- route(id, message)
- else
- route(message)
- end
- end
- --updates the list of known systems with a new entry
- function update(id, name)
- if not contains(comp, name) then
- comp[name] = id
- end
- end
- --checks if a key is in the specified table
- function contains(table, object)
- for i in pairs(table) do
- if i == object then
- return true
- else
- return false
- end
- end
- end
- --main program loop
- while true do
- recieve()
- --debugging code
- print("recieved")
- for i, v in ipairs(comp) do
- print(i)
- print(v)
- end
- print("end")
- --end debugging code
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement