1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-23 10:38:05 +11:00

rewrote microtel-3 to be smaller and stuff

This commit is contained in:
Izaya 2018-03-18 12:13:47 +11:00
parent 44efbc259d
commit 4656df51b7
4 changed files with 227 additions and 171 deletions

View File

@ -1,101 +1,76 @@
_G.net={} _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 do
local rcpe,PC,RC,pQ,M=computer.pullSignal,{},{},{},{} local M,packetQueue,pC,rC,C={},{},{},{},computer
local cI,cU,cPS=component.invoke,computer.uptime,computer.pushSignal net.port,net.hostname,net.route=4096,C.address():sub(1,8),true
for a,t in component.list("modem") do for a in component.list("modem") do
M[#M+1]=component.proxy(a) M[a]=component.proxy(a)
M[#M].open(net.port) M[a].open(net.port)
end end
local function gP() local function gP()
local npID="" local pID=""
for i=1,16 do for i=1,16 do
npID=npID .. string.char(math.random(32,126)) pID=pID .. string.char(math.random(32,126))
end end
return npID return pID
end end
local function sP(pID,pT,D,S,vP,dA) local function sP(pID,pT,T,vP,D)
if RC[D] then pC[pID]=C.uptime()
cI(RC[D][1],"send",RC[D][2],net.port,pID,pT,D,S,vP,dA) if rC[T] then
M[rC[T][1]].send(rC[T][2],net.port,pID,pT,T,net.hostname,vP,D)
else else
for k,v in pairs(M) do for k,v in pairs(M) do
v.broadcast(net.port,pID,pT,D,S,vP,dA) v.broadcast(net.port,pID,pT,T,net.hostname,vP,D)
end end
end end
end end
local function pC() function net.send(T,vP,D,pT,pID)
for k,v in pairs(RC) do pT,pID=pT or 1,pID or gP()
if v[3]<cU() then packetQueue[pID]={pT,T,vP,D,0}
RC[k]=nil sP(pID,pT,T,vP,D)
end
end
for k,v in pairs(PC) do
if v<cU() then
PC[k]=nil
end
end
end
local function cPC(pID)
for k,v in pairs(PC) do
if k==pID then return true end
end end
local function cC(pID)
for k,v in pairs(pC) do
if k==pID then
return false return false
end end
local function pP() end
for k,v in pairs(pQ) do return true
if v[5]<cU() then end
sP(k,v[1],v[2],net.hostname,v[3],v[4]) local rCPE=C.pullSignal
if v[1]~=1 or v[6]==255 then function C.pullSignal(t)
pQ[k]=nil local eT={rCPE(t)}
else for k,v in pairs(pC) do
pQ[k][5]=cU()+net.retry if C.uptime()>v+30 then
pQ[k][6]=pQ[k][6]+1 pC[k]=nil
end end
end end
for k,v in pairs(rC) do
if C.uptime()>v[3]+30 then
rC[k]=nil
end end
end end
function computer.pullSignal(t) if eT[1]=="modem_message" and (eT[4]==net.port or eT[4]==0) and cC(eT[6]) then
pC() rC[eT[9]]={eT[2],eT[3],C.uptime()}
pP() if eT[8]==net.hostname then
local tev={rcpe(t)} if eT[7]~=2 then
if tev[1]=="modem_message" and tev[4]==net.port and not cPC(tev[6]) then C.pushSignal("net_msg",eT[9],eT[10],eT[11])
if tev[8]==net.hostname then if eT[7]==1 then
if tev[7]==1 then sP(gP(),2,eT[9],eT[10],eT[6])
sP(gP(),2,tev[9],net.hostname,tev[10],tev[6])
end
if tev[7]==2 then
pQ[tev[11]]=nil
cPS("net_ack",tev[11])
end
if tev[7]~=2 then
cPS("net_msg",tev[9],tev[10],tev[11])
end end
else else
sP(tev[6],tev[7],tev[8],tev[9],tev[10],tev[11]) packetQueue[eT[11]]=nil
end end
if not RC[tev[9]] then elseif net.route and cC(eT[6]) then
RC[tev[9]]={tev[2],tev[3],cU()+net.rctime} sP(eT[6],eT[7],eT[8],eT[9],eT[10],eT[11])
end end
if not PC[tev[6]] then pC[eT[6]]=C.uptime()
PC[tev[6]]=cU()+net.pctime end
for k,v in pairs(packetQueue) do
if C.uptime()>v[5] then
sP(k,table.unpack(v))
v[5]=C.uptime()+30
end end
end end
return table.unpack(tev) return table.unpack(eT)
end
function net.usend(to,vP,dA,npID)
npID=npID or gP()
pQ[npID]={0,to,vP,dA,0,0}
end
function net.rsend(to,vP,dA,npID)
npID=npID or gP()
pQ[npID]={1,to,vP,dA,0,0}
repeat
local te={computer.pullSignal()}
until te[1]=="net_ack" and te[2]==npID
end end
end end

View File

@ -1,111 +1,84 @@
_G.net={} _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 do
local modems,packetQueue,packetCache,routeCache,C = {},{},{},{},NOTCOMPUTER
net.port,net.hostname,net.route=4096,computer.address():sub(1,8),true
local rcpe, pcache, rcache, pqueue, modems = computer.pullSignal, {}, {}, {}, {} for a in component.list("modem") do
--subhere modems[a] = component.proxy(a)
modems[a].open(net.port)
for a,t in component.list("modem") do
modems[#modems+1] = component.proxy(a)
modems[#modems].open(net.port)
end end
local function genPacketID() local function genPacketID()
local npID = "" local packetID = ""
for i = 1, 16 do for i = 1, 16 do
npID = npID .. string.char(math.random(32,126)) packetID = packetID .. string.char(math.random(32,126))
end end
return npID return packetID
end end
local function sendPacket(packetID,packetType,dest,sender,vport,data) local function sendPacket(packetID,packetType,to,vport,data)
if rcache[dest] then packetCache[packetID] = computer.uptime()
component.invoke(rcache[dest][1],"send",rcache[dest][2],net.port,packetID,packetType,dest,sender,vport,data) if routeCache[to] then
modems[routeCache[to][1]].send(routeCache[to][2],net.port,packetID,packetType,to,net.hostname,vport,data)
else else
for k,v in pairs(modems) do for k,v in pairs(modems) do
v.broadcast(net.port,packetID,packetType,dest,sender,vport,data) v.broadcast(net.port,packetID,packetType,to,net.hostname,vport,data)
end end
end end
end end
local function pruneCache() function net.send(to,vport,data,packetType,packetID)
for k,v in pairs(rcache) do packetType,packetID = packetType or 1, packetID or genPacketID()
if v[3] < computer.uptime() then packetQueue[packetID] = {packetType,to,vport,data,0}
rcache[k] = nil sendPacket(packetID,packetType,to,vport,data)
end
end
for k,v in pairs(pcache) do
if v < computer.uptime() then
pcache[k] = nil
end
end
end end
local function checkPCache(packetID) local function checkCache(packetID)
for k,v in pairs(pcache) do for k,v in pairs(packetCache) do
if k == packetID then return true end if k == packetID then
end
return false return false
end end
local function packetPusher()
for k,v in pairs(pqueue) do
if v[5] < computer.uptime() then
sendPacket(k,v[1],v[2],net.hostname,v[3],v[4])
if v[1] ~= 1 or v[6] == 255 then
pqueue[k] = nil
else
pqueue[k][5]=computer.uptime()+net.retry
pqueue[k][6]=pqueue[k][6]+1
end
end
end end
return true
end end
local realComputerPullSignal = computer.pullSignal
function computer.pullSignal(t) function computer.pullSignal(t)
pruneCache() local eventTab = {realComputerPullSignal(t)}
packetPusher() for k,v in pairs(packetCache) do
local tev = {rcpe(t)} if computer.uptime() > v+30 then
if tev[1] == "modem_message" and tev[4] == net.port and not checkPCache(tev[6]) then packetCache[k] = nil
if tev[8] == net.hostname then
if tev[7] == 1 then
sendPacket(genPacketID(),2,tev[9],net.hostname,tev[10],tev[6])
end end
if tev[7] == 2 then
pqueue[tev[11]] = nil
computer.pushSignal("net_ack",tev[11])
end end
if tev[7] ~= 2 then for k,v in pairs(routeCache) do
computer.pushSignal("net_msg",tev[9],tev[10],tev[11]) if computer.uptime() > v[3]+30 then
routeCache[k] = nil
end
end
if eventTab[1] == "modem_message" and (eventTab[4] == net.port or eventTab[4] == 0) and checkCache(eventTab[6]) then
routeCache[eventTab[9]] = {eventTab[2],eventTab[3],computer.uptime()}
if eventTab[8] == net.hostname then
if eventTab[7] ~= 2 then
computer.pushSignal("net_msg",eventTab[9],eventTab[10],eventTab[11])
if eventTab[7] == 1 then
sendPacket(genPacketID(),2,eventTab[9],eventTab[10],eventTab[6])
end end
else else
sendPacket(tev[6],tev[7],tev[8],tev[9],tev[10],tev[11]) packetQueue[eventTab[11]] = nil
end end
if not rcache[tev[9]] then elseif net.route and checkCache(eventTab[6]) then
rcache[tev[9]] = {tev[2],tev[3],computer.uptime()+net.rctime} sendPacket(eventTab[6],eventTab[7],eventTab[8],eventTab[9],eventTab[10],eventTab[11])
end end
if not pcache[tev[6]] then packetCache[eventTab[6]] = computer.uptime()
pcache[tev[6]] = computer.uptime()+net.pctime end
for k,v in pairs(packetQueue) do
if computer.uptime() > v[5] then
sendPacket(k,table.unpack(v))
v[5]=computer.uptime()+30
end end
end end
return table.unpack(tev) return table.unpack(eventTab)
end
function net.usend(to,vport,data,npID)
npID = npID or genPacketID()
pqueue[npID] = {0,to,vport,data,0,0}
end
function net.rsend(to,vport,data,npID)
npID = npID or genPacketID()
pqueue[npID] = {1,to,vport,data,0,0}
repeat
local te={computer.pullSignal()}
until te[1] == "net_ack" and te[2] == npID
end end
end end

View File

@ -1,25 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#microtel-3.lua #microtel-3.lua
cp microtel-3.lua microtel-3-mini.lua cp microtel-3.lua microtel-3-mini.lua
sed -i -e 's/pcache/PC/g' microtel-3-mini.lua sed -i -e 's/eventTab/eT/g' microtel-3-mini.lua
sed -i -e 's/rcache/RC/g' microtel-3-mini.lua
sed -i -e 's/pqueue/pQ/g' microtel-3-mini.lua
sed -i -e 's/modems/M/g' microtel-3-mini.lua sed -i -e 's/modems/M/g' microtel-3-mini.lua
sed -i -e 's/qPacket/qP/g' microtel-3-mini.lua
sed -i -e 's/packetID/pID/g' microtel-3-mini.lua sed -i -e 's/packetID/pID/g' microtel-3-mini.lua
sed -i -e 's/packetType/pT/g' microtel-3-mini.lua sed -i -e 's/packetType/pT/g' microtel-3-mini.lua
sed -i -e 's/dest/D/g' microtel-3-mini.lua sed -i -e 's/to/T/g' microtel-3-mini.lua
sed -i -e 's/sender/S/g' microtel-3-mini.lua
sed -i -e 's/vport/vP/g' microtel-3-mini.lua sed -i -e 's/vport/vP/g' microtel-3-mini.lua
sed -i -e 's/data/dA/g' microtel-3-mini.lua sed -i -e 's/data/D/g' microtel-3-mini.lua
sed -i -e 's/genPacketID/gP/g' microtel-3-mini.lua
sed -i -e 's/sendPacket/sP/g' microtel-3-mini.lua sed -i -e 's/sendPacket/sP/g' microtel-3-mini.lua
sed -i -e 's/pruneCache/pC/g' microtel-3-mini.lua sed -i -e 's/genPacketID/gP/g' microtel-3-mini.lua
sed -i -e 's/checkPCache/cPC/g' microtel-3-mini.lua sed -i -e 's/packetCache/pC/g' microtel-3-mini.lua
sed -i -e 's/packetPusher/pP/g' microtel-3-mini.lua sed -i -e 's/checkCache/cC/g' microtel-3-mini.lua
sed -i -e 's/component.invoke/cI/g' microtel-3-mini.lua sed -i -e 's/routeCache/rC/g' microtel-3-mini.lua
sed -i -e 's/computer.uptime/cU/g' microtel-3-mini.lua sed -i -e 's/realComputerPullSignal/rCPE/g' microtel-3-mini.lua
sed -i -e 's/computer.pushSignal/cPS/g' microtel-3-mini.lua sed -i -e 's/computer/C/g' microtel-3-mini.lua
sed -i -e 's/--subhere/local cI,cU,cPS = component.invoke,computer.uptime,computer.pushSignal/g' microtel-3-mini.lua sed -i -e 's/NOTCOMPUTER/computer/g' microtel-3-mini.lua
lua strip.lua microtel-3-mini.lua microtel-3-mini.lua lua strip.lua microtel-3-mini.lua microtel-3-mini.lua
#microtel-4.lua #microtel-4.lua

111
Embedded/old-microtel-3.lua Normal file
View File

@ -0,0 +1,111 @@
_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, pcache, rcache, pqueue, modems = computer.pullSignal, {}, {}, {}, {}
--subhere
for a,t in component.list("modem") do
modems[#modems+1] = component.proxy(a)
modems[#modems].open(net.port)
end
local function genPacketID()
local npID = ""
for i = 1, 16 do
npID = npID .. string.char(math.random(32,126))
end
return npID
end
local function sendPacket(packetID,packetType,dest,sender,vport,data)
if rcache[dest] then
component.invoke(rcache[dest][1],"send",rcache[dest][2],net.port,packetID,packetType,dest,sender,vport,data)
else
for k,v in pairs(modems) do
v.broadcast(net.port,packetID,packetType,dest,sender,vport,data)
end
end
end
local function pruneCache()
for k,v in pairs(rcache) do
if v[3] < computer.uptime() then
rcache[k] = nil
end
end
for k,v in pairs(pcache) do
if v < computer.uptime() then
pcache[k] = nil
end
end
end
local function checkPCache(packetID)
for k,v in pairs(pcache) do
if k == packetID then return true end
end
return false
end
local function packetPusher()
for k,v in pairs(pqueue) do
if v[5] < computer.uptime() then
sendPacket(k,v[1],v[2],net.hostname,v[3],v[4])
if v[1] ~= 1 or v[6] == 255 then
pqueue[k] = nil
else
pqueue[k][5]=computer.uptime()+net.retry
pqueue[k][6]=pqueue[k][6]+1
end
end
end
end
function computer.pullSignal(t)
pruneCache()
packetPusher()
local tev = {rcpe(t)}
if tev[1] == "modem_message" and tev[4] == net.port and not checkPCache(tev[6]) then
if tev[8] == net.hostname then
if tev[7] == 1 then
sendPacket(genPacketID(),2,tev[9],net.hostname,tev[10],tev[6])
end
if tev[7] == 2 then
pqueue[tev[11]] = nil
computer.pushSignal("net_ack",tev[11])
end
if tev[7] ~= 2 then
computer.pushSignal("net_msg",tev[9],tev[10],tev[11])
end
else
sendPacket(tev[6],tev[7],tev[8],tev[9],tev[10],tev[11])
end
if not rcache[tev[9]] then
rcache[tev[9]] = {tev[2],tev[3],computer.uptime()+net.rctime}
end
if not pcache[tev[6]] then
pcache[tev[6]] = computer.uptime()+net.pctime
end
end
return table.unpack(tev)
end
function net.usend(to,vport,data,npID)
npID = npID or genPacketID()
pqueue[npID] = {0,to,vport,data,0,0}
end
function net.rsend(to,vport,data,npID)
npID = npID or genPacketID()
pqueue[npID] = {1,to,vport,data,0,0}
repeat
local te={computer.pullSignal()}
until te[1] == "net_ack" and te[2] == npID
end
end