Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. -- Variables
  2. local delay = 5
  3. local modem = peripheral.wrap("top")
  4.  
  5. local server = 10
  6.  
  7. local Chan = tonumber(os.getComputerID())
  8.  
  9. local rChan = tonumber(os.getComputerID())
  10.  
  11. -- Users table
  12. local users = {
  13. ["Admin"] = {["password"] = "password", ["permissions"] = "admin"},
  14. }
  15.  
  16. local logo = {
  17.  
  18.  
  19. }
  20.  
  21. local commands = {
  22. ["Add User"] = "Adds a user with permission. You must be a moderator or admin to add the user",
  23. ["Remove User"] = "Removes user. Must have moderator or admin privilages.",
  24. ["Launch missile"] = "Activates launch handle system,",
  25. ["open door"] = "Opens launch bay doors.",
  26. ["close door"] = "Closes launch bay doors.",
  27. }
  28.  
  29. ----------------------------------------------------------
  30.  
  31. -- Startup Function
  32. local function startup()
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. term.setCursorPos(18,8)
  36. term.setTextColor(colors.lime)
  37. print("MissileCraft 1.04")
  38. term.setCursorPos(18,9)
  39. print("'Speedy Skeleton'")
  40. sleep(5)
  41. term.clear()
  42. term.setCursorPos(1,1)
  43. term.setTextColor(colors.white)
  44.  
  45. modem.open( Chan )
  46.  
  47.  
  48. term.setBackgroundColor(colors.black)
  49. modem.open(tonumber(os.getComputerID()))
  50. file = fs.open("/.users", "r")
  51. dataT = file.readAll()
  52. data = textutils.unserialize(dataT)
  53. file.close()
  54. users = data
  55.  
  56. end
  57. ----------------------------------------------------------
  58. local function checkUNamePasswd()
  59. local uName
  60. while (not users[uName]) or users[uName].password ~= passwd do
  61. term.clear()
  62. term.setCursorPos(1, 1)
  63. textutils.slowPrint("Enter username:", 25)
  64. local uName = read()
  65. -- Now check store password as variable
  66. term.clear()
  67. term.setCursorPos(1, 1)
  68. textutils.slowPrint("Enter your password:", 25)
  69. local passwd = read()
  70. if (not users[uName]) or users[uName].password ~= passwd then
  71. term.clear()
  72. term.setCursorPos(1, 1)
  73. term.setTextColor(colors.red)
  74. textutils.slowPrint("Incorrect password! Please try again.", 50)
  75. term.setTextColor(colors.white)
  76. print("")
  77. else
  78. break
  79. end
  80. end
  81. end
  82. ----------------------------------------------------------
  83. local function checkUsrNamePerm()
  84. local uName
  85. while (not users[uName]) or (users[uName].permissions ~= "admin" and users[uName].permissions ~= "moderator") do
  86. term.clear()
  87. term.setCursorPos(1, 1)
  88. textutils.slowPrint("Enter username for verification", 25)
  89. uName = read()
  90. if (not users[uName]) or (users[uName].permissions ~= "admin" and users[uName].permissions ~= "moderator") then
  91. print("You don't have enough permissions! Please try again.")
  92. else
  93. break
  94. end
  95. end
  96. end
  97. ----------------------------------------------------------
  98. local function save(table,users)
  99. local file = fs.open(".users", "w")
  100. file.write(textutils.serialize(users))
  101. file.close()
  102. end
  103. ----------------------------------------------------------
  104. local function addUsr(Name, password, permissions)
  105. users[Name] = {}
  106. users[Name].password = password
  107. users[Name].permissions = permissions
  108. save(users, users)
  109. end
  110. ---------------------------------------------------------
  111. local function checkLoadbarLib()
  112. f = fs.exists("/lib/loadBar")
  113. if f == true then
  114. break
  115. elseif f == false then
  116. fs.makeDir("/lib")
  117. shell.run("pastebin","get","zeG34tu6","LoadBar")
  118. fs.move("LoadBar", "/lib/LoadBar")
  119. end
  120. end
  121. checkLoadbarLib()
  122. ----------------------------------------------------------
  123. os.loadAPI("/lib/LoadBar")
  124. local bar = LoadBar.init(LoadBar.ASCII_BAR_ONLY, nil, 10, 30, 14, nil, nil, nil, nil )
  125. local function doStuff()
  126. bar:setMessage( "Loading..." )
  127. for i = 1, 9 do
  128. sleep(0.5)
  129. bar:triggerUpdate("Initializing component("..(bar:getCurrentProgress()+1).."/9)")
  130. end
  131. bar:triggerUpdate("Done!")
  132. end
  133. ----------------------------------------------------------
  134. local function doBar()
  135. bar:run( true )
  136. end
  137. ----------------------------------------------------------
  138. local function missile_launch()
  139. -- Code here...
  140.  
  141. -- Run the loading bar
  142. parallel.waitForAll( doBar, doStuff )
  143. term.clear()
  144. term.setBackgroundColor(colors.gray)
  145. term.setCursorPos(1, 1)
  146. for i = 1, 19 do
  147. print(" ")
  148. end
  149. term.setTextColor(colors.yellow)
  150. term.setCursorPos(1, 1)
  151. textutils.slowPrint("Remote missile launch system" )
  152. textutils.slowPrint("Usage: launch <label>", 50)
  153. term.setTextColor(colors.white)
  154. lSilo = read()
  155. print("Confirm launch![Y/N]")
  156. _, char = os.pullEvent("char")
  157. if char == "y" then
  158. modem.transmit(server, rChan, lSilo)
  159. elseif char == "n" then
  160. do main_CLI() end
  161. end
  162. end
  163. ----------------------------------------------------------
  164. local function addUser_CLI()
  165. -- Code here...
  166. term.clear()
  167. term.setCursorPos(1, 1)
  168. print("User addition system")
  169. print("Press enter to continue")
  170. os.pullEvent("key")
  171. textutils.slowPrint("What should the user's username be?", 50)
  172. local name = read()
  173. print("What would you like "..name.."'s password to be?")
  174. local passwd = read()
  175. print("What permissions should user "..name.." have?")
  176. local perms = read()
  177. for i = 1,10 do
  178. term.setCursorPos(18, 30)
  179. sleep(.3)
  180. end
  181. addUsr(name, passwd, perms)
  182. save(users,users)
  183. print("User created!")
  184. end
  185. ----------------------------------------------------------
  186. local function removeUser(usr)
  187. -- Code here...
  188. users[usr].password = nil
  189. users[usr].permissions = nil
  190. users[usr] = nil
  191. end
  192. ----------------------------------------------------------
  193. local function removeUser_CLI()
  194. -- Code here...
  195. term.clear()
  196. term.setCursorPos(1, 1)
  197. print("User removal system")
  198. print("Please type the name of the user you want to remove")
  199. local uName = read()
  200. removeUser(uName)
  201. print("User removed!")
  202. end
  203. ----------------------------------------------------------
  204. local function restart()
  205. os.startTimer(delay)
  206. while true do
  207. local evt, p1, p2, p3, p4, p5 = os.pullEvent()
  208. if evt == "timer" then
  209. break
  210. elseif evt == "modem_message" then
  211. print(p2..":"..p4)
  212. end
  213. end
  214. end
  215. ----------------------------------------------------------
  216. local function main_CLI()
  217. -- Code here...
  218. term.clear()
  219. term.setCursorPos(1, 1)
  220. print("CCMC CLI")
  221. print("Type help for more info.")
  222. local cmd = read()
  223. if cmd == "help" then
  224. print("All commands are lowercase.")
  225. for _, v in pairs(commands) do
  226. print(_..":"..v)
  227. end
  228. elseif cmd == "exit" or cmd == "quit" then
  229. return
  230. end
  231. if cmd == "launch missile" then
  232. missile_launch()
  233. end
  234. if cmd == "add user" then
  235. checkUsrNamePerm()
  236. addUser_CLI()
  237. elseif cmd == "remove user" then
  238. checkUsrNamePerm()
  239. removeUser_CLI()
  240. end
  241. restart()
  242. end
  243. ----------------------------------------------------------
  244.  
  245. startup()
  246. checkUNamePasswd()
  247. main_CLI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement