Advertisement
OfficialStamper

derlV1.1.0

Aug 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. --derl (Draconic Evolution Reactor Listener) V1.1.0
  2. --Official Stamper (c) Aug 2018
  3.  
  4. --Changelog V1.1.0 added OC Code
  5.  
  6. local modemSide = 'bottom'    -- Only required for CC
  7. local reactorSide = 'top'
  8. local modemTx = 21
  9. local modemRx = 21
  10.  
  11. --Peripherals and components (do not initialise to values)
  12. local modem
  13. local reactor
  14. local serialization
  15. local fileIO
  16.  
  17. --check os version
  18. local OSVer = ""
  19. local OC = false
  20. local CC = false
  21.  
  22. if _OSVERSION then
  23.     OSVer = _OSVERSION
  24.     OC = true
  25. elseif os.version() then
  26.     OSVer = os.version()
  27.     CC = true
  28. end
  29.  
  30. if CC then
  31.     --Open the modem on the channel specified
  32.     modem = peripheral.wrap(modemSide)
  33.     reactor = peripheral.wrap(reactorSide)
  34.     fileIO = fs
  35.  
  36. elseif OC then
  37.     local component = require("component")
  38.     local computer = require("computer")
  39.     local event = require("event")
  40.     local term = require("term")
  41.     serialization = require("serialization")
  42.     fileIO = require("filesystem")
  43.     modem = component.modem
  44.     local gpu = component.gpu
  45.     reactor = component.draconic_reactor
  46.     os.pullEvent = event.pull
  47.     modem.transmit = modem.broadcast
  48.     os.getComputerID = computer.address
  49.     os.reboot = function()
  50.                     computer.shutdown(true)
  51.                 end
  52.  
  53. else
  54.     -- no valid OS
  55. end
  56.  
  57. modem.open(modemRx)
  58. print("Listening on port ("..modemRx..").....")
  59.  
  60. local request = {
  61.     getReactorInfo  = function(id)
  62.                             local info = reactor.getReactorInfo()
  63.                             if OC then info = serialization.serialize(info) end
  64.                             modem.transmit(modemTx, id, info)
  65.                         end,
  66.     chargeReactor   = function() reactor.chargeReactor() end,
  67.     activateReactor = function() reactor.activateReactor() end,
  68.     stopReactor     = function() reactor.stopReactor() end,
  69.     setFailSafe     = function() reactor.setFailSafe() end,
  70.     reset           = function() reactor.reset() end
  71. }
  72.  
  73. function main()
  74.     while true do
  75.    
  76.         local event, modemSide, senderChannel, id, message, senderDistance, more = os.pullEvent("modem_message")
  77.  
  78.         if OC then
  79.             senderChannel = id
  80.             id = senderDistance
  81.             message = serialization.unserialize(more)
  82.         end
  83.        
  84.         if (senderChannel == modemRx) then  -- is this message for me?
  85.             request[message.req](id)
  86.         else
  87.             --Message not for me
  88.         end
  89.  
  90.     end
  91. end
  92.  
  93. --main()
  94. local errNo, errMsg = pcall(main)
  95.  
  96. if not errNo then
  97.     print(tostring(errNo).."    "..tostring(errMsg))
  98.     if errMsg == "Terminated" or errMsg == "interrupted" then
  99.         return
  100.     else
  101.         local f = fileIO.open("log","a")
  102.         f:write("#"..os.getComputerID().." :: "..errMsg.."\n")
  103.         f:close()
  104.         os.reboot()
  105. --print("Reboot commented")
  106.     end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement