Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('Ensure Node is near a gps node')
- print('Ensure Node is equipped with an Ender Modem on the top')
- print('Press Enter once finished')
- read()
- posX = 0
- posY = 0
- posZ = 0
- chunkX = 0
- chunkZ = 0
- protectedChunks = {}
- nodes = {}
- print(posZ)
- print('Initializing Node...')
- posX, posY, posZ = gps.locate()
- print('Received position: X'..posX..' Y'..posY..' Z'..posZ)
- chunkX = math.floor(posX/16)
- chunkZ = math.floor(posZ/16)
- rednet.open('top')
- rednet.broadcast('V_RPC', 'V_RPC')
- sender,message,distance = rednet.receive("V_PC", 2)
- protectedChunks = textutils.unserialise(message)
- print('Received '..#protectedChunks..' protected chunks')
- function BroadcastProtectedChunks()
- print('broadcasting protected chunks')
- rednet.broadcast(textutils.serialise(protectedChunks), "V_PC")
- print('broadcasted protected chunks')
- end
- table.insert(protectedChunks, chunkX..','..chunkZ)
- print('Added own chunk to protected chunks')
- BroadcastProtectedChunks()
- function UpdatePChunkLoop()
- while true do
- sender,message,distance = rednet.receive("V_PC")
- protectedChunks = textutils.unserialise(message)
- end
- end
- function ServeProtectedChunks()
- while true do
- sender,message,distance = rednet.receive("V_RPC")
- rednet.send(sender, textutils.serialise(protectedChunks), "V_PC")
- print("Served PChunk request")
- end
- end
- function ServeNodes()
- while true do
- sender,message,distance = rednet.receive("V_RN")
- rednet.send(sender, textutils.serialise({posX,posZ}), "V_N")
- print("Served Node request")
- end
- end
- function PostMsgs()
- while true do
- sender,message,distance = rednet.receive("V_M")
- print('msg from '..sender..': '..message)
- end
- end
- function Main()
- while true do
- print('add protected chunk: a')
- print('remove protected chunk: r')
- print('locate all turtles: l')
- print('update network: u')
- command = read()
- if command == 'a' then
- print('chunk X')
- x = tonumber(read())
- print('chunk Z')
- z = tonumber(read())
- if protectedChunks[x..','..z] == nil then
- table.insert(protectedChunks, x..','..z)
- BroadcastProtectedChunks()
- else
- print('chunk already exists')
- end
- elseif command == 'r' then
- print('chunk X')
- x = tonumber(read())
- print('chunk Z')
- z = tonumber(read())
- if protectedChunks[x..','..z] ~= nil then
- table.remove(x..','..z)
- BroadcastProtectedChunks()
- else
- print('chunk does not exist')
- end
- elseif command == 'l' then
- print('locating tutels...')
- rednet.broadcast('pos', "V_CT")
- elseif command == 'u' then
- print('updating...')
- rednet.broadcast('upd', "V_CT")
- else
- print('unknown command')
- end
- end
- end
- parallel.waitForAll(UpdatePChunkLoop, ServeProtectedChunks, ServeNodes, Main)
Add Comment
Please, Sign In to add comment