Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Set functions first, then do main instructions
- PROTOCOL = "danetos3"
- turtleNum = 0
- idList = {}
- jobList = {}
- homeList = {}
- function lookupHome(sender) --Looks up the home from the table
- for x=1,turtleNum-1 do
- if idList[x] == sender then
- return (homeList[x])
- end
- end
- print("ERROR! Could not find home for Computer " .. sender)
- end
- function lookupJob(sender)
- for x=1,turtleNum-1 do
- if idList[x] == sender then
- return (jobList[x])
- end
- end
- print("ERROR! Could not find job for Computer " .. sender)
- end
- function receiveRequests()
- sender,message = rednet.receive("danetos3")
- if message == "getHome" then --If a turtle asks for its home <3
- home = lookupHome(tostring(sender))
- rednet.send(sender,home,PROTOCOL)
- print("Send home information to Computer " .. sender)
- elseif message == "getJob" then --If a turtle asks for its job
- job = lookupJob(tostring(sender))
- rednet.send(sender,job,PROTOCOL)
- print("Sent job information to Computer " .. sender)
- end
- end
- function getData()
- local fileData = {} --Declare a table for the file data
- for line in io.lines("danetos3/data.danet") do-- Start a loop to read the data until no data is left
- table.insert(fileData,line)
- end
- print("SUCCESS! Data files read to table.")
- --Data parsing
- turtleNum = fileData[1]
- local readNum = turtleNum * 3
- for x=1,readNum,3 do
- idList[x] = fileData[x+1]
- jobList[x] = fileData[x+2]
- homeList[x] = fileData[x+3]
- end
- end
- --MAIN INSTRUCTIONS GO HERE
- shell.run("clear")
- print("DanetOS3 MainServer!")
- getData() --Get data from file system
- rednet.open("right")
- rednet.host(PROTOCOL,"MainServer")
- while(true) do --Wait for clients
- receiveRequests()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement