mirror of
https://github.com/LDDestroier/CC/
synced 2025-01-08 08:20:27 +00:00
Fixed bad minification
This commit is contained in:
parent
3a11d244f2
commit
ba5287dd78
47
disknet.lua
47
disknet.lua
@ -17,17 +17,52 @@ end
|
|||||||
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.005 -- amount of time before a message is removed
|
local ageToToss = 0.005 -- amount of time before a message is removed
|
||||||
|
|
||||||
-- used for synching times between different emulators
|
-- used for synching times between different emulators
|
||||||
disknet._timeMod = 0
|
disknet._timeMod = 0
|
||||||
|
|
||||||
-- I would have used os.epoch("utc"), but not every emulator has that
|
-- 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) + disknet._timeMod
|
return (os.time() + (-1 + os.day()) * 24) + disknet._timeMod
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function serialize(tbl)
|
||||||
|
local output = "{"
|
||||||
|
local noKlist = {}
|
||||||
|
local cc = table.concat
|
||||||
|
for i = 1, #tbl do
|
||||||
|
if type(tbl[i]) == "table" then
|
||||||
|
output = output .. serialize(tbl[i])
|
||||||
|
elseif type(tbl[i]) == "string" then
|
||||||
|
output = cc({output, "\"", tbl[i], "\""})
|
||||||
|
else
|
||||||
|
output = output .. tbl[i]
|
||||||
|
end
|
||||||
|
noKlist[i] = true
|
||||||
|
output = output .. ","
|
||||||
|
end
|
||||||
|
for k,v in pairs(tbl) do
|
||||||
|
if not noKlist[k] then
|
||||||
|
if type(k) == "number" or type(k) == "table" then
|
||||||
|
output = cc({output, "[", k, "]="})
|
||||||
|
else
|
||||||
|
output = cc({output, k, "="})
|
||||||
|
end
|
||||||
|
if type(v) == "table" then
|
||||||
|
output = output .. serialize(v)
|
||||||
|
elseif type(v) == "string" then
|
||||||
|
output = cc({output, "\"", v, "\""})
|
||||||
|
else
|
||||||
|
output = output .. v
|
||||||
|
end
|
||||||
|
output = output .. ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return output:sub(1, -2):gsub("\n", "\\n") .. "}"
|
||||||
|
end
|
||||||
|
|
||||||
local readFile = function(path)
|
local readFile = function(path)
|
||||||
local file = fs.open(path, "r")
|
local file = fs.open(path, "r")
|
||||||
local contents = file.readAll()
|
local contents = file.readAll()
|
||||||
@ -133,9 +168,9 @@ disknet.send = function(channel, message, recipient)
|
|||||||
if #contents > maximumBufferSize then
|
if #contents > maximumBufferSize then
|
||||||
table.remove(contents, 1)
|
table.remove(contents, 1)
|
||||||
end
|
end
|
||||||
file.write(textutils.serialize(contents):gsub("\n[ ]*", ""))
|
file.write(serialize(contents))
|
||||||
else
|
else
|
||||||
file.write(textutils.serialize({{
|
file.write(serialize({{
|
||||||
time = cTime,
|
time = cTime,
|
||||||
id = yourID,
|
id = yourID,
|
||||||
uniqueID = uniqueID,
|
uniqueID = uniqueID,
|
||||||
@ -223,7 +258,7 @@ disknet.receive = function(channel, senderFilter)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if doRewrite then
|
if doRewrite then
|
||||||
writeFile(pList[i], textutils.serialize(contents))
|
writeFile(pList[i], serialize(contents))
|
||||||
end
|
end
|
||||||
if output then
|
if output then
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user