mirror of
https://github.com/ShadowKatStudios/OC-Minitel.git
synced 2024-11-23 10:38:05 +11:00
rewrote minitel-5 and split each part into separate files
This commit is contained in:
parent
10ad65a7ec
commit
b82698aedc
14
Embedded/microtel-5-core-mini.lua
Normal file
14
Embedded/microtel-5-core-mini.lua
Normal file
@ -0,0 +1,14 @@
|
||||
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
|
26
Embedded/microtel-5-core.lua
Normal file
26
Embedded/microtel-5-core.lua
Normal file
@ -0,0 +1,26 @@
|
||||
function net.socket(address, port, sclose)
|
||||
local conn = {}
|
||||
local conn.state, conn.buffer, conn.port, rb, conn.address = "o", "", tonumber(port), "", address
|
||||
function conn.r(self,length)
|
||||
rb=self.buffer:sub(1,l)
|
||||
self.buffer=self.buffer:sub(l+1)
|
||||
return rb
|
||||
end
|
||||
function conn.w(self,data)
|
||||
net.lsend(self.address,self.port,data)
|
||||
end
|
||||
function conn.c(s)
|
||||
net.send(conn.address,conn.port,sclose)
|
||||
end
|
||||
function net.hook[sclose](etype, from, port, data)
|
||||
if from == conn.address and port == conn.port then
|
||||
if data == sclose then
|
||||
net.hook[sclose] = nil
|
||||
conn.state = "c"
|
||||
return
|
||||
end
|
||||
conn.buffer = conn.buffer..data
|
||||
end
|
||||
end
|
||||
return conn
|
||||
end
|
10
Embedded/microtel-5-flisten-mini.lua
Normal file
10
Embedded/microtel-5-flisten-mini.lua
Normal file
@ -0,0 +1,10 @@
|
||||
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
|
10
Embedded/microtel-5-flisten.lua
Normal file
10
Embedded/microtel-5-flisten.lua
Normal file
@ -0,0 +1,10 @@
|
||||
function net.flisten(vport,handler)
|
||||
function net.hook[vport](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))
|
||||
net.send(from,nport,sclose)
|
||||
handler(net.socket(from,nport,sclose))
|
||||
end
|
||||
end
|
||||
end
|
9
Embedded/microtel-5-listen-mini.lua
Normal file
9
Embedded/microtel-5-listen-mini.lua
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
9
Embedded/microtel-5-listen.lua
Normal file
9
Embedded/microtel-5-listen.lua
Normal file
@ -0,0 +1,9 @@
|
||||
function net.listen(vport)
|
||||
repeat
|
||||
local etype, from, port, data = computer.pullSignal(0.5)
|
||||
until port == vport and data == "openstream"
|
||||
local nport,sclose = math.random(2^15,2^16),tostring(math.random(-2^16,2^16))
|
||||
net.send(from,port,tostring(nport))
|
||||
net.send(from,nport,sclose)
|
||||
return net.socket(from,nport,sclose)
|
||||
end
|
@ -1,81 +0,0 @@
|
||||
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<computer.uptime() then
|
||||
return nil,"timed out"
|
||||
end
|
||||
end
|
||||
if not est then
|
||||
return nil,"refused"
|
||||
end
|
||||
D=tonumber(D)
|
||||
sC=""
|
||||
repeat
|
||||
_,F,nP,sC=event.pull("net_msg")
|
||||
until F==to and nP==D
|
||||
return socket(to,D,sC)
|
||||
end
|
||||
function net.listen(P)
|
||||
repeat
|
||||
_,F,rP,D=computer.pullSignal()
|
||||
until rP==P and D=="openstream"
|
||||
local nP=math.random(net.minP,net.maxP)
|
||||
local sC=net.genPacketID()
|
||||
net.rsend(F,rP,tostring(nP))
|
||||
net.rsend(F,nP,sC)
|
||||
return socket(F,nP,sC)
|
||||
end
|
||||
end
|
14
Embedded/microtel-5-open-mini.lua
Normal file
14
Embedded/microtel-5-open-mini.lua
Normal file
@ -0,0 +1,14 @@
|
||||
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
|
14
Embedded/microtel-5-open.lua
Normal file
14
Embedded/microtel-5-open.lua
Normal file
@ -0,0 +1,14 @@
|
||||
net.timeout = 60
|
||||
function net.open(address,vport)
|
||||
local st=computer.uptime()
|
||||
net.send(address,port,"openstream")
|
||||
repeat
|
||||
_, from, port, data = computer.pullSignal(0.5)
|
||||
if computer.uptime() > st+net.timeout then return false end
|
||||
until from == address and port == vport and tonumber(data)
|
||||
vport=tonumber(data)
|
||||
repeat
|
||||
_, from, port, data = computer.pullSignal(0.5)
|
||||
until from == address and port == vport
|
||||
return socket(address,vport,data)
|
||||
end
|
@ -1,86 +0,0 @@
|
||||
do
|
||||
local hooks = {}
|
||||
function computer.pullSignal(T)
|
||||
tE = {computer.pullSignal(T)}
|
||||
for k,v in pairs(hooks) do
|
||||
v(table.unpack(tE))
|
||||
end
|
||||
return table.unpack(tE)
|
||||
end
|
||||
|
||||
local function cwrite(self,data)
|
||||
if self.state == "open" then
|
||||
net.send(self.addr,self.port,data)
|
||||
end
|
||||
end
|
||||
local function cread(self,length)
|
||||
local rdata = ""
|
||||
rdata = self.rbuffer:sub(1,length)
|
||||
self.rbuffer = self.rbuffer:sub(length+1)
|
||||
return rdata
|
||||
end
|
||||
|
||||
local function socket(addr,port,sclose) -- todo, add remote closing of sockets
|
||||
local conn = {}
|
||||
conn.addr,conn.port = addr,tonumber(port)
|
||||
conn.rbuffer = ""
|
||||
conn.write = cwrite
|
||||
conn.read = cread
|
||||
conn.state = "open"
|
||||
local function listener(_,f,p,d)
|
||||
if f == conn.addr and p == conn.port then
|
||||
if d == sclose then
|
||||
conn:close()
|
||||
else
|
||||
conn.rbuffer = conn.rbuffer .. d
|
||||
end
|
||||
end
|
||||
end
|
||||
slisten = tostring(listener)
|
||||
hooks[slisten]=listener
|
||||
function conn.close(self)
|
||||
hooks[slisten]=nil
|
||||
conn.state = "closed"
|
||||
net.rsend(addr,port,sclose)
|
||||
end
|
||||
return conn
|
||||
end
|
||||
|
||||
function net.open(to,port)
|
||||
net.rsend(to,port,"openstream")
|
||||
local st = computer.uptime()+net.streamdelay
|
||||
local est = false
|
||||
while true do
|
||||
_,from,rport,data = event.pull("net_msg")
|
||||
if to == from and rport == port then
|
||||
if tonumber(data) then
|
||||
est = true
|
||||
end
|
||||
break
|
||||
end
|
||||
if st < computer.uptime() then
|
||||
return nil, "timed out"
|
||||
end
|
||||
end
|
||||
if not est then
|
||||
return nil, "refused"
|
||||
end
|
||||
data = tonumber(data)
|
||||
sclose = ""
|
||||
repeat
|
||||
_,from,nport,sclose = event.pull("net_msg")
|
||||
until from == to and nport == data
|
||||
return socket(to,data,sclose)
|
||||
end
|
||||
|
||||
function net.listen(port)
|
||||
repeat
|
||||
_, from, rport, data = computer.pullSignal()
|
||||
until rport == port and data == "openstream"
|
||||
local nport = math.random(net.minport,net.maxport)
|
||||
local sclose = net.genPacketID()
|
||||
net.rsend(from,rport,tostring(nport))
|
||||
net.rsend(from,nport,sclose)
|
||||
return socket(from,nport,sclose)
|
||||
end
|
||||
end
|
@ -32,23 +32,58 @@ sed -i -e 's/ldata/L/g' microtel-4-mini.lua
|
||||
sed -i -e 's/tdata/D/g' microtel-4-mini.lua
|
||||
lua strip.lua microtel-4-mini.lua microtel-4-mini.lua
|
||||
|
||||
#microtel-5.lua
|
||||
cp microtel-5.lua microtel-5-mini.lua
|
||||
sed -i -e 's/hooks/H/g' microtel-5-mini.lua
|
||||
sed -i -e 's/cwrite/cW/g' microtel-5-mini.lua
|
||||
sed -i -e 's/cread/cR/g' microtel-5-mini.lua
|
||||
sed -i -e 's/conn/C/g' microtel-5-mini.lua
|
||||
sed -i -e 's/listener/lI/g' microtel-5-mini.lua
|
||||
sed -i -e 's/slisten/sL/g' microtel-5-mini.lua
|
||||
sed -i -e 's/self/S/g' microtel-5-mini.lua
|
||||
sed -i -e 's/addr/A/g' microtel-5-mini.lua
|
||||
sed -i -e 's/rbuffer/rB/g' microtel-5-mini.lua
|
||||
sed -i -e 's/rport/rP/g' microtel-5-mini.lua
|
||||
sed -i -e 's/nport/nP/g' microtel-5-mini.lua
|
||||
sed -i -e 's/port/P/g' microtel-5-mini.lua
|
||||
sed -i -e 's/sclose/sC/g' microtel-5-mini.lua
|
||||
sed -i -e 's/rdata/rD/g' microtel-5-mini.lua
|
||||
sed -i -e 's/length/lN/g' microtel-5-mini.lua
|
||||
sed -i -e 's/data/D/g' microtel-5-mini.lua
|
||||
sed -i -e 's/from/F/g' microtel-5-mini.lua
|
||||
lua strip.lua microtel-5-mini.lua microtel-5-mini.lua
|
||||
#microtel-5-core.lua
|
||||
cp microtel-5-core.lua microtel-5-core-mini.lua
|
||||
sed -i -e 's/address/A/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/vport/V/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/sclose/S/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/port/P/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/conn.state/conn.s/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/conn.buffer/conn.b/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/conn/C/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/etype/E/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/from/F/g' microtel-5-core-mini.lua
|
||||
sed -i -e 's/data/D/g' microtel-5-core-mini.lua
|
||||
lua strip.lua microtel-5-core-mini.lua microtel-5-core-mini.lua
|
||||
|
||||
#microtel-5-listen.lua
|
||||
cp microtel-5-listen.lua microtel-5-listen-mini.lua
|
||||
sed -i -e 's/address/A/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/vport/V/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/sclose/S/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/port/P/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/conn.state/conn.s/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/conn.buffer/conn.b/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/conn/C/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/etype/E/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/from/F/g' microtel-5-listen-mini.lua
|
||||
sed -i -e 's/data/D/g' microtel-5-listen-mini.lua
|
||||
lua strip.lua microtel-5-listen-mini.lua microtel-5-core-mini.lua
|
||||
|
||||
#microtel-5-flisten.lua
|
||||
cp microtel-5-flisten.lua microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/address/A/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/vport/V/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/sclose/S/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/port/P/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/conn.state/conn.s/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/conn.buffer/conn.b/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/conn/C/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/etype/E/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/from/F/g' microtel-5-flisten-mini.lua
|
||||
sed -i -e 's/data/D/g' microtel-5-flisten-mini.lua
|
||||
lua strip.lua microtel-5-flisten-mini.lua microtel-5-core-mini.lua
|
||||
|
||||
#microtel-5-open.lua
|
||||
cp microtel-5-open.lua microtel-5-open-mini.lua
|
||||
sed -i -e 's/address/A/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/vport/V/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/sclose/S/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/port/P/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/conn.state/conn.s/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/conn.buffer/conn.b/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/conn/C/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/etype/E/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/from/F/g' microtel-5-open-mini.lua
|
||||
sed -i -e 's/data/D/g' microtel-5-open-mini.lua
|
||||
lua strip.lua microtel-5-open-mini.lua microtel-5-core-mini.lua
|
||||
|
Loading…
Reference in New Issue
Block a user