Advertisement
Guest User

Untitled

a guest
Jul 14th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 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.  
  137. ---------------------------------------------------------
  138. local function checkLoadbarLib()
  139. f = fs.exists("/lib/loadBar")
  140. if f == true then
  141. return false
  142. elseif f == false then
  143. fs.makeDir("/lib")
  144. shell.run("pastebin","get","zeG34tu6","LoadBar")
  145. fs.move("LoadBar", "/lib/LoadBar")
  146. end
  147. end
  148. checkLoadbarLib()
  149. os.loadAPI("/lib/LoadBar")
  150.  
  151.  
  152. ----------------------------------------------------------
  153. local bar = LoadBar.init(LoadBar.ASCII_BAR_ONLY, nil, 10, 30, 14, nil, nil, nil, nil )
  154. local function doStuff()
  155. bar:setMessage( "Loading..." )
  156. for i = 1, 9 do
  157. sleep(0.5)
  158. bar:triggerUpdate("Initializing component("..(bar:getCurrentProgress()+1).."/9)")
  159. end
  160. bar:triggerUpdate("Done!")
  161. end
  162. ----------------------------------------------------------
  163. local function doBar()
  164. bar:run( true )
  165. textutils.slowPrint("Remote missile launch system" )
  166. end
  167. ----------------------------------------------------------
  168. local function missile_launch()
  169. -- Code here...
  170. os.loadAPI("/lib/LoadBar")
  171.  
  172. -- Run the loading bar
  173. parallel.waitForAll( doBar, doStuff )
  174. term.clear()
  175. term.setBackgroundColor(colors.gray)
  176. term.setCursorPos(1, 1)
  177. for i = 1, 19 do
  178. print(" ")
  179. end
  180. term.setTextColor(colors.yellow)
  181. term.setCursorPos(1, 1)
  182. textutils.slowPrint("Remote missile launch system" )
  183. textutils.slowPrint("Usage: launch <label>", 50)
  184. term.setTextColor(colors.white)
  185. lSilo = read()
  186. print("Confirm launch![Y/N]")
  187. _, char = os.pullEvent("char")
  188. if char == "y" then
  189. modem.transmit(server, rChan, lSilo)
  190. elseif char == "n" then
  191. do main_CLI() end
  192. end
  193. end
  194. ----------------------------------------------------------
  195. local function addUser_CLI()
  196. -- Code here...
  197. term.clear()
  198. term.setCursorPos(1, 1)
  199. print("User addition system")
  200. print("Press enter to continue")
  201. os.pullEvent("key")
  202. textutils.slowPrint("What should the user's username be?", 50)
  203. local name = read()
  204. print("What would you like "..name.."'s password to be?")
  205. local passwd = read()
  206. print("What permissions should user "..name.." have?")
  207. local perms = read()
  208. for i = 1,10 do
  209. term.setCursorPos(18, 30)
  210. sleep(.3)
  211. end
  212. addUsr(name, passwd, perms)
  213. save(users,users)
  214. print("User created!")
  215. end
  216. ----------------------------------------------------------
  217. local function removeUser(usr)
  218. -- Code here...
  219. users[usr].password = nil
  220. users[usr].permissions = nil
  221. users[usr] = nil
  222. end
  223. ----------------------------------------------------------
  224. local function removeUser_CLI()
  225. -- Code here...
  226. term.clear()
  227. term.setCursorPos(1, 1)
  228. print("User removal system")
  229. print("Please type the name of the user you want to remove")
  230. local uName = read()
  231. removeUser(uName)
  232. print("User removed!")
  233. end
  234. ---------------------------------------------------------
  235.  
  236. ----------------------------------------------------------
  237. local function restart()
  238. os.startTimer(delay)
  239. while true do
  240. local evt, p1, p2, p3, p4, p5 = os.pullEvent()
  241. if evt == "timer" then
  242. break
  243. elseif evt == "modem_message" then
  244. print(p2..":"..p4)
  245. end
  246. end
  247. end
  248. ----------------------------------------------------------
  249. local function main_CLI()
  250. -- Code here...
  251. term.clear()
  252. term.setCursorPos(1, 1)
  253. print("CCMC CLI")
  254. print("Type help for more info.")
  255. local cmd = read()
  256. if cmd == "help" then
  257. print("All commands are lowercase.")
  258. for _, v in pairs(commands) do
  259. print(_..":"..v)
  260. end
  261. elseif cmd == "exit" or cmd == "quit" then
  262. return
  263. end
  264. if cmd == "launch missile" then
  265. missile_launch()
  266. end
  267. if cmd == "add user" then
  268. checkUsrNamePerm()
  269. addUser_CLI()
  270. elseif cmd == "remove user" then
  271. checkUsrNamePerm()
  272. removeUser_CLI()
  273. end
  274. restart()
  275. end
  276. ----------------------------------------------------------
  277.  
  278. startup()
  279. checkUNamePasswd()
  280. main_CLI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement