diff --git a/modules/net/copper.lua b/modules/net/copper.lua index 8d91483..e1bf669 100644 --- a/modules/net/copper.lua +++ b/modules/net/copper.lua @@ -2,6 +2,9 @@ net = {} net.id = computer.address():sub(1,8) net.np = 4957 net.tm = {} +if not component.list("ocemu")() then + _G.LKR_CACHE = true +end function net.send(id,po,msg) -- id, port, message if id and po and msg then event.push("sendmsg",id,po,msg) @@ -13,6 +16,12 @@ spawn("copperd",function() print(xpcall(function () local pt = {} local ps = {} local fcache = {} + local olog = log + local function log(...) + if COPPER_LOG then + olog(...) + end + end for a,t in component.list("modem") do table.insert(net.tm,component.proxy(a)) component.proxy(a).open(net.np) @@ -81,7 +90,6 @@ spawn("copperd",function() print(xpcall(function () if fcache[v.nid] and _G.LKR_CACHE then local lma = fcache[v.nid][1] local rma = fcache[v.nid][2] - print(lma,rma) component.invoke(lma,"send",rma,net.np,"copper",cdlib.encode(0,net.id,v.nid,relib.encode(v))) else for l,m in ipairs(net.tm) do @@ -102,6 +110,11 @@ spawn("copperd",function() print(xpcall(function () pt[k] = nil end end + for k,v in pairs(fcache) do + if v[3] < cot - 60 then + fcache[k] = nil + end + end end end)) end) end