made listen and flisten care what is sent to them

This commit is contained in:
Izaya 2018-02-17 18:31:50 +11:00
parent 6240fe7218
commit e891f0d220
1 changed files with 15 additions and 1 deletions

View File

@ -113,7 +113,7 @@ end
function net.listen(port)
repeat
_, from, rport, data = event.pull("net_msg")
until rport == port
until rport == port and data == "openstream"
local nport = math.random(net.minport,net.maxport)
local sclose = net.genPacketID()
net.rsend(from,rport,tostring(nport))
@ -121,4 +121,18 @@ function net.listen(port)
return socket(from,nport,sclose)
end
function net.flisten(port,listener)
local function helper(_,from,rport,data)
if rport == port and data == "openstream" then
local nport = math.random(net.minport,net.maxport)
local sclose = net.genPacketID()
net.rsend(from,rport,tostring(nport))
net.rsend(from,nport,sclose)
listener(socket(from,nport,sclose))
end
end
event.listen("net_msg",helper)
return helper
end
return net