more fixes for #5

This commit is contained in:
Izaya 2017-09-04 02:37:43 +10:00
parent 9bc2b463ec
commit 8b7179edfe

View File

@ -3,7 +3,10 @@ net.id = computer.address():sub(1,8)
net.np = 4957 net.np = 4957
net.tm = {} net.tm = {}
function net.send(id,po,msg) -- id, port, message function net.send(id,po,msg) -- id, port, message
event.push("sendmsg",id,po,msg) if id and po and msg then
event.push("sendmsg",id,po,msg)
else return false
end
end end
if cdlib and relib then if cdlib and relib then
spawn("copperd",function() print(pcall(function () spawn("copperd",function() print(pcall(function ()
@ -38,15 +41,17 @@ spawn("copperd",function() print(pcall(function ()
event.push("net_rmsg",src,data) event.push("net_rmsg",src,data)
local pd = relib.decode(data) local pd = relib.decode(data)
if pd then if pd then
if pd.pt == 1 then if pd.port and pd.pid and pd.at and pd.pt and pd.msg then
event.push("net_msg",src,pd.port,pd.msg) if pd.pt == 1 then
pd.pt = 2 event.push("net_msg",src,pd.port,pd.msg)
pd.nid = src pd.pt = 2
pd.lt = 0 pd.nid = src
pd.msg = "" pd.lt = 0
ps[pd.pid] = pd pd.msg = ""
elseif pd.pt == 2 then ps[pd.pid] = pd
ps[pd.pid] = nil elseif pd.pt == 2 then
ps[pd.pid] = nil
end
end end
end end
else else