Advertisement
Arc13

Setup for arcLock

Jul 17th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. local args = {...}
  2.  
  3. if not fs.exists("arcui") or args[1] == "true" then
  4. print("Downloading arcUI...")
  5. shell.run("pastebin get NuZUGEmn arcui")
  6. end
  7.  
  8. os.loadAPI("arcui")
  9.  
  10. local twentyFourHour = true
  11. local side = nil
  12. local sideSecond = nil
  13. local doorOpenSeconds = 5
  14. local badPasswordSeconds = 2
  15. local rednetID = nil
  16. local rednetMsg = nil
  17. local rednetProtocol = nil
  18. local exitCode = nil
  19. local code = nil
  20.  
  21. monX, monY = term.getSize()
  22.  
  23. arcui.drawWindow("arcLock setup")
  24. arcui.drawSlider("twenty_slider", 2, 3, "Twenty-four Hour", true)
  25. arcui.drawTextbox("side_one_txtbox", 1, 5, monX / 2 - 2, "Redstone side", nil, nil, nil, rs.getSides())
  26. arcui.drawTextbox("side_two_txtbox", monX / 2 + 2, 5, monX, "Redstone side 2", nil, nil, nil, rs.getSides())
  27. arcui.drawLabel("sec_label", 2, 7, "Open time :")
  28. arcui.drawLabel("sec_bad_label", monX / 2 + 2, 7, "Bad password :")
  29. arcui.drawNumeric("seconds_numeric", 2, 8, monX / 2 - 2, 5, 1, math.huge)
  30. arcui.drawNumeric("seconds_bad_numeric", monX / 2 + 2, 8, monX - 1, 2, 1, math.huge)
  31. arcui.drawTextbox("open_code_txtbox", 1, 11, monX / 2 - 2, "Open code (4 number)")
  32. arcui.drawTextbox("exit_code_txtbox", monX / 2 + 2, 11, monX, "Exit code (4 number)")
  33. arcui.drawLabel("lbl_rednet", 2, 13, "Send a rednet message : (Optional)")
  34. arcui.drawTextbox("rednet_id_textbox", 1, 14, monX / 2 - 2, "Receiver ID")
  35. arcui.drawTextbox("rednet_msg_textbox", monX / 2 + 2, 14, monX, "Message")
  36. arcui.drawTextbox("rednet_protocol_textbox", 1, 16, monX, "Rednet Protocol (Optional)")
  37. arcui.drawButton("confirm_btn", 1, monY, monX, monY, colors.green, ">")
  38.  
  39. function main()
  40. while true do
  41. event, a1, a2, a3 = os.pullEvent()
  42.  
  43. if event == "button_close_clicked" then
  44. arcui.closeWindow()
  45.  
  46. return true
  47. elseif event == "slider_state" then
  48. if a1 == "twenty_slider" then
  49. twentyFourHour = a2
  50. end
  51. elseif event == "numeric_value" then
  52. if a1 == "seconds_numeric" then
  53. doorOpenSeconds = a2
  54. elseif a1 == "seconds_bad_numeric" then
  55. badPasswordSeconds = a2
  56. end
  57. elseif event == "textbox_text" then
  58. if a1 == "side_one_txtbox" then
  59. local result = false
  60.  
  61. for i = 1, #rs.getSides() do
  62. if a2 == rs.getSides()[i] then
  63. result = true
  64. end
  65. end
  66.  
  67. if result == true then
  68. side = a2
  69. elseif a2 == "" then
  70. --Do nothing
  71. else
  72. arcui.openDialog("side_one_dialog", "Invalid side", "You entered an invalid side !")
  73. arcui.redrawWindow("arcLock setup")
  74. arcui.changeValue("side_one_txtbox", "value", "")
  75. end
  76. elseif a1 == "side_two_txtbox" then
  77. local result = false
  78.  
  79. for i = 1, #rs.getSides() do
  80. if a2 == rs.getSides()[i] then
  81. result = true
  82. end
  83. end
  84.  
  85. if result == true then
  86. sideSecond = a2
  87. elseif a2 == "" then
  88. --Do nothing
  89. else
  90. arcui.openDialog("side_two_dialog", "Invalid side", "You entered an invalid side !")
  91. arcui.redrawWindow("arcLock setup")
  92. arcui.changeValue("side_two_txtbox", "value", "")
  93. end
  94. elseif a1 == "open_code_txtbox" then
  95. if a2 == "" then
  96. --Do nothing
  97. elseif not tonumber(a2) then
  98. arcui.openDialog("open_code_dialog", "Invalid code", "Code must be a number !")
  99. arcui.redrawWindow("arcLock setup")
  100. arcui.changeValue("open_code_txtbox", "value", "")
  101. elseif #a2 ~= 4 then
  102. arcui.openDialog("open_code_dialog", "Invalid code", "Code must be 4 numbers !")
  103. arcui.redrawWindow("arcLock setup")
  104. arcui.changeValue("open_code_txtbox", "value", "")
  105. else
  106. code = tonumber(a2)
  107. end
  108. elseif a1 == "exit_code_txtbox" then
  109. if a2 == "" then
  110. --Do nothing
  111. elseif not tonumber(a2) then
  112. arcui.openDialog("exit_code_dialog", "Invalid code", "Code must be a number !")
  113. arcui.redrawWindow("arcLock setup")
  114. arcui.changeValue("exit_code_txtbox", "value", "")
  115. elseif #a2 ~= 4 then
  116. arcui.openDialog("exit_code_dialog", "Invalid code", "Code must be 4 numbers !")
  117. arcui.redrawWindow("arcLock setup")
  118. arcui.changeValue("exit_code_txtbox", "value", "")
  119. else
  120. exitCode = tonumber(a2)
  121. end
  122. elseif a1 == "rednet_id_textbox" then
  123. if tonumber(a2) then
  124. rednetID = a2
  125. else
  126. arcui.openDialog("exit_code_dialog", "Invalid ID", "ID must be a number !")
  127. arcui.redrawWindow("arcLock setup")
  128. arcui.changeValue("rednet_id_textbox", "value", "")
  129. end
  130. elseif a1 == "rednet_msg_textbox" then
  131. rednetMessage = a2
  132. elseif a1 == "rednet_protocol_textbox" then
  133. rednetProtocol = a2
  134. end
  135. elseif event == "button_clicked" then
  136. if a1 == "confirm_btn" then
  137. if not code then
  138. arcui.openDialog("confirm_dialog", "Something is missing...", "You have to enter a code !")
  139. arcui.redrawWindow("arcLock setup")
  140. elseif not exitCode then
  141. arcui.openDialog("confirm_dialog", "Something is missing...", "You have to enter an exit code !")
  142. arcui.redrawWindow("arcLock setup")
  143. else
  144. rep = arcui.openDialog("confirm_dialog", "Save changes", "Do you want to save changes ?")
  145. arcui.redrawWindow("arcLock setup")
  146.  
  147. if rep == true then
  148. settings.set("arclock.twenty_four_hour", twentyFourHour)
  149. if side then
  150. settings.set("arclock.door_side", side)
  151. end
  152. if sideSecond then
  153. settings.set("arclock.door_side_second", sideSecond)
  154. end
  155. settings.set("arclock.door_open_seconds", doorOpenSeconds)
  156. settings.set("arclock.bad_password_seconds", badPasswordSeconds)
  157. settings.set("arclock.code", code)
  158. settings.set("arclock.exit_code", exitCode)
  159. if rednetID and rednetMessage then
  160. settings.set("arclock.rednet_id", tonumber(rednetID))
  161. settings.set("arclock.rednet_message", rednetMessage)
  162. end
  163. if rednetProtocol then
  164. settings.set("arclock.rednet_protocol", rednetProtocol)
  165. end
  166. settings.save(".settings")
  167. if not fs.exists("lock") then
  168. shell.run("pastebin get 5jQcugtT lock")
  169. rep = arcui.openDialog("confirm_dialog", "arcLock setup", "arcLock downloaded as lock.")
  170. arcui.redrawWindow("arcLock setup")
  171. end
  172.  
  173. rep = arcui.openDialog("confirm_dialog", "arcLock setup", "Your computer will reboot...")
  174. os.reboot()
  175. end
  176. end
  177. end
  178. end
  179. end
  180. end
  181.  
  182. parallel.waitForAll(main, arcui.eventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement