mirror of
https://github.com/ShadowKatStudios/OC-Minitel.git
synced 2024-11-23 02:28:05 +11:00
made microtel-5-flisten actually work
This commit is contained in:
parent
99c7477733
commit
d5e2d82a50
@ -1,79 +0,0 @@
|
||||
_G.net={}
|
||||
do
|
||||
local M,pQ,pC,rC,C,Y={},{},{},{},computer,table.unpack
|
||||
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)
|
||||
end
|
||||
local function gP()
|
||||
local pID=""
|
||||
for i=1,16 do
|
||||
pID=pID .. string.char(math.random(32,126))
|
||||
end
|
||||
return pID
|
||||
end
|
||||
local function sP(pID,pT,T,vP,D)
|
||||
pC[pID]=U()
|
||||
if rC[T] then
|
||||
M[rC[T][1]].send(rC[T][2],net.port,pID,pT,T,net.hostname,vP,D)
|
||||
else
|
||||
for k,v in pairs(M) do
|
||||
v.broadcast(net.port,pID,pT,T,net.hostname,vP,D)
|
||||
end
|
||||
end
|
||||
end
|
||||
function net.send(T,vP,D,pT,pID)
|
||||
pT,pID=pT or 1,pID or gP()
|
||||
pQ[pID]={pT,T,vP,D,0}
|
||||
sP(pID,pT,T,vP,D)
|
||||
end
|
||||
local function cC(pID)
|
||||
for k,v in pairs(pC) do
|
||||
if k==pID then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
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
|
||||
end
|
||||
end
|
||||
for k,v in pairs(rC) do
|
||||
if U()>v[3]+30 then
|
||||
rC[k]=nil
|
||||
end
|
||||
end
|
||||
if Z[1]=="modem_message" and (Z[4]==net.port or Z[4]==0) and cC(Z[6]) then
|
||||
rC[Z[9]]={Z[2],Z[3],U()}
|
||||
if Z[8]==net.hostname then
|
||||
if Z[7]~=2 then
|
||||
C.pushSignal("net_msg",Z[9],Z[10],Z[11])
|
||||
if Z[7]==1 then
|
||||
sP(gP(),2,Z[9],Z[10],Z[6])
|
||||
end
|
||||
else
|
||||
pQ[Z[11]]=nil
|
||||
end
|
||||
elseif net.route and cC(Z[6]) then
|
||||
sP(Z[6],Z[7],Z[8],Z[9],Z[10],Z[11])
|
||||
end
|
||||
pC[Z[6]]=U()
|
||||
end
|
||||
for k,v in pairs(pQ) do
|
||||
if U()>v[5] then
|
||||
sP(k,Y(v))
|
||||
v[5]=U()+30
|
||||
end
|
||||
end
|
||||
return Y(Z)
|
||||
end
|
||||
end
|
@ -1,11 +0,0 @@
|
||||
net.mtu=4096
|
||||
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.send(T,P,v)
|
||||
end
|
||||
end
|
@ -1,14 +0,0 @@
|
||||
net.timeout=60
|
||||
function net.open(A,V)
|
||||
local st=computer.uptime()
|
||||
net.send(A,P,"openstream")
|
||||
repeat
|
||||
_,F,P,D=computer.pullSignal(0.5)
|
||||
if computer.uptime()>st+net.timeout then return false end
|
||||
until F==A and P==V and tonumber(D)
|
||||
V=tonumber(D)
|
||||
repeat
|
||||
_,F,P,D=computer.pullSignal(0.5)
|
||||
until F==A and P==V
|
||||
return socket(A,V,D)
|
||||
end
|
@ -1,10 +0,0 @@
|
||||
function net.flisten(V,handler)
|
||||
function net.hook[V](E,F,P,D)
|
||||
if P == V and D == "openstream" then
|
||||
local nP,S = math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(F,P,tostring(nP))
|
||||
net.send(F,nP,S)
|
||||
handler(net.socket(F,nP,S))
|
||||
end
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
function net.flisten(vport,handler)
|
||||
function net.hook[vport](etype,from,port,data)
|
||||
local function h(etype,from,port,data)
|
||||
if port == vport and data == "openstream" then
|
||||
local nport,sclose = math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(from,port,tostring(nport))
|
||||
@ -7,4 +7,5 @@ function net.flisten(vport,handler)
|
||||
handler(net.socket(from,nport,sclose))
|
||||
end
|
||||
end
|
||||
net.hook[vport] = h
|
||||
end
|
||||
|
@ -1,9 +0,0 @@
|
||||
function net.listen(V)
|
||||
repeat
|
||||
local E, F, P, D = computer.pullSignal(0.5)
|
||||
until P == V and D == "openstream"
|
||||
local nP,S = math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(F,P,tostring(nP))
|
||||
net.send(F,nP,S)
|
||||
return net.socket(F,nP,S)
|
||||
end
|
@ -1,14 +0,0 @@
|
||||
net.timeout = 60
|
||||
function net.open(A,V)
|
||||
local st=computer.uptime()
|
||||
net.send(A,P,"openstream")
|
||||
repeat
|
||||
_, F, P, D = computer.pullSignal(0.5)
|
||||
if computer.uptime() > st+net.timeout then return false end
|
||||
until F == A and P == V and tonumber(D)
|
||||
V=tonumber(D)
|
||||
repeat
|
||||
_, F, P, D = computer.pullSignal(0.5)
|
||||
until F == A and P == V
|
||||
return socket(A,V,D)
|
||||
end
|
Loading…
Reference in New Issue
Block a user