Advertisement
Guest User

Untitled

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