From 8b7179edfe44d81c89d230ae2d7cd6b21d0ae0c5 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 4 Sep 2017 02:37:43 +1000 Subject: [PATCH] more fixes for #5 --- modules/net/copper.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/modules/net/copper.lua b/modules/net/copper.lua index fbd16ef..92de0ce 100644 --- a/modules/net/copper.lua +++ b/modules/net/copper.lua @@ -3,7 +3,10 @@ net.id = computer.address():sub(1,8) net.np = 4957 net.tm = {} 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 if cdlib and relib then spawn("copperd",function() print(pcall(function () @@ -38,15 +41,17 @@ spawn("copperd",function() print(pcall(function () event.push("net_rmsg",src,data) local pd = relib.decode(data) if pd then - if pd.pt == 1 then - event.push("net_msg",src,pd.port,pd.msg) - pd.pt = 2 - pd.nid = src - pd.lt = 0 - pd.msg = "" - ps[pd.pid] = pd - elseif pd.pt == 2 then - ps[pd.pid] = nil + if pd.port and pd.pid and pd.at and pd.pt and pd.msg then + if pd.pt == 1 then + event.push("net_msg",src,pd.port,pd.msg) + pd.pt = 2 + pd.nid = src + pd.lt = 0 + pd.msg = "" + ps[pd.pid] = pd + elseif pd.pt == 2 then + ps[pd.pid] = nil + end end end else