Compare commits
21 Commits
6ec10e2edf
...
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 |
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
18
disklock.lua
18
disklock.lua
@@ -28,13 +28,14 @@ local function deepcopy(o, seen)
|
||||
end
|
||||
|
||||
local realfs = deepcopy(fs)
|
||||
local function getRom(path)
|
||||
if not path then path = "/rom" end
|
||||
local rom_cache = nil
|
||||
|
||||
local function buildRom(path)
|
||||
local out = {}
|
||||
for _,file in ipairs(realfs.list(path)) do
|
||||
local fullPath = realfs.combine(path, file) -- use realfs here to avoid recursing into _G.fs
|
||||
for _, file in ipairs(realfs.list(path)) do
|
||||
local fullPath = realfs.combine(path, file)
|
||||
if realfs.isDir(fullPath) then
|
||||
out[file] = getRom(fullPath)
|
||||
out[file] = buildRom(fullPath)
|
||||
else
|
||||
local handle = realfs.open(fullPath, "r")
|
||||
out[file] = handle.readAll()
|
||||
@@ -44,6 +45,13 @@ local function getRom(path)
|
||||
return out
|
||||
end
|
||||
|
||||
local function getRom()
|
||||
if not rom_cache then
|
||||
rom_cache = buildRom("/rom")
|
||||
end
|
||||
return rom_cache
|
||||
end
|
||||
|
||||
local function getFileSystem()
|
||||
if filesystem then filesystem.rom = getRom() return filesystem end
|
||||
if not realfs.exists("fs") then
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local max_distance = 220
|
||||
|
||||
local pullEvent = os.pullEventRaw
|
||||
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
|
||||
term.clear()
|
||||
@@ -11,14 +9,15 @@ if not modem then
|
||||
end
|
||||
local message_queue = {}
|
||||
modem.open(15125)
|
||||
local canidate = {id = -1, distance = max_distance}
|
||||
local canidate = {id = -1, distance = 764, max_distance=0}
|
||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||
function ()
|
||||
while true do
|
||||
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
||||
if channel == 15125 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.distance = distance
|
||||
end
|
||||
@@ -36,9 +35,11 @@ local function receive()
|
||||
if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then
|
||||
last_heartbeat = os.epoch("utc")
|
||||
modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id})
|
||||
if distance > max_distance 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})
|
||||
canidate = {id = -1, distance = max_distance}
|
||||
canidate = {id = -1, distance = 764, max_distance=0}
|
||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||
function ()
|
||||
while true do
|
||||
@@ -46,6 +47,7 @@ local function receive()
|
||||
if channel == 15125 then
|
||||
if msg.protocol == "entrypoint_advertise" then
|
||||
if distance < canidate.distance then
|
||||
canidate.max_distance = msg.max_distance
|
||||
canidate.id = msg.sender
|
||||
canidate.distance = distance
|
||||
end
|
||||
@@ -77,15 +79,18 @@ end
|
||||
|
||||
local function connect()
|
||||
while true do
|
||||
if os.epoch("utc") - last_heartbeat > 200 then
|
||||
canidate = {id = -1, distance = max_distance}
|
||||
if os.epoch("utc") - last_heartbeat > math.max((300*canidate.distance)/100,300) then
|
||||
canidate = {id = -1, distance = 764, max_distance=0}
|
||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||
function ()
|
||||
while true do
|
||||
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
||||
if channel == 15125 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.distance = distance
|
||||
end
|
||||
@@ -96,8 +101,12 @@ local function connect()
|
||||
if canidate.id == -1 then
|
||||
sleep(5)
|
||||
else
|
||||
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
|
||||
last_heartbeat = os.epoch("utc")
|
||||
if canidate.distance > (canidate.max_distance or 128) then
|
||||
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
|
||||
else
|
||||
local msg = table.remove(message_queue,1)
|
||||
@@ -108,5 +117,8 @@ local function connect()
|
||||
sleep()
|
||||
end
|
||||
end
|
||||
function _G.network.getCandidate()
|
||||
return canidate
|
||||
end
|
||||
parallel.waitForAny(receive, connect,function () shell.run("shell") end)
|
||||
os.shutdown()
|
||||
|
||||
2045
lua-minify.lua
Normal file
2045
lua-minify.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,7 @@ if radio and modem then
|
||||
local data = {os.pullEvent()}
|
||||
if data[1] == "radio_message" then
|
||||
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
|
||||
if data[5]._target == os.getComputerID() or data[5]._target == nil then return data[2], data[5], data[6] end
|
||||
end
|
||||
@@ -61,7 +61,7 @@ elseif radio then
|
||||
while true do
|
||||
local data = {os.pullEvent("radio_message")}
|
||||
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
|
||||
function interactions.send(message,target)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
local interactions = {}
|
||||
local radio = peripheral.find("radio_tower")
|
||||
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
|
||||
|
||||
local max_distance = 128
|
||||
local distancemap = {}
|
||||
local clients = {}
|
||||
local message_queue = {}
|
||||
@@ -48,6 +50,8 @@ local function entrypoint_recieving(channel, msg)
|
||||
print("No route to",msg.destination)
|
||||
end
|
||||
end
|
||||
elseif msg.protocol == "out_of_range" then
|
||||
print("readjusting range")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -84,6 +88,8 @@ if radio and modem then
|
||||
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
|
||||
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[3] == 15125 then
|
||||
entrypoint_recieving(data[3], data[5])
|
||||
@@ -107,6 +113,7 @@ elseif modem then
|
||||
local data = {[5]={_target=-1}}
|
||||
while true do
|
||||
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[3] == 15125 then
|
||||
entrypoint_recieving(data[3], data[5])
|
||||
@@ -236,7 +243,7 @@ local function heartbeat_f()
|
||||
end
|
||||
local function entrypoint_advertising()
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -249,7 +256,7 @@ local function healthcheck()
|
||||
sleep(0.1)
|
||||
end, function()
|
||||
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()
|
||||
end
|
||||
end)
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user