Reduced amount of new fs.open()'s

This commit is contained in:
LDDestroier 2019-05-02 11:00:43 -04:00 committed by GitHub
parent 714da7ee03
commit 4e0369e7d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 11 deletions

View File

@ -153,22 +153,25 @@ end
disknet.receive = function(channel)
local valid, grr = checkValidChannel(channel)
if valid or not channel then
local output, contents
local doRewrite = false
loadFList()
while true do
loadFList()
for i = 1, #fList do
contents = fList[i].readAll()
if contents ~= "" then
contents = textutils.unserialize(contents)
fList[i].close()
fList[i] = fs.open(pList[i], "r")
contents = textutils.unserialize(fList[i].readAll())
if type(contents) == "table" then
if contents[1] then
if not output then
for look = 1, #contents do
if (contents[look].uniqueID ~= uniqueID) and (not msgCheckList[contents[look].messageID]) then
if getTime() - (contents[look].time or 0) <= 0.01 then
if getTime() - (contents[look].time or 0) <= 0.001 then
msgCheckList[contents[look].messageID] = true
output = {}
for k,v in pairs(contents[look]) do
@ -179,11 +182,11 @@ disknet.receive = function(channel)
end
end
end
-- delete old msesages
doRewrite = false
for t = #contents, 1, -1 do
if getTime() - (contents[t].time or 0) > 0.01 then
if getTime() - (contents[t].time or 0) > 0.001 then
msgCheckList[contents[t].messageID] = nil
table.remove(contents, t)
doRewrite = true
@ -205,14 +208,11 @@ disknet.receive = function(channel)
if output then
break
else
for i = 1, #fList do
fList[i].close()
end
os.queueEvent("")
os.pullEvent("")
end
end
if contents then
return output.message, output.channel, output.id, output.time
else