Compare commits
31 Commits
5924cba842
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| beafcfd29f | |||
| 5f64113546 | |||
| 52afc41061 | |||
| 8eb9766874 | |||
| 9820bd4fa0 | |||
| 464b692f69 | |||
| 8d0bcf6599 | |||
| f330830e6c | |||
| 34d9397ab4 | |||
| 533b8f126d | |||
| 5ad67d6f3a | |||
| 358c7aeb54 | |||
| 21573b57b4 | |||
| 27ded0f69a | |||
| 5ef412e9f3 | |||
| c25899c22b | |||
| 6f24903281 | |||
| e8f6ee2a50 | |||
| 53bfcd57fb | |||
| f408acc81e | |||
| 1814070fb6 | |||
|
|
6ec10e2edf | ||
|
|
5f09b5b81d | ||
|
|
c318867d6d | ||
|
|
8c41220f9a | ||
|
|
374d239407 | ||
|
|
b1c4a68490 | ||
|
|
9cd255c938 | ||
|
|
feb764c379 | ||
|
|
fe7accadb7 | ||
|
|
82615a9d82 |
1061
containers.lua
Normal file
1061
containers.lua
Normal file
File diff suppressed because one or more lines are too long
1
containers_minified.lua
Normal file
1
containers_minified.lua
Normal file
File diff suppressed because one or more lines are too long
680
disklock.lua
Normal file
680
disklock.lua
Normal file
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
|||||||
local pullEvent = os.pullEventRaw
|
local pullEvent = os.pullEventRaw
|
||||||
local modem = peripheral.find("modem")
|
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
_G.network = {}
|
_G.network = {}
|
||||||
@@ -9,14 +9,15 @@ if not modem then
|
|||||||
end
|
end
|
||||||
local message_queue = {}
|
local message_queue = {}
|
||||||
modem.open(15125)
|
modem.open(15125)
|
||||||
local canidate = {id = -1, distance = 170}
|
local canidate = {id = -1, distance = 764, max_distance=0}
|
||||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||||
function ()
|
function ()
|
||||||
while true do
|
while true do
|
||||||
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
||||||
if channel == 15125 then
|
if channel == 15125 then
|
||||||
if msg.protocol == "entrypoint_advertise" then
|
if msg.protocol == "entrypoint_advertise" then
|
||||||
if distance < canidate.distance then
|
if distance < canidate.distance and distance < (msg.max_distance or 128) then
|
||||||
|
canidate.max_distance = (msg.max_distance or 128)
|
||||||
canidate.id = msg.sender
|
canidate.id = msg.sender
|
||||||
canidate.distance = distance
|
canidate.distance = distance
|
||||||
end
|
end
|
||||||
@@ -34,9 +35,11 @@ local function receive()
|
|||||||
if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then
|
if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then
|
||||||
last_heartbeat = os.epoch("utc")
|
last_heartbeat = os.epoch("utc")
|
||||||
modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id})
|
modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id})
|
||||||
if distance > 170 then
|
canidate.distance = distance
|
||||||
|
canidate.max_distance = msg.max_distance
|
||||||
|
if distance > (msg.max_distance or 764) then
|
||||||
modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id})
|
modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id})
|
||||||
canidate = {id = -1, distance = 170}
|
canidate = {id = -1, distance = 764, max_distance=0}
|
||||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||||
function ()
|
function ()
|
||||||
while true do
|
while true do
|
||||||
@@ -44,6 +47,7 @@ local function receive()
|
|||||||
if channel == 15125 then
|
if channel == 15125 then
|
||||||
if msg.protocol == "entrypoint_advertise" then
|
if msg.protocol == "entrypoint_advertise" then
|
||||||
if distance < canidate.distance then
|
if distance < canidate.distance then
|
||||||
|
canidate.max_distance = msg.max_distance
|
||||||
canidate.id = msg.sender
|
canidate.id = msg.sender
|
||||||
canidate.distance = distance
|
canidate.distance = distance
|
||||||
end
|
end
|
||||||
@@ -75,15 +79,18 @@ end
|
|||||||
|
|
||||||
local function connect()
|
local function connect()
|
||||||
while true do
|
while true do
|
||||||
if os.epoch("utc") - last_heartbeat > 200 then
|
if os.epoch("utc") - last_heartbeat > math.max((300*canidate.distance)/100,300) then
|
||||||
canidate = {id = -1, distance = 170}
|
canidate = {id = -1, distance = 764, max_distance=0}
|
||||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||||
function ()
|
function ()
|
||||||
while true do
|
while true do
|
||||||
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
||||||
if channel == 15125 then
|
if channel == 15125 then
|
||||||
if msg.protocol == "entrypoint_advertise" then
|
if msg.protocol == "entrypoint_advertise" then
|
||||||
if distance < canidate.distance then
|
if distance > (msg.max_distance or 128) then
|
||||||
|
modem.transmit(15125,15125,{protocol="out_of_range",sender=os.getComputerID(),target=msg.sender})
|
||||||
|
elseif distance < canidate.distance then
|
||||||
|
canidate.max_distance = msg.max_distance
|
||||||
canidate.id = msg.sender
|
canidate.id = msg.sender
|
||||||
canidate.distance = distance
|
canidate.distance = distance
|
||||||
end
|
end
|
||||||
@@ -94,8 +101,12 @@ local function connect()
|
|||||||
if canidate.id == -1 then
|
if canidate.id == -1 then
|
||||||
sleep(5)
|
sleep(5)
|
||||||
else
|
else
|
||||||
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
|
if canidate.distance > (canidate.max_distance or 128) then
|
||||||
last_heartbeat = os.epoch("utc")
|
modem.transmit(15125,15125,{protocol="out_of_range",sender=os.getComputerID(),target=canidate.id})
|
||||||
|
else
|
||||||
|
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
|
||||||
|
last_heartbeat = os.epoch("utc")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local msg = table.remove(message_queue,1)
|
local msg = table.remove(message_queue,1)
|
||||||
@@ -106,5 +117,8 @@ local function connect()
|
|||||||
sleep()
|
sleep()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function _G.network.getCandidate()
|
||||||
|
return canidate
|
||||||
|
end
|
||||||
parallel.waitForAny(receive, connect,function () shell.run("shell") end)
|
parallel.waitForAny(receive, connect,function () shell.run("shell") end)
|
||||||
os.shutdown()
|
os.shutdown()
|
||||||
|
|||||||
1
libDeflate.lua
Normal file
1
libDeflate.lua
Normal file
File diff suppressed because one or more lines are too long
2045
lua-minify.lua
Normal file
2045
lua-minify.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
local interactions = {}
|
local interactions = {}
|
||||||
local radio = peripheral.find("radio_tower")
|
local radio = peripheral.find("radio_tower")
|
||||||
local modem = peripheral.find("modem")
|
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
|
||||||
local distancemap = {}
|
local distancemap = {}
|
||||||
local message_queue = {}
|
local message_queue = {}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ if radio and modem then
|
|||||||
local data = {os.pullEvent()}
|
local data = {os.pullEvent()}
|
||||||
if data[1] == "radio_message" then
|
if data[1] == "radio_message" then
|
||||||
data[3] = textutils.unserialise(data[3])
|
data[3] = textutils.unserialise(data[3])
|
||||||
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end
|
if data[3]._target == os.getComputerID() or data[3]._target == nil and data[4] < 2611 then return data[2], data[3], data[4] end
|
||||||
elseif data[1] == "modem_message" then
|
elseif data[1] == "modem_message" then
|
||||||
if data[5]._target == os.getComputerID() or data[5]._target == nil then return data[2], data[5], data[6] end
|
if data[5]._target == os.getComputerID() or data[5]._target == nil then return data[2], data[5], data[6] end
|
||||||
end
|
end
|
||||||
@@ -61,7 +61,7 @@ elseif radio then
|
|||||||
while true do
|
while true do
|
||||||
local data = {os.pullEvent("radio_message")}
|
local data = {os.pullEvent("radio_message")}
|
||||||
data[3] = textutils.unserialise(data[3])
|
data[3] = textutils.unserialise(data[3])
|
||||||
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end
|
if data[3]._target == os.getComputerID() or data[3]._target == nil and data[4] < 2611 then return data[2], data[3], data[4] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function interactions.send(message,target)
|
function interactions.send(message,target)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
local interactions = {}
|
local interactions = {}
|
||||||
local radio = peripheral.find("radio_tower")
|
local radio = peripheral.find("radio_tower")
|
||||||
local modem = peripheral.find("modem")
|
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
|
||||||
|
|
||||||
|
local max_distance = 128
|
||||||
local distancemap = {}
|
local distancemap = {}
|
||||||
local clients = {}
|
local clients = {}
|
||||||
local message_queue = {}
|
local message_queue = {}
|
||||||
@@ -48,6 +50,8 @@ local function entrypoint_recieving(channel, msg)
|
|||||||
print("No route to",msg.destination)
|
print("No route to",msg.destination)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif msg.protocol == "out_of_range" then
|
||||||
|
print("readjusting range")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -84,6 +88,8 @@ if radio and modem then
|
|||||||
data[3] = textutils.unserialise(data[3])
|
data[3] = textutils.unserialise(data[3])
|
||||||
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end
|
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end
|
||||||
elseif data[1] == "modem_message" then
|
elseif data[1] == "modem_message" then
|
||||||
|
print(data[6])
|
||||||
|
max_distance = math.max(data[6] or 0,max_distance)
|
||||||
if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end
|
if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end
|
||||||
if data[3] == 15125 then
|
if data[3] == 15125 then
|
||||||
entrypoint_recieving(data[3], data[5])
|
entrypoint_recieving(data[3], data[5])
|
||||||
@@ -107,6 +113,7 @@ elseif modem then
|
|||||||
local data = {[5]={_target=-1}}
|
local data = {[5]={_target=-1}}
|
||||||
while true do
|
while true do
|
||||||
data = {os.pullEvent("modem_message")}
|
data = {os.pullEvent("modem_message")}
|
||||||
|
max_distance = math.max(data[6] or 0,max_distance)
|
||||||
if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end
|
if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end
|
||||||
if data[3] == 15125 then
|
if data[3] == 15125 then
|
||||||
entrypoint_recieving(data[3], data[5])
|
entrypoint_recieving(data[3], data[5])
|
||||||
@@ -126,7 +133,14 @@ queue_message({protocol="getroutes"})
|
|||||||
interactions.send({protocol="route_erase",destination=os.getComputerID()})
|
interactions.send({protocol="route_erase",destination=os.getComputerID()})
|
||||||
queue_message({protocol="route",destination=os.getComputerID(),distance=0})
|
queue_message({protocol="route",destination=os.getComputerID(),distance=0})
|
||||||
local heartbeat = false
|
local heartbeat = false
|
||||||
|
local function generate_default_routes()
|
||||||
|
local map = {}
|
||||||
|
map[os.computerID()] = {dist = 0, sender = os.computerID()}
|
||||||
|
for client,_ in pairs(clients) do
|
||||||
|
map[client] = {dist = 1, sender = client}
|
||||||
|
end
|
||||||
|
return map
|
||||||
|
end
|
||||||
local function recieve()
|
local function recieve()
|
||||||
while true do
|
while true do
|
||||||
local _, msg = interactions.receive()
|
local _, msg = interactions.receive()
|
||||||
@@ -188,8 +202,7 @@ while true do
|
|||||||
if (not msg.visited) then msg.visited = {} end
|
if (not msg.visited) then msg.visited = {} end
|
||||||
msg.visited[#msg.visited+1] = os.getComputerID()
|
msg.visited[#msg.visited+1] = os.getComputerID()
|
||||||
print("rerouting")
|
print("rerouting")
|
||||||
distancemap = {}
|
distancemap = generate_default_routes()
|
||||||
distancemap[os.computerID()] = {dist = 0, sender = os.computerID()}
|
|
||||||
queue_message({protocol="getroutes"})
|
queue_message({protocol="getroutes"})
|
||||||
queue_message(msg)
|
queue_message(msg)
|
||||||
end
|
end
|
||||||
@@ -219,6 +232,7 @@ local function heartbeat_f()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if not heartbeat then
|
if not heartbeat then
|
||||||
|
print(k, "timed out")
|
||||||
distancemap[k] = nil
|
distancemap[k] = nil
|
||||||
queue_message({protocol="reroute"})
|
queue_message({protocol="reroute"})
|
||||||
end
|
end
|
||||||
@@ -229,7 +243,7 @@ local function heartbeat_f()
|
|||||||
end
|
end
|
||||||
local function entrypoint_advertising()
|
local function entrypoint_advertising()
|
||||||
while true do
|
while true do
|
||||||
modem.transmit(15125,15125,{protocol="entrypoint_advertise",sender=os.getComputerID()})
|
modem.transmit(15125,15125,{protocol="entrypoint_advertise",sender=os.getComputerID(),max_distance=max_distance-10})
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -242,7 +256,7 @@ local function healthcheck()
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
end, function()
|
end, function()
|
||||||
while not heartbeat_entrypoint do
|
while not heartbeat_entrypoint do
|
||||||
modem.transmit(15125,15125,{protocol="heartbeat",sender=os.getComputerID(),target=client})
|
modem.transmit(15125,15125,{protocol="heartbeat",sender=os.getComputerID(),target=client,max_distance=max_distance-10})
|
||||||
sleep()
|
sleep()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
1
minified_disklock.lua
Normal file
1
minified_disklock.lua
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user