Posted 12 July 2012 - 11:50 PM
I'm planning on making cable internet on a server I'm playing on, with a tree system. Basically it would consist of computer "hubs" arranged in a tree, so that if a hub gets a message meant for a computer not on its system, it sends the message to its parent hub. When the hub is started, it checks for a connect hub to be a parent. To differentiate between parents and children, computers would be connected to their parents through the top surface, and any other surfaces could be use for children. If there is one found, it will store the id as the parent, and if none are found, it will have a nil parent and be at the highest level of its network. Currently, there is a way to implement it:
The computer is connected by its top to a parent, and by the bottom to a child.
print("requesting parent")
rednet.open("top")
rednet.broadcast("request_parent")
id, message = rednet.receive(2)
if message == "parent" then
print ("parent " .. id .." found")
parent = id
else
print ("parent not found, becoming top-level hub")
parent = nil
end
After that, it would ennumerate peripherals and activate all rednet interfaces for communication, including listing more hubs as children.
The parent computer would be on an endless loop processing requests, and if it receives a "request_parent" message it will store the sender to a table of child hubs.
The problem with this, however, is that children connecting cables to the same slot on the parent hub would communicate with each other, erronerously assigning each other as the parent, since they are connected to each other by the top. This means that a hub could at most have one parent and five children. This wouldn't really be too bad (computers aren't too expensive after all), but it would make it much less of a hassle to just be able to connect more. If sides were passed, then it would be possible to make hubs ignore parent requests from their top port, enabling them to be connected at the top before reaching the parent hub.
The computer is connected by its top to a parent, and by the bottom to a child.
print("requesting parent")
rednet.open("top")
rednet.broadcast("request_parent")
id, message = rednet.receive(2)
if message == "parent" then
print ("parent " .. id .." found")
parent = id
else
print ("parent not found, becoming top-level hub")
parent = nil
end
After that, it would ennumerate peripherals and activate all rednet interfaces for communication, including listing more hubs as children.
The parent computer would be on an endless loop processing requests, and if it receives a "request_parent" message it will store the sender to a table of child hubs.
The problem with this, however, is that children connecting cables to the same slot on the parent hub would communicate with each other, erronerously assigning each other as the parent, since they are connected to each other by the top. This means that a hub could at most have one parent and five children. This wouldn't really be too bad (computers aren't too expensive after all), but it would make it much less of a hassle to just be able to connect more. If sides were passed, then it would be possible to make hubs ignore parent requests from their top port, enabling them to be connected at the top before reaching the parent hub.