From 772ed1b73972218ef1255e057e259d8a90decec6 Mon Sep 17 00:00:00 2001 From: LDDestroier Date: Sat, 1 Feb 2020 05:21:35 -0500 Subject: [PATCH] Added time syncing feature (for working across emulators) --- disknet.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/disknet.lua b/disknet.lua index b250dc0..41431e5 100644 --- a/disknet.lua +++ b/disknet.lua @@ -2,7 +2,7 @@ local disknet = {} local tArg = {...} -disknet.mainPath = tArg[1] or "disk/DISKNET" +disknet.mainPath = "disk/DISKNET" local limitChannelsToModem = false local useSleepToYield = false 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 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 local getTime = function() - return os.time() + (-1 + os.day()) * 24 + return (os.time() + (-1 + os.day()) * 24) + disknet._timeMod end local readFile = function(path) @@ -250,4 +253,12 @@ disknet.receive = function(channel, senderFilter) 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