Guest User

Untitled

a guest
Jan 29th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ICBM Launch Server]]--
  2.  
  3. size = {term.getSize()}
  4.  
  5. users = {"Splingold"}
  6. passwords = {"1789"}
  7.  
  8. local silos = {}
  9.  
  10. --[[Functions]]--
  11.  
  12. rednet.open("back")
  13. local waitDelay = 2
  14.  
  15. local function red()
  16. term.setBackgroundColor(colors.red)
  17. print("                                                          ")
  18. term.setBackgroundColor(colors.blue)
  19. end
  20.  
  21. local function findSilos()
  22.     rednet.broadcast("ping silo")
  23.  
  24.   local timerID = os.startTimer(waitDelay)
  25.  
  26.   while true do
  27.     event, id, msg, distance = os.pullEvent()
  28.    
  29.     if event == "rednet_message" and msg == "pong" then
  30.       table.insert(silos, id)
  31.       timerID = os.startTimer(waitDelay)
  32.     elseif event == "timer" and id == timerID then
  33.        return
  34.     end
  35.   end
  36. end
  37.  
  38. local curSilo = 1
  39. local function launch(count, x, y, z)
  40.   local msg = {x = x, y = y, z = z}
  41.     print("launching Missiles At " .. x .. ", " .. y .. ", " .. z)
  42.       for i = 1, count do
  43.         rednet.send(silos[curSilo], msg)
  44.           curSilo = (curSilo == #silos) and 1 or (curSilo + 1)
  45.             sleep(5)
  46.       end
  47. end
  48.  
  49. local function printSilos()
  50.   term.clear()
  51.   term.setCursorPos(1,1)
  52.     print("              [Detected silos]       ")
  53.     for k, v in ipairs(silos) do
  54.     print("              silo #" .. k .. " id = "..v)
  55.   end
  56. end
  57.  
  58. function drawBoxPos(x,y,x1,y1)
  59.   cy = y
  60.   term.setCursorPos(x,y)
  61.   for i = 1,(y1-y)+1 do
  62.     for i = 1,(x1-x) do
  63.       term.write(" ")
  64.     end
  65.     cy = cy+1
  66.     term.setCursorPos(x,cy)
  67.   end
  68. end
  69.  
  70. function reset()
  71.   term.setBackgroundColor(colors.lightGray)
  72.   term.setCursorPos(2,12)
  73.   for i = 1,size[1]-4 do
  74.     term.write(" ")
  75.   end
  76.   term.setTextColor(colors.gray)
  77.   term.setBackgroundColor(colors.gray)
  78.   drawBoxPos(9,8,size[1]-1,8)
  79.   term.setBackgroundColor(colors.lightGray)
  80.   term.setCursorPos(3,8)
  81.   print("USER:")
  82.   term.setBackgroundColor(colors.gray)
  83.   drawBoxPos(9,10,size[1]-1,10)
  84.   term.setBackgroundColor(colors.lightGray)
  85.   term.setCursorPos(3,10)
  86.   print("PASS:")
  87. end
  88.  
  89. function loginScreen()
  90.   term.setBackgroundColor(colors.white)
  91.   term.clear()
  92.   term.setBackgroundColor(colors.lightGray)
  93.   drawBoxPos(2,2,size[1],size[2]-1)
  94.   term.setCursorPos(1,size[2]-7)
  95.   term.setBackgroundColor(colors.gray)
  96.   drawBoxPos(((size[1]/2)-10)-1,2,((size[1]/2)+13)-1,4)
  97.   term.setBackgroundColor(colors.red)
  98.   drawBoxPos((size[1]/2)-10,1,(size[1]/2)+13,3)
  99.   term.setTextColor(colors.gray)
  100.   str = "Skynet Mainframe"
  101.   term.setCursorPos((size[1]/2)-(#str/2) +1,2)
  102.   term.write(str)
  103.   term.setBackgroundColor(colors.lightGray)
  104.   str = "Enter Authentication Credentials"
  105.   term.setCursorPos((size[1]/2)-(#str/2) +1,6)
  106.   term.write(str)
  107.   term.setBackgroundColor(colors.gray)
  108.   drawBoxPos(9,8,size[1]-1,8)
  109.   term.setBackgroundColor(colors.lightGray)
  110.   term.setCursorPos(3,8)
  111.   print("USER:")
  112.   term.setBackgroundColor(colors.gray)
  113.   drawBoxPos(9,10,size[1]-1,10)
  114.   term.setBackgroundColor(colors.lightGray)
  115.   term.setCursorPos(3,10)
  116.   print("PASS:")
  117.   term.setBackgroundColor(colors.red)
  118.   drawBoxPos(((size[1]/2)-9)-1,13,((size[1]/2)+13)-1,15)
  119.   term.setTextColor(colors.gray)
  120.   str = "Login to Skynet!"
  121.   term.setCursorPos((size[1]/2)-(#str/2) +1,14)
  122.   term.write(str)
  123.   term.setBackgroundColor(colors.lightGray)
  124.   str = "(c) 2016 Skynet - Build. Innovate. Conquer"
  125.   term.setCursorPos((size[1]/2)-(#str/2) +1,size[2]-2)
  126.   term.write(str)
  127.   while true do
  128.     evnt = {os.pullEvent()}
  129.     if evnt[1] == "mouse_click" then
  130.       if evnt[3] > 8 and evnt[3] < size[1]-1 and evnt[4] == 8 then
  131.         term.setBackgroundColor(colors.gray)
  132.         term.setTextColor(colors.lightGray)
  133.         term.setCursorPos(9,8)
  134.         username = read()
  135.       elseif evnt[3] > 8 and evnt[3] < size[1]-1 and evnt[4] == 10 then
  136.         term.setBackgroundColor(colors.gray)
  137.         term.setTextColor(colors.lightGray)
  138.         term.setCursorPos(9,10)
  139.         password = read("*")
  140.       elseif evnt[3] > ((size[1]/2)-9)-2 and evnt[3] < ((size[1]/2)+13)-2 and evnt[4] > 12 and evnt[4] < 16 then
  141.         if username ~= nil and password ~= nil then
  142.           loggedin = false
  143.           for i = 1,#users do
  144.             if username == users[i] then
  145.               if password == passwords[i] then
  146.                 term.setTextColor(colors.lime)
  147.                 term.setBackgroundColor(colors.lightGray)
  148.                 str = "Access Granted. Welcome back, "..username
  149.                 term.setCursorPos((size[1]/2)-(#str/2) +1,12)
  150.                 term.write(str)
  151.                 loggedin = true
  152.                 sleep(3)
  153.               end
  154.             end
  155.           end
  156.           if loggedin then
  157. term.setBackgroundColor(colors.blue)
  158. term.clear()
  159. findSilos()
  160. term.setCursorPos(1,1)
  161. term.setBackgroundColor(colors.blue)
  162. term.clear()
  163.   printSilos()
  164. red()
  165. write("Enter Launch Verification Code: ")
  166.   input  = read()
  167. red()
  168.   term.setBackgroundColor(colors.blue)
  169.   if input == "exit" then
  170.    break
  171.     elseif input == "Xplode" then
  172.      while true do
  173.      sleep(1)
  174. red()
  175.        write("Launch Confirmation [Yes/No]: ")
  176.         input2 = read()
  177.        if input2 == "No" then
  178.       os.reboot()
  179.    elseif input2 == "Yes" then
  180.  local count, x, y, z
  181.   while not (type(count) == "number" and type(x) == "number" and type(y) == "number" and type(z) == "number") do
  182. red()
  183. print("      [Target Selection]       ")
  184. red()
  185. term.setBackgroundColor(colors.blue)
  186.  write(" Missile Count: ")
  187.       count = tonumber(read())
  188.       print("Coordinates:")
  189.       write("X: ")
  190.       x = tonumber(read())
  191.       write("Y: ")
  192.       y = tonumber(read())
  193.       write("Z: ")
  194.       z = tonumber(read())
  195. sleep(1)
  196. print("Target Selection Complete:")
  197.  red()
  198. term.setBackgroundColor(colors.blue)
  199.    print("Launching at: "..x..","..y..","..z)
  200.    print("Launching Missiles -T Minus 10 Seconds.")
  201.    sleep(1)
  202. red()
  203.    
  204. sleep(1)
  205. write("  Abort [Yes/No]: ")
  206. local abort = read()
  207. if abort == "Yes" then
  208. write("Warheads Disarmed Successfully")
  209. sleep(1)
  210. write("Session Expired, renewing login:")
  211. sleep(2)
  212. os.reboot()
  213. elseif abort == "No" then
  214.     end
  215.     launch(count, x, y, z)
  216.     sleep(10)
  217.     os.reboot()
  218. end
  219.           elseif loggedin == false then
  220.             term.setTextColor(colors.red)
  221.             term.setBackgroundColor(colors.lightGray)
  222.             str = "Username or Password incorrect."
  223.             term.setCursorPos((size[1]/2)-(#str/2) +1,12)
  224.             term.write(str)
  225.             sleep(2)
  226.             reset()
  227.           end
  228.           end
  229.         elseif username == nil or password == nil then
  230.           reset()
  231.           term.setTextColor(colors.red)
  232.           term.setBackgroundColor(colors.lightGray)
  233.           str = "Username or Password not recognized."
  234.           term.setCursorPos((size[1]/2)-(#str/2) +1,12)
  235.           term.write(str)
  236.           sleep(2)
  237.  
  238. printer.newPage()
  239. printer.setPageTitle(" ###Launch Report###")
  240. printer.setCursorPos(1, 1)
  241. printer.write("    ###Launch Report###")
  242. printer.setCursorPos(1, 3)
  243. printer.write(" "..count.." Missile(s) launched")
  244. printer.setCursorPos(1, 4)
  245. printer.write("Target: "..x..","..y..","..z)
  246. printer.setCursorPos(1, 5)
  247. printer.write("User logged: "..users)
  248. printer.endPage()
  249.           reset()
  250.         end
  251.       end
  252.     end
  253.   end
  254. end
  255. end
  256. printer.newPage()
  257. printer.setPageTitle("###Launch Report###")
  258. printer.setCursorPos(1, 1)
  259. printer.write("###Launch Report###")
  260. printer.setCursorPos(1, 2)
  261. printer.write("..count.. Missile(s) launched")
  262. printer.setCursorPos(1, 3)
  263. printer.write("Target: ..x.. , ..y.. , ..z..")
  264. printer.endPage()
  265.  
  266. end
  267.  
  268. local printer = peripheral.wrap("right")
  269. loginScreen()
  270. term.setBackgroundColor(colors.black)
  271. term.clear()
  272. term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment