From 10ad65a7ec765ebae83e22c2c901ce9c2c58ebc9 Mon Sep 17 00:00:00 2001 From: Izaya Date: Sun, 18 Mar 2018 13:55:16 +1100 Subject: [PATCH] added hook support to microtel-3 for use with microtel-5 --- Embedded/microtel-3-mini.lua | 5 ++++- Embedded/microtel-3.lua | 5 ++++- Embedded/microtel-4-mini.lua | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Embedded/microtel-3-mini.lua b/Embedded/microtel-3-mini.lua index 2235f0f..d7f6b13 100644 --- a/Embedded/microtel-3-mini.lua +++ b/Embedded/microtel-3-mini.lua @@ -1,7 +1,7 @@ _G.net={} do local M,pQ,pC,rC,C,Y={},{},{},{},computer,table.unpack -net.port,net.hostname,net.route,U=4096,C.address():sub(1,8),true,C.uptime +net.port,net.hostname,net.route,net.hook,U=4096,C.address():sub(1,8),true,{},C.uptime for a in component.list("modem") do M[a]=component.proxy(a) M[a].open(net.port) @@ -39,6 +39,9 @@ end local rCPE=C.pullSignal function C.pullSignal(t) local Z={rCPE(t)} +for k,v in pairs(net.hook) do +pcall(v,Y(Z)) +end for k,v in pairs(pC) do if U()>v+30 then pC[k]=nil diff --git a/Embedded/microtel-3.lua b/Embedded/microtel-3.lua index 26927cb..865630c 100644 --- a/Embedded/microtel-3.lua +++ b/Embedded/microtel-3.lua @@ -2,7 +2,7 @@ _G.net={} do local modems,packetQueue,packetCache,routeCache,C,Y = {},{},{},{},COMPUTER,UNPACK -net.port,net.hostname,net.route,U=4096,computer.address():sub(1,8),true,UPTIME +net.port,net.hostname,net.route,net.hook,U=4096,computer.address():sub(1,8),true,{},UPTIME for a in component.list("modem") do modems[a] = component.proxy(a) @@ -46,6 +46,9 @@ end local realComputerPullSignal = computer.pullSignal function computer.pullSignal(t) local eventTab = {realComputerPullSignal(t)} + for k,v in pairs(net.hook) do + pcall(v,table.unpack(eventTab)) + end for k,v in pairs(packetCache) do if computer.uptime() > v+30 then packetCache[k] = nil diff --git a/Embedded/microtel-4-mini.lua b/Embedded/microtel-4-mini.lua index 1f89d51..b72289c 100644 --- a/Embedded/microtel-4-mini.lua +++ b/Embedded/microtel-4-mini.lua @@ -1,11 +1,11 @@ net.mtu=4096 -function net.send(T,P,L) +function net.lsend(T,P,L) local D={} for i=1,L:len(),net.mtu do D[#D+1]=L:sub(1,net.mtu) L=L:sub(net.mtu+1) end for k,v in ipairs(D) do -net.rsend(T,P,v) +net.send(T,P,v) end end