Advertisement
znepb

CasavaNet

Jan 24th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. local casavaVer = "1.1.0"
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. print("CasavaNet " .. casavaVer)
  5. local modem = peripheral.find("modem")
  6. modem.open(9191)
  7. local cordinate = nil
  8. local w, h = term.getSize()
  9. local running = false
  10.  
  11. while true do
  12.   local e = {os.pullEvent()}
  13.   if e[1] == "modem_message" then
  14.     local msg = e[5]
  15.  
  16.     if msg.type == "shutdown" then
  17.       print("Shutting down...")
  18.       sleep(0.5)
  19.       os.shutdown()
  20.       modem.transmit(9192, 9191, {
  21.         type = "success",
  22.         action = "shutdown",
  23.       })
  24.     elseif msg.type == "start" then
  25.       running = true
  26.       print("Starting new program")
  27.       local function run()
  28.         print("Running", table.unpack(msg.content))
  29.         shell.run(table.unpack(msg.content))
  30.       end
  31.       cor = coroutine.create(run)
  32.       win = window.create(term.native(), 1, 1, w, h)
  33.     elseif msg.type == "end" then
  34.       running = false
  35.       print("Ending program")
  36.       cor = nil
  37.       win = nil
  38.     elseif msg.type == "event" and running and cor and window then
  39.       local data = msg.content
  40.       term.redirect(win)
  41.       coroutine.resume(cor, unpack(data))
  42.     end
  43.   end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement