Guest User

Untitled

a guest
Sep 16th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.54 KB | None | 0 0
  1. local w, h = term.getSize()
  2.  
  3. function usercp(user, pass)
  4. options = {[0] = "Log out", [1] = "Change Password", [2] = "Back to Reactor Access Panel"}
  5. selected = 0
  6. maxoptions = 2
  7. checkingkey = true
  8. while checkingkey do
  9.         term.clear()
  10.         term.setCursorPos(1,1)
  11.         i=0
  12.         repeat
  13.         write("-")
  14.         i=i+1
  15.         until i == (w-1)
  16.         workstring = "NeXTBattle User CP"
  17.         term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  18.         write(workstring)
  19.         term.setCursorPos(1,3)
  20.         i=0
  21.         repeat
  22.         write("-")
  23.         i=i+1
  24.         until i == (w-1)
  25.         term.setCursorPos(1,16)
  26.         i=0
  27.         repeat
  28.         write("-")
  29.         i=i+1
  30.         until i == (w-1)
  31.         workstring = "Welcome to the User CP, "..user.."!"
  32.         term.setCursorPos(((w/2)-(string.len(workstring)/2)),17)
  33.         write(workstring)
  34.         term.setCursorPos(1,18)
  35.         i=0
  36.         repeat
  37.         write("-")
  38.         i=i+1
  39.         until i == (w-1)
  40.         workstring = "[--> "..options[selected].." <--]"
  41.         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2))
  42.         write(workstring)
  43.         subselect = 0
  44.         if selected == 0 then subselect = maxoptions else subselect = selected-1 end
  45.         workstring = options[subselect]
  46.         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  47.         write(workstring)
  48.         if selected == maxoptions then subselect = 0 else subselect = selected+1 end
  49.         workstring = options[subselect]
  50.         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)+2)
  51.         write(workstring)
  52.         local sEvent, param = os.pullEvent("key")
  53.         if(sEvent == "key") then
  54.             if(param == 200) then
  55.                 if selected == 0 then selected = maxoptions else selected = selected-1 end
  56.             end
  57.             if(param == 208) then
  58.                 if selected == maxoptions then selected = 0 else selected = selected+1 end
  59.             end
  60.             if(param == 28) then
  61.                 if selected == 2 then
  62.                     checkingkey = false;
  63.                     mainmenu(user, pass)
  64.                 end
  65.                 if selected == 1 then
  66.                     term.clear()
  67.                     term.setCursorPos(1,1)
  68.                     i=0
  69.                     repeat
  70.                     write("-")
  71.                     i=i+1
  72.                     until i == (w-1)
  73.                     workstring = "NeXTBattle User CP"
  74.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  75.                     write(workstring)
  76.                     term.setCursorPos(1,3)
  77.                     i=0
  78.                     repeat
  79.                     write("-")
  80.                     i=i+1
  81.                     until i == (w-1)
  82.                     workstring = "Please enter your current password:"
  83.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  84.                     write(workstring)
  85.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-1)
  86.                     currentpass = read("*")
  87.                     if currentpass ~= pass then
  88.                         term.clear()
  89.                         term.setCursorPos(1,1)
  90.                         i=0
  91.                         repeat
  92.                         write("-")
  93.                         i=i+1
  94.                         until i == (w-1)
  95.                         workstring = "NeXTBattle User CP"
  96.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  97.                         write(workstring)
  98.                         term.setCursorPos(1,3)
  99.                         i=0
  100.                         repeat
  101.                         write("-")
  102.                         i=i+1
  103.                         until i == (w-1)
  104.                         workstring = "Incorrect Password!"
  105.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  106.                         write(workstring)
  107.                         sleep(2)
  108.                     else
  109.                         term.clear()
  110.                         term.setCursorPos(1,1)
  111.                         i=0
  112.                         repeat
  113.                         write("-")
  114.                         i=i+1
  115.                         until i == (w-1)
  116.                         workstring = "NeXTBattle User CP"
  117.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  118.                         write(workstring)
  119.                         term.setCursorPos(1,3)
  120.                         i=0
  121.                         repeat
  122.                         write("-")
  123.                         i=i+1
  124.                         until i == (w-1)
  125.                         workstring = "Please enter your new password:"
  126.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  127.                         write(workstring)
  128.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-1)
  129.                         newpass = read("*")
  130.                         term.clear()
  131.                         term.setCursorPos(1,1)
  132.                         i=0
  133.                         repeat
  134.                         write("-")
  135.                         i=i+1
  136.                         until i == (w-1)
  137.                         workstring = "NeXTBattle User CP"
  138.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  139.                         write(workstring)
  140.                         term.setCursorPos(1,3)
  141.                         i=0
  142.                         repeat
  143.                         write("-")
  144.                         i=i+1
  145.                         until i == (w-1)
  146.                         workstring = "Please confirm your new password:"
  147.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  148.                         write(workstring)
  149.                         term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-1)
  150.                         newconfpass = read("*")
  151.                         if newconfpass == newpass then
  152.                             rednet.send(56, "~"..user.."~"..newpass)
  153.                             id, msg = rednet.receive()
  154.                             if msg == "ok" then
  155.                                 term.clear()
  156.                                 term.setCursorPos(1,1)
  157.                                 i=0
  158.                                 repeat
  159.                                 write("-")
  160.                                 i=i+1
  161.                                 until i == (w-1)
  162.                                 workstring = "NeXTBattle User CP"
  163.                                 term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  164.                                 write(workstring)
  165.                                 term.setCursorPos(1,3)
  166.                                 i=0
  167.                                 repeat
  168.                                 write("-")
  169.                                 i=i+1
  170.                                 until i == (w-1)
  171.                                 workstring = "Your password has been changed!"
  172.                                 term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  173.                                 write(workstring)
  174.                                 sleep(2)
  175.                             else
  176.                                 term.clear()
  177.                                 term.setCursorPos(1,1)
  178.                                 i=0
  179.                                 repeat
  180.                                 write("-")
  181.                                 i=i+1
  182.                                 until i == (w-1)
  183.                                 workstring = "NeXTBattle User CP"
  184.                                 term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  185.                                 write(workstring)
  186.                                 term.setCursorPos(1,3)
  187.                                 i=0
  188.                                 repeat
  189.                                 write("-")
  190.                                 i=i+1
  191.                                 until i == (w-1)
  192.                                 workstring = "An error occurred!"
  193.                                 term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  194.                                 write(workstring)
  195.                                 sleep(2)
  196.                             end
  197.                         else
  198.                             term.clear()
  199.                             term.setCursorPos(1,1)
  200.                             i=0
  201.                             repeat
  202.                             write("-")
  203.                             i=i+1
  204.                             until i == (w-1)
  205.                             workstring = "NeXTBattle User CP"
  206.                             term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  207.                             write(workstring)
  208.                             term.setCursorPos(1,3)
  209.                             i=0
  210.                             repeat
  211.                             write("-")
  212.                             i=i+1
  213.                             until i == (w-1)
  214.                             workstring = "The passwords didn't match!"
  215.                             term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  216.                             write(workstring)
  217.                             sleep(2)
  218.                         end
  219.                     end
  220.                     selected = 0
  221.                 end
  222.                 if selected == 0 then
  223.                     term.clear()
  224.                     term.setCursorPos(1,1)
  225.                     i=0
  226.                     repeat
  227.                     write("-")
  228.                     i=i+1
  229.                     until i == (w-1)
  230.                     workstring = "NeXTBattle Nuclear Access"
  231.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  232.                     write(workstring)
  233.                     term.setCursorPos(1,3)
  234.                     i=0
  235.                     repeat
  236.                     write("-")
  237.                     i=i+1
  238.                     until i == (w-1)
  239.                     workstring = "Logging out..."
  240.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  241.                     write(workstring)
  242.                     sleep(1)
  243.                     os.reboot()
  244.                 end
  245.             end
  246.         end
  247.         sleep(0.2)
  248.     end
  249. end
  250.  
  251. function mainmenu(user, pass)
  252. options = {[0] = "Log out", [1] = "Open Reactor Control Room", [2] = "Open Reactor Maintenance Access", [3] = "Open EU Storage Room", [4] = "Open Server Center Access"}
  253. maxoptions = 4
  254. selected = 0
  255. checkingkey = true
  256. while checkingkey do
  257.    
  258.     term.clear()
  259.     term.setCursorPos(1,1)
  260.     i=0
  261.     repeat
  262.     write("-")
  263.     i=i+1
  264.     until i == (w-1)
  265.     workstring = "NeXTBattle Nuclear Access"
  266.     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  267.     write(workstring)
  268.     term.setCursorPos(1,3)
  269.     i=0
  270.     repeat
  271.     write("-")
  272.     i=i+1
  273.     until i == (w-1)
  274.     term.setCursorPos(1,16)
  275.     i=0
  276.     repeat
  277.     write("-")
  278.     i=i+1
  279.     until i == (w-1)
  280.     workstring = "Successfully logged in"
  281.     term.setCursorPos(1,17)
  282.     write(workstring)
  283.     workstring = "U - UserCP"
  284.     term.setCursorPos(w-string.len(workstring),17)
  285.     write(workstring)
  286.     term.setCursorPos(1,18)
  287.     i=0
  288.     repeat
  289.     write("-")
  290.     i=i+1
  291.     until i == (w-1)
  292.     workstring = "[--> "..options[selected].." <--]"
  293.     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2))
  294.     write(workstring)
  295.     subselect = 0
  296.     if selected == 0 then subselect = maxoptions else subselect = selected-1 end
  297.     workstring = options[subselect]
  298.     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  299.     write(workstring)
  300.     if selected == maxoptions then subselect = 0 else subselect = selected+1 end
  301.     workstring = options[subselect]
  302.     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)+2)
  303.     write(workstring)
  304.     local sEvent, param = os.pullEvent("key")
  305.         if(sEvent == "key") then
  306.             if(param == 22) then
  307.                 checkingkey = false
  308.                 usercp(user, pass)
  309.             end
  310.             if(param == 200) then
  311.                 if selected == 0 then selected = maxoptions else selected = selected-1 end
  312.             end
  313.             if(param == 208) then
  314.                 if selected == maxoptions then selected = 0 else selected = selected+1 end
  315.             end
  316.             if(param == 28) then
  317.                 if selected == 1 then
  318.                     term.clear()
  319.                     term.setCursorPos(1,1)
  320.                     i=0
  321.                     repeat
  322.                     write("-")
  323.                     i=i+1
  324.                     until i == (w-1)
  325.                     workstring = "NeXTBattle Nuclear Access"
  326.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  327.                     write(workstring)
  328.                     term.setCursorPos(1,3)
  329.                     i=0
  330.                     repeat
  331.                     write("-")
  332.                     i=i+1
  333.                     until i == (w-1)
  334.                     workstring = "Opening the Reactor Control Room..."
  335.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  336.                     write(workstring)
  337.                     rednet.send(25, "L1")
  338.                     rednet.receive()
  339.                     sleep(5)
  340.                     rednet.send(25, "L1")
  341.                     rednet.receive()
  342.                     selected = 0
  343.                 end
  344.                 if selected == 2 then
  345.                     term.clear()
  346.                     term.setCursorPos(1,1)
  347.                     i=0
  348.                     repeat
  349.                     write("-")
  350.                     i=i+1
  351.                     until i == (w-1)
  352.                     workstring = "NeXTBattle Nuclear Access"
  353.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  354.                     write(workstring)
  355.                     term.setCursorPos(1,3)
  356.                     i=0
  357.                     repeat
  358.                     write("-")
  359.                     i=i+1
  360.                     until i == (w-1)
  361.                     workstring = "Opening the Reactor Maintenance Access..."
  362.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  363.                     write(workstring)
  364.                     rednet.send(25, "L4")
  365.                     rednet.receive()
  366.                     sleep(5)
  367.                     rednet.send(25, "L4")
  368.                     rednet.receive()
  369.                     selected = 0
  370.                 end
  371.                 if selected == 3 then
  372.                     term.clear()
  373.                     term.setCursorPos(1,1)
  374.                     i=0
  375.                     repeat
  376.                     write("-")
  377.                     i=i+1
  378.                     until i == (w-1)
  379.                     workstring = "NeXTBattle Nuclear Access"
  380.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  381.                     write(workstring)
  382.                     term.setCursorPos(1,3)
  383.                     i=0
  384.                     repeat
  385.                     write("-")
  386.                     i=i+1
  387.                     until i == (w-1)
  388.                     workstring = "Opening the EU Storage Area..."
  389.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  390.                     write(workstring)
  391.                     rednet.send(25, "L2")
  392.                     rednet.receive()
  393.                     sleep(5)
  394.                     rednet.send(25, "L2")
  395.                     rednet.receive()
  396.                     selected = 0
  397.                 end
  398.                 if selected == 4 then
  399.                     term.clear()
  400.                     term.setCursorPos(1,1)
  401.                     i=0
  402.                     repeat
  403.                     write("-")
  404.                     i=i+1
  405.                     until i == (w-1)
  406.                     workstring = "NeXTBattle Nuclear Access"
  407.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  408.                     write(workstring)
  409.                     term.setCursorPos(1,3)
  410.                     i=0
  411.                     repeat
  412.                     write("-")
  413.                     i=i+1
  414.                     until i == (w-1)
  415.                     workstring = "Opening the Server Center Access..."
  416.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  417.                     write(workstring)
  418.                     rednet.send(25, "L8")
  419.                     rednet.receive()
  420.                     sleep(5)
  421.                     rednet.send(25, "L8")
  422.                     rednet.receive()
  423.                     selected = 0
  424.                 end
  425.                 if selected == 0 then
  426.                     term.clear()
  427.                     term.setCursorPos(1,1)
  428.                     i=0
  429.                     repeat
  430.                     write("-")
  431.                     i=i+1
  432.                     until i == (w-1)
  433.                     workstring = "NeXTBattle Nuclear Access"
  434.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  435.                     write(workstring)
  436.                     term.setCursorPos(1,3)
  437.                     i=0
  438.                     repeat
  439.                     write("-")
  440.                     i=i+1
  441.                     until i == (w-1)
  442.                     workstring = "Logging out..."
  443.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  444.                     write(workstring)
  445.                     sleep(1)
  446.                     os.reboot()
  447.                 end
  448.             end
  449.         end
  450.     sleep(0.2)
  451. end
  452.  
  453. end
  454.  
  455. term.clear()
  456. term.setCursorPos(1,1)
  457. i=0
  458. repeat
  459. write("-")
  460. i=i+1
  461. until i == (w-1)
  462. workstring = "NeXTBattle Nuclear Access"
  463. term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  464. write(workstring)
  465. term.setCursorPos(1,3)
  466. i=0
  467. repeat
  468. write("-")
  469. i=i+1
  470. until i == (w-1)
  471. term.setCursorPos(1,16)
  472. i=0
  473. repeat
  474. write("-")
  475. i=i+1
  476. until i == (w-1)
  477. workstring = "Please login for reactor access"
  478. term.setCursorPos(((w/2)-(string.len(workstring)/2)),17)
  479. write(workstring)
  480. term.setCursorPos(1,18)
  481. i=0
  482. repeat
  483. write("-")
  484. i=i+1
  485. until i == (w-1)
  486. workstring = "Please enter your username:"
  487. term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  488. write(workstring)
  489. term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-1)
  490. user = read()
  491. term.clear()
  492. term.setCursorPos(1,1)
  493. local w, h = term.getSize()
  494. i=0
  495. repeat
  496. write("-")
  497. i=i+1
  498. until i == (w-1)
  499. workstring = "NeXTBattle Nuclear Access"
  500. term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  501. write(workstring)
  502. term.setCursorPos(1,3)
  503. i=0
  504. repeat
  505. write("-")
  506. i=i+1
  507. until i == (w-1)
  508. term.setCursorPos(1,16)
  509. i=0
  510. repeat
  511. write("-")
  512. i=i+1
  513. until i == (w-1)
  514. workstring = "Please login for reactor access"
  515. term.setCursorPos(((w/2)-(string.len(workstring)/2)),17)
  516. write(workstring)
  517. term.setCursorPos(1,18)
  518. i=0
  519. repeat
  520. write("-")
  521. i=i+1
  522. until i == (w-1)
  523. workstring = "Please enter your password:"
  524. term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  525. write(workstring)
  526. term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-1)
  527. pass = read("*")
  528. rednet.open("back")
  529. rednet.send(56, user.."~"..pass)
  530. id, msg = rednet.receive()
  531. if id==56 and (msg=="true" or msg=="root") then
  532.  
  533.                     term.clear()
  534.                     term.setCursorPos(1,1)
  535.                     i=0
  536.                     repeat
  537.                     write("-")
  538.                     i=i+1
  539.                     until i == (w-1)
  540.                     workstring = "NeXTBattle Nuclear Access"
  541.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  542.                     write(workstring)
  543.                     term.setCursorPos(1,3)
  544.                     i=0
  545.                     repeat
  546.                     write("-")
  547.                     i=i+1
  548.                     until i == (w-1)
  549.                     workstring = "Welcome "..user.."!"
  550.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  551.                     write(workstring)
  552.                     workstring = "Logging in..."
  553.                     term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-1)
  554.                     write(workstring)
  555.                     sleep(1)
  556.                     mainmenu(user, pass)
  557. else
  558. term.clear()
  559. term.setCursorPos(1,1)
  560. i=0
  561. repeat
  562. write("-")
  563. i=i+1
  564. until i == (w-1)
  565. workstring = "NeXTBattle Nuclear Access"
  566. term.setCursorPos(((w/2)-(string.len(workstring)/2)),2)
  567. write(workstring)
  568. term.setCursorPos(1,3)
  569. i=0
  570. repeat
  571. write("-")
  572. i=i+1
  573. until i == (w-1)
  574. if msg == nil then workstring = "Could not connect to the login server!" else workstring = "Invalid Details!" end
  575. term.setCursorPos(((w/2)-(string.len(workstring)/2)),(h/2)-2)
  576. write(workstring)
  577. sleep(3)
  578. os.reboot()
  579. end
Add Comment
Please, Sign In to add comment