Advertisement
LuaCrawler

ICBM-control-panel

Mar 5th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.30 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 bar = LoadBar.init(LoadBar.ASCII_BAR_ONLY, nil, 10, 30, 14, nil, nil, nil, nil )
  137. local function doStuff()
  138.     bar:setMessage( "Loading..." )
  139.     for i = 1, 9 do
  140.         sleep(0.5)
  141.         bar:triggerUpdate("Initializing component("..(bar:getCurrentProgress()+1).."/9)")
  142.     end
  143.     bar:triggerUpdate("Done!")
  144. end
  145. ----------------------------------------------------------
  146. local function doBar()
  147.     bar:run( true )
  148. end
  149. ----------------------------------------------------------
  150. local function missile_launch()
  151.     -- Code here...
  152.      os.loadAPI("/lib/LoadBar")
  153.    
  154.     -- Run the loading bar
  155.     parallel.waitForAll( doBar, doStuff )
  156.     term.clear()
  157.     term.setBackgroundColor(colors.gray)
  158.     term.setCursorPos(1, 1)
  159.     for i = 1, 19 do
  160.         print("                                                      ")
  161.     end
  162.     term.setTextColor(colors.yellow)
  163.     term.setCursorPos(1, 1)
  164.     textutils.slowPrint("Remote missile launch system" )
  165.     textutils.slowPrint("Usage: launch <label>", 50)
  166.     term.setTextColor(colors.white)
  167.     lSilo = read()
  168.     print("Confirm launch![Y/N]")
  169.     _, char = os.pullEvent("char")
  170.     if char == "y" then
  171.         modem.transmit(server, rChan, lSilo)
  172.     elseif char == "n" then
  173.         do main_CLI() end
  174.     end
  175. end
  176. ----------------------------------------------------------
  177. local function addUser_CLI()
  178.     -- Code here...
  179.     term.clear()
  180.     term.setCursorPos(1, 1)
  181.     print("User addition system")
  182.     print("Press enter to continue")
  183.     os.pullEvent("key")
  184.     textutils.slowPrint("What should the user's username be?", 50)
  185.     local name = read()
  186.     print("What would you like "..name.."'s password to be?")
  187.     local passwd = read()
  188.     print("What permissions should user "..name.." have?")
  189.     local perms = read()
  190.     for i = 1,10 do
  191.         term.setCursorPos(18, 30)
  192.         sleep(.3)
  193.     end
  194.     addUsr(name, passwd, perms)
  195.     save(users,users)
  196.     print("User created!")
  197. end
  198. ----------------------------------------------------------
  199. local function removeUser(usr)
  200.     -- Code here...
  201.     users[usr].password = nil
  202.     users[usr].permissions = nil
  203.     users[usr] = nil
  204. end
  205. ----------------------------------------------------------
  206. local function removeUser_CLI()
  207.     -- Code here...
  208.     term.clear()
  209.     term.setCursorPos(1, 1)
  210.     print("User removal system")
  211.     print("Please type the name of the user you want to remove")
  212.     local uName = read()
  213.     removeUser(uName)
  214.     print("User removed!")
  215. end
  216. ---------------------------------------------------------
  217. local function checkLoadbarLib()
  218.     f = fs.exists("/lib/loadBar")
  219.     if f == true then
  220.     break
  221.     elseif f == false then
  222.     fs.makeDir("/lib")
  223.     shell.run("pastebin","get","zeG34tu6","LoadBar")
  224.     fs.move("LoadBar", "/lib/LoadBar")
  225.     end
  226. end
  227. checkLoadbarLib()
  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