diff --git a/Embedded/microtel-3-mini.lua b/Embedded/microtel-3-mini.lua new file mode 100644 index 0000000..6fcca63 --- /dev/null +++ b/Embedded/microtel-3-mini.lua @@ -0,0 +1,101 @@ +_G.net={} +net.port=4096 +net.hostname=computer.address():sub(1,8) +net.debug=false +net.rctime=30 +net.pctime=30 +net.retry=30 +do +local rcpe,PC,RC,pQ,M=computer.pullSignal,{},{},{},{} +local cI,cU=component.invoke,computer.uptime +for a,t in component.list("modem") do +M[#M+1]=component.proxy(a) +M[#M].open(net.port) +end +local function gP() +local npID="" +for i=1,16 do +npID=npID .. string.char(math.random(32,126)) +end +return npID +end +local function sP(packetID,packetType,dest,sender,vport,data) +if RC[dest] then +cI(RC[dest][1],"send",RC[dest][2],net.port,packetID,packetType,dest,sender,vport,data) +else +for k,v in pairs(M) do +v.broadcast(net.port,packetID,packetType,dest,sender,vport,data) +end +end +end +local function pC() +for k,v in pairs(RC) do +if v[3]net.mtu then +for i=1,L:len(),net.mtu do +D[#D+1]=L:sub(1,net.mtu) +L=L:sub(net.mtu+1) +end +else +D={L} +end +for k,v in ipairs(D) do +net.rsend(T,P,v) +end +end diff --git a/Embedded/microtel-4.lua b/Embedded/microtel-4.lua new file mode 100644 index 0000000..3782d5d --- /dev/null +++ b/Embedded/microtel-4.lua @@ -0,0 +1,15 @@ +net.mtu = 4096 +function net.send(to,vport,ldata) + local tdata = {} + if ldata:len() > net.mtu then + for i = 1, ldata:len(), net.mtu do + tdata[#tdata+1] = ldata:sub(1,net.mtu) + ldata = ldata:sub(net.mtu+1) + end + else + tdata = {ldata} + end + for k,v in ipairs(tdata) do + net.rsend(to,vport,v) + end +end diff --git a/Embedded/microtel-5-mini.lua b/Embedded/microtel-5-mini.lua new file mode 100644 index 0000000..f67ab10 --- /dev/null +++ b/Embedded/microtel-5-mini.lua @@ -0,0 +1,81 @@ +do +local H={} +function computer.pullSignal(T) +tE={computer.pullSignal(T)} +for k,v in pairs(H) do +v(table.unpack(tE)) +end +return table.unpack(tE) +end +local function cW(S,D) +if S.state=="open" then +net.send(S.A,S.P,D) +end +end +local function cR(S,lN) +local rD="" +rD=S.rB:sub(1,lN) +S.rB=S.rB:sub(lN+1) +return rD +end +local function socket(A,P,sC) local C={} +C.A,C.P=A,tonumber(P) +C.rB="" +C.write=cW +C.read=cR +C.state="open" +local function lI(_,f,p,d) +if f==C.A and p==C.P then +if d==sC then +C:close() +else +C.rB=C.rB .. d +end +end +end +sL=tostring(lI) +H[sL]=lI +function C.close(S) +H[sL]=nil +C.state="closed" +net.rsend(A,P,sC) +end +return C +end +function net.open(to,P) +net.rsend(to,P,"openstream") +local st=computer.uptime()+net.streamdelay +local est=false +while true do +_,F,rP,D=event.pull("net_msg") +if to==F and rP==P then +if tonumber(D) then +est=true +end +break +end +if st