LDDestroier

Syncro (cc) (test)

Jan 6th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. -- pastebin get j9qGCdRR syncro
  2. local path = "disk/disknet_data"
  3. local eventBlacklist = {
  4.     timer = true,
  5. }
  6.  
  7. local id = math.random(0,99999999) --this might be replaced with a better check
  8. local wfile = fs.open(path,"a")
  9. wfile.flush()
  10. local rfile = fs.open(path,"r")
  11. local readData = function()
  12.     local line, tblpos
  13.     while true do
  14.         line = rfile.readLine()
  15.         if line then
  16.             if line:sub(1,#tostring(id)) ~= tostring(id) then
  17.                 tblpos = line:find("{")
  18.                 detectedEvents = textutils.unserialize(line:sub(tblpos+1))
  19.                 os.queueEvent(table.unpack(detectedEvents))
  20.                 for a = 1, #detectedEvents do
  21.                     print(detectedEvents[a])
  22.                 end
  23.                 term.setBackgroundColor(colors.white)
  24.                 term.clearLine()
  25.                 term.setBackgroundColor(colors.black)
  26.                 print("")
  27.             end
  28.         else
  29.             sleep(0)
  30.         end
  31.     end
  32. end
  33. local writeData = function()
  34.     local evt
  35.     while true do
  36.         evt = {os.pullEvent()}
  37.         if not eventBlacklist[evt[1]] then
  38.             wfile.writeLine(tostring(id)..textutils.serialize(evt):gsub("\n",""):gsub(",}","}"))
  39.             wfile.flush()
  40.         end
  41.     end
  42. end
  43.  
  44. parallel.waitForAny(writeData,readData)
Add Comment
Please, Sign In to add comment