mirror of https://github.com/LDDestroier/CC/
Added time syncing feature (for working across emulators)
This commit is contained in:
parent
1476a88691
commit
772ed1b739
15
disknet.lua
15
disknet.lua
|
@ -2,7 +2,7 @@ local disknet = {}
|
||||||
|
|
||||||
local tArg = {...}
|
local tArg = {...}
|
||||||
|
|
||||||
disknet.mainPath = tArg[1] or "disk/DISKNET"
|
disknet.mainPath = "disk/DISKNET"
|
||||||
local limitChannelsToModem = false
|
local limitChannelsToModem = false
|
||||||
local useSleepToYield = false
|
local useSleepToYield = false
|
||||||
local maximumBufferSize = 64
|
local maximumBufferSize = 64
|
||||||
|
@ -13,9 +13,12 @@ local uniqueID = math.random(1, 2^31 - 1) -- prevents receiving your own message
|
||||||
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
|
local ageToToss = 0.002 -- amount of time before a message is removed
|
||||||
|
|
||||||
|
-- used for synching times between different emulators
|
||||||
|
disknet._timeMod = 0
|
||||||
|
|
||||||
-- 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()
|
||||||
return os.time() + (-1 + os.day()) * 24
|
return (os.time() + (-1 + os.day()) * 24) + disknet._timeMod
|
||||||
end
|
end
|
||||||
|
|
||||||
local readFile = function(path)
|
local readFile = function(path)
|
||||||
|
@ -250,4 +253,12 @@ disknet.receive = function(channel, senderFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
disknet.receive_TS = function(...)
|
||||||
|
local message, channel, id, time = disknet.receive(...)
|
||||||
|
if time then
|
||||||
|
disknet._timeMod = time - getTime()
|
||||||
|
end
|
||||||
|
return message, channel, id, time
|
||||||
|
end
|
||||||
|
|
||||||
return disknet
|
return disknet
|
||||||
|
|
Loading…
Reference in New Issue