Advertisement
Marlingaming

PowerBox System

Nov 21st, 2022 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. local Modem
  2. local Drive
  3. local ID
  4. local Key
  5. local Company
  6. local Client
  7. local EndTime = 0
  8.  
  9. local V = "1.0"
  10.  
  11. local SCh
  12. local LCh
  13.  
  14. local function StopProgram()
  15. print("stopping terminal . . .")
  16. os.shutdown()
  17. end
  18.  
  19. local function RunDrive()
  20. local Path
  21. if Drive.isPresent() then Path = Drive.getMethod() end
  22. if fs.exists(Path.."/BoxDetails.txt") then fs.copy(Path.."/BoxDetails.txt","Account.txt") end
  23. end
  24.  
  25. local function CheckPeripherals()
  26. if peripheral.isPresent("modem") then Modem = peripheral.find("modem") end
  27. if peripheral.isPresent("drive") then Drive = peripheral.find("Drive") RunDrive() end
  28. end
  29.  
  30. local function CheckCertificate()
  31. if fs.exists("Certificate.txt") then
  32. local file = fs.open("Certificate".txt","r")
  33. local Data = textutils.unserialize(file.readAll())
  34. file.close()
  35. SCh = Data[2]
  36. LCh = Data[3]
  37. end
  38. end
  39.  
  40. local function CheckAccount()
  41. if fs.exists("Account.txt") then
  42. local file = fs.open("Account.txt","r")
  43. local Data = textutils.unserialize(file.readAll())
  44. file.close()
  45. ID = Data[1]
  46. Key = Data[2]
  47. Company = Data[3]
  48. Client = Data[4]
  49. EndTime = Data[5]
  50. print("account file found")
  51. print("ready")
  52. else
  53. print("account file missing")
  54. StopProgram()
  55. end
  56. end
  57.  
  58. local function Message(MSG)
  59. local Data = {ID,Key,MSG}
  60. Modem.transmit(SCh,LCh,textutils.serialize(Data))
  61. Modem.open(LCh)
  62. local a, b, c, d, e
  63. repeat
  64. a, b, c, d, e = os.pullEvent("modem_message")
  65. until b == LCh
  66. return textutils.unseriaize(e)
  67. end
  68.  
  69. local function Loop()
  70. while true do
  71. if os.day("ingame") > EndTime then redstone.setOutput("top",false) break else redstone.setOutput("top",true) end
  72. if Modem ~= nil and fs.exists("Certificate.txt")
  73. Modem.open(LCh)
  74. local a, b, c, d, e = os.pullEvent("modem_message")
  75. end
  76. end
  77. end
  78.  
  79. local function DisplayText(text)
  80. term.clear()
  81. term.setCursorPos(1,1)
  82. print(text)
  83. end
  84.  
  85. local function CMenu()
  86. term.clear()
  87. term.setCursorPos(1,1)
  88. print("==Consumer=Menu==")
  89. print("Client: "..Client..", Company: "..Company)
  90. print("ID: "..ID)
  91. print("days til next invoice: "..(EndTime - os.day("ingame")))
  92. print("==Options==")
  93. print("1 - details")
  94. print("2 - payment")
  95. if Modem ~= nil and Drive ~= nil then print("3 - Download Certificate") else print("<requires Modem and Drive>")
  96. print("4 - continue boot")
  97. local a, b
  98. repeat
  99. a, b = os.pullEvent("key")
  100. until b == keys.one or b == keys.two or (b == keys.three and Modem ~= nil and Drive ~= nil) or b == keys.four
  101. if b == keys.one then
  102. DisplayText(Company.." Endorsed Power Unit Box")
  103. os.reboot(2)
  104. os.reboot()
  105. elseif b == keys.two then
  106. DisplayText("payment can be submitted at anytime")
  107. os.sleep(2)
  108. os.reboot()
  109. elseif b == keys.three and Modem ~= nil and Drive ~= nil then
  110. if Drive.isPresent() and fs.exists(fs.combine(Drive.getMethod(),"Certificate.txt")) then fs.copy(fs.combine(Drive.getMethod(),"Certificate.txt"),"Certificate.txt") os.reboot() end
  111. elseif b == keys.four then
  112. Loop()
  113. else
  114. os.reboot()
  115. end
  116. end
  117.  
  118. local function Start()
  119. term.clear()
  120. term.setCursorPos(1,1)
  121. print("=======Power=Box="..V.."======")
  122. print("starting terminal . . .")
  123. CheckPeripherals()
  124. CheckAccount()
  125. if Modem ~= nil then CheckCertificate() end
  126. if Modem ~= nil and fs.exists("Certificate.txt") then if Message("auth_unit")[2] == false then StopProgram() end end
  127. local Time = os.time("ingame") + 0.01
  128. print("to enter consumer menu, press enter within 10 seconds")
  129. local a, b = os.pullEvent("key")
  130. repeat until b == keys.enter or os.time("ingame") > Time
  131. if b == keys.enter then CMenu() else Loop() end
  132. end
  133.  
  134. Start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement