mirror of
https://github.com/LDDestroier/CC/
synced 2025-01-09 17:00:28 +00:00
Fixed compatibility for CC 1.41
Also, compatibility with os.loadAPI() has been added, in case you happen to have a version of CC that DOESN'T HAVE REQUIRE or DOESN'T LET DOFILE RETURN ANYTHING
This commit is contained in:
parent
8546f2d807
commit
89e238d07b
23
disknet.lua
23
disknet.lua
@ -1,4 +1,4 @@
|
|||||||
local disknet = {}
|
local disknet = disknet or {}
|
||||||
|
|
||||||
local tArg = {...}
|
local tArg = {...}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ 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
|
disknet.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
|
||||||
@ -25,7 +25,11 @@ 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()
|
||||||
|
if os.day then
|
||||||
return (os.time() + (-1 + os.day()) * 24) + disknet._timeMod
|
return (os.time() + (-1 + os.day()) * 24) + disknet._timeMod
|
||||||
|
else
|
||||||
|
return os.time() + disknet._timeMod
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function serialize(tbl)
|
local function serialize(tbl)
|
||||||
@ -110,6 +114,7 @@ disknet.isOpen = function(channel)
|
|||||||
error(grr)
|
error(grr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
isOpen = disknet.isOpen
|
||||||
|
|
||||||
disknet.open = function(channel)
|
disknet.open = function(channel)
|
||||||
local valid, grr = checkValidChannel(channel)
|
local valid, grr = checkValidChannel(channel)
|
||||||
@ -120,6 +125,7 @@ disknet.open = function(channel)
|
|||||||
error(grr)
|
error(grr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
open = disknet.open
|
||||||
|
|
||||||
disknet.close = function(channel)
|
disknet.close = function(channel)
|
||||||
local valid, grr = checkValidChannel(channel)
|
local valid, grr = checkValidChannel(channel)
|
||||||
@ -135,15 +141,18 @@ disknet.close = function(channel)
|
|||||||
error(grr)
|
error(grr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
close = disknet.close
|
||||||
|
|
||||||
disknet.closeAll = function()
|
disknet.closeAll = function()
|
||||||
openChannels = {}
|
openChannels = {}
|
||||||
end
|
end
|
||||||
|
closeAll = disknet.closeAll
|
||||||
|
|
||||||
disknet.send = function(channel, message, recipient)
|
disknet.send = function(channel, message, recipient)
|
||||||
local valid, grr = checkValidChannel(channel)
|
local valid, grr = checkValidChannel(channel)
|
||||||
if valid then
|
if valid then
|
||||||
if not fs.exists(fs.combine(disknet.mainPath, tostring(channel))) then
|
if not fs.exists(fs.combine(disknet.mainPath, tostring(channel))) then
|
||||||
|
fs.makeDir(disknet.mainPath)
|
||||||
fs.open(fs.combine(disknet.mainPath, tostring(channel)), "w").close()
|
fs.open(fs.combine(disknet.mainPath, tostring(channel)), "w").close()
|
||||||
end
|
end
|
||||||
local contents = textutils.unserialize(readFile(fs.combine(disknet.mainPath, tostring(channel))))
|
local contents = textutils.unserialize(readFile(fs.combine(disknet.mainPath, tostring(channel))))
|
||||||
@ -188,6 +197,7 @@ disknet.send = function(channel, message, recipient)
|
|||||||
error(grr)
|
error(grr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
send = disknet.send
|
||||||
|
|
||||||
local fList, pList, sList = {}, {}, {}
|
local fList, pList, sList = {}, {}, {}
|
||||||
|
|
||||||
@ -204,6 +214,7 @@ local loadFList = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns: string message, string/number channel, number senderID, number timeThatMessageWasSentAt
|
||||||
disknet.receive = function(channel, senderFilter)
|
disknet.receive = function(channel, senderFilter)
|
||||||
local valid, grr = checkValidChannel(channel)
|
local valid, grr = checkValidChannel(channel)
|
||||||
if valid or not channel then
|
if valid or not channel then
|
||||||
@ -224,7 +235,7 @@ disknet.receive = function(channel, senderFilter)
|
|||||||
if contents[1] then
|
if contents[1] then
|
||||||
if not output then
|
if not output then
|
||||||
for look = 1, #contents do
|
for look = 1, #contents do
|
||||||
if (contents[look].uniqueID ~= uniqueID) and (not msgCheckList[contents[look].messageID]) then -- make sure you're not receiving messages that you sent
|
if (contents[look].uniqueID ~= uniqueID) and (not disknet.msgCheckList[contents[look].messageID]) then -- make sure you're not receiving messages that you sent
|
||||||
if (not contents[look].recipient) or contents[look].recipient == yourID then -- make sure that messages intended for others aren't picked up
|
if (not contents[look].recipient) or contents[look].recipient == yourID then -- make sure that messages intended for others aren't picked up
|
||||||
if (not channel) or channel == contents[look].channel then -- make sure that messages are the same channel as the filter, if any
|
if (not channel) or channel == contents[look].channel then -- make sure that messages are the same channel as the filter, if any
|
||||||
if (not senderFilter) or senderFilter == contents[look].id then -- make sure that the sender is the same as the id filter, if any
|
if (not senderFilter) or senderFilter == contents[look].id then -- make sure that the sender is the same as the id filter, if any
|
||||||
@ -234,7 +245,7 @@ disknet.receive = function(channel, senderFilter)
|
|||||||
goWithIt = true
|
goWithIt = true
|
||||||
end
|
end
|
||||||
if cTime - (contents[look].time or 0) <= ageToToss or goWithIt then -- make sure the message isn't too old
|
if cTime - (contents[look].time or 0) <= ageToToss or goWithIt then -- make sure the message isn't too old
|
||||||
msgCheckList[contents[look].messageID] = true
|
disknet.msgCheckList[contents[look].messageID] = true
|
||||||
output = {}
|
output = {}
|
||||||
for k,v in pairs(contents[look]) do
|
for k,v in pairs(contents[look]) do
|
||||||
output[k] = v
|
output[k] = v
|
||||||
@ -252,7 +263,7 @@ disknet.receive = function(channel, senderFilter)
|
|||||||
doRewrite = false
|
doRewrite = false
|
||||||
for t = #contents, 1, -1 do
|
for t = #contents, 1, -1 do
|
||||||
if cTime - (contents[t].time or 0) > ageToToss or cTime - (contents[t].time or 0) < -1 then
|
if cTime - (contents[t].time or 0) > ageToToss or cTime - (contents[t].time or 0) < -1 then
|
||||||
msgCheckList[contents[t].messageID] = nil
|
disknet.msgCheckList[contents[t].messageID] = nil
|
||||||
table.remove(contents, t)
|
table.remove(contents, t)
|
||||||
doRewrite = true
|
doRewrite = true
|
||||||
end
|
end
|
||||||
@ -300,6 +311,7 @@ disknet.receive = function(channel, senderFilter)
|
|||||||
error(grr)
|
error(grr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
receive = disknet.receive
|
||||||
|
|
||||||
-- not really needed if going between CCEmuX and another emulator, but may be needed between two separate CCEmuX daemons
|
-- not really needed if going between CCEmuX and another emulator, but may be needed between two separate CCEmuX daemons
|
||||||
disknet.receive_TS = function(...)
|
disknet.receive_TS = function(...)
|
||||||
@ -309,5 +321,6 @@ disknet.receive_TS = function(...)
|
|||||||
end
|
end
|
||||||
return message, channel, id, time
|
return message, channel, id, time
|
||||||
end
|
end
|
||||||
|
receive_TS = disknet.receive_TS
|
||||||
|
|
||||||
return disknet
|
return disknet
|
||||||
|
Loading…
Reference in New Issue
Block a user