Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local filename = ".syncro"
- local tArg = {...}
- _G.isClient = false
- local evtqueue = {}
- if parallel.waitForAny(function()
- sleep(0.25) end, function()
- while true do
- local _,key = os.pullEvent("key")
- if key == keys.home then
- return
- end
- end
- end) == 2 then
- _G.isClient = true
- print("You are client.")
- end
- sliceEventLog = function(newSize)
- local file = fs.open(filename,"r")
- local line = ""
- local input = {}
- repeat
- line = file.readLine()
- if line then
- table.insert(input,line)
- end
- until not line
- file.close()
- file = fs.open(filename,"w")
- for a = #input-(newSize or 5), #input do
- file.writeLine(input[a])
- end
- file.close()
- end
- readEvents = function()
- local lines = 0
- while true do
- sleep(0)
- local file = fs.open(filename,"r")
- if file then
- local line = ""
- while true do
- line = file.readLine()
- if line and (#(line or {}) > 1) then
- lines = lines + 1
- local isc = line:sub(1,1) == "t"
- line = line:sub(2)
- if isc ~= _G.isClient and textutils.unserialise(line) then
- os.queueEvent(unpack(textutils.unserialise(line)))
- end
- end
- if not line then sleep(0) end
- if lines > 50 then
- sliceEventLog(5)
- lines = 5
- end
- end
- end
- end
- end
- getEvents = function()
- while true do
- local evt = {os.pullEvent()}
- table.insert(evtqueue,evt)
- end
- end
- writeEvents = function()
- while true do
- if #evtqueue > 0 then
- local evt = evtqueue[1]
- --if evt[1] ~= "timer" then
- local file = fs.open(filename,"a")
- file.writeLine(tostring(_G.isClient):sub(1,1)..textutils.serialise(evt):gsub("\n",""))
- file.close()
- --end
- table.remove(evtqueue,1)
- else
- sleep(0)
- end
- end
- end
- carryOn = function()
- local path
- if not shell then
- os.loadAPI("shell")
- end
- if #tArg > 0 then
- path = shell.resolve(tArg[1])
- else
- path = "/rom/programs/shell"
- end
- local file = fs.open(path,"r")
- if not file then
- return "No such program", false
- end
- local func = loadstring(file.readAll())
- setfenv(func,getfenv())
- table.remove(tArg,1)
- func(unpack(tArg))
- os.shutdown()
- end
- local funky = {
- writeEvents,
- readEvents,
- getEvents,
- }
- if not isClient then
- table.insert(funky,carryOn)
- end
- parallel.waitForAny(unpack(funky))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement