1
0
mirror of https://github.com/LDDestroier/CC/ synced 2025-01-19 05:32:51 +00:00

Update disknet.lua

This commit is contained in:
LDDestroier 2019-05-07 21:32:18 -04:00 committed by GitHub
parent d666db5125
commit 9262842835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,12 +4,13 @@ local tArg = {...}
disknet.mainPath = tArg[1] or "disk/DISKNET" disknet.mainPath = tArg[1] or "disk/DISKNET"
local limitChannelsToModem = false local limitChannelsToModem = false
local maximumBufferSize = 32 local maximumBufferSize = 64
local openChannels = {} local openChannels = {}
local yourID = os.getComputerID() local yourID = os.getComputerID()
local uniqueID = math.random(1, 2^31 - 1) -- prevents receiving your own messages local uniqueID = math.random(1, 2^31 - 1) -- prevents receiving your own messages
local msgCheckList = {} -- makes sure duplicate messages aren't received local msgCheckList = {} -- makes sure duplicate messages aren't received
local ageToToss = 0.002 -- amount of time before a message is removed
-- do not think for one second that os.epoch("utc") would be a proper substitute -- do not think for one second that os.epoch("utc") would be a proper substitute
local getTime = function() local getTime = function()
@ -174,7 +175,7 @@ disknet.receive = function(channel)
for look = 1, #contents do for look = 1, #contents do
if (contents[look].uniqueID ~= uniqueID) and (not msgCheckList[contents[look].messageID]) then if (contents[look].uniqueID ~= uniqueID) and (not msgCheckList[contents[look].messageID]) then
if (not contents[look].recipient) or contents[look].recipient == yourID then if (not contents[look].recipient) or contents[look].recipient == yourID then
if getTime() - (contents[look].time or 0) <= 0.001 then if getTime() - (contents[look].time or 0) <= ageToToss then
msgCheckList[contents[look].messageID] = true msgCheckList[contents[look].messageID] = true
output = {} output = {}
for k,v in pairs(contents[look]) do for k,v in pairs(contents[look]) do
@ -190,7 +191,7 @@ disknet.receive = function(channel)
-- delete old msesages -- delete old msesages
doRewrite = false doRewrite = false
for t = #contents, 1, -1 do for t = #contents, 1, -1 do
if getTime() - (contents[t].time or 0) > 0.001 then if getTime() - (contents[t].time or 0) > ageToToss then
msgCheckList[contents[t].messageID] = nil msgCheckList[contents[t].messageID] = nil
table.remove(contents, t) table.remove(contents, t)
doRewrite = true doRewrite = true