jille_Jr

CC: Cannon mail [Server] - main.lua

Feb 22nd, 2016
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- main.lua
  2.  
  3. --(( APIs ))--
  4.  
  5. os.loadAPI("util")
  6. os.loadAPI("inv")
  7. os.loadAPI("mail")
  8.  
  9. --(( Settings ))--
  10.  
  11. local rsOutput = "left"
  12. -- seconds between each tick
  13. local tickDelay = 5
  14. -- seconds between each update
  15. local updateWait = 1
  16.  
  17. --(( Variables ))--
  18.  
  19. --(( Functions ))--
  20.  
  21. local function handleDisk()
  22.     local data = mail.readMail()
  23.  
  24.     if data.err then
  25.         if data.err ~= "missing_item" then
  26.             print(mail.err[data.err])
  27.  
  28.             inv.emptyDrive()
  29.         end
  30.     else
  31.         mail.writeMail(data)
  32.         inv.emptyDrive(inv.getDirection(data.sender))
  33.     end
  34. end
  35.  
  36. local function tickRedstone()
  37.     rs.setOutput(rsOutput, os.clock() % tickDelay / tickDelay > 0.5)
  38. end
  39.  
  40. local function update()
  41.     handleDisk()
  42.     tickRedstone()
  43. end
  44.  
  45. --(( Mane program ))--
  46.  
  47. -- empty the printer just in case
  48. pcall(mail.getPrinter().endPage)
  49. inv.emptyDropper()
  50.  
  51.  
  52. -- Main loop
  53. while true do
  54.     update()
  55.     sleep(updateWait)
  56. end
  57.  
  58. -- eof
RAW Paste Data