Advertisement
IAmCiel_

Untitled

Feb 26th, 2025 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 KB | None | 0 0
  1. -- Secure Terminal for ComputerCraft 1.12.2
  2. -- Features: Login Interface, Door Control with Confirmation, Mouse Input
  3.  
  4. local doorSide = "bottom"  -- Change to where the redstone signal is sent
  5. local resetTime = 5 * 60  -- Time in seconds before terminal resets
  6. local idleTime = 120  -- Time in seconds before auto-reset due to inactivity
  7. local loggedIn = false
  8. local username = "admin"
  9. local password = "password"
  10. local options = {"Open Door", "Close Door", "Check Access Logs", "Logout"}
  11. local selectedOption = nil
  12.  
  13. -- Function to generate corrupted logs
  14. local function generateCorruptData()
  15.     local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"
  16.     local data = "DATA CORRUPTED\n"
  17.     for i = 1, 10 do
  18.         local line = ""
  19.         for j = 1, math.random(10, 25) do
  20.             line = line .. chars:sub(math.random(1, #chars), math.random(1, #chars))
  21.         end
  22.         data = data .. line .. "\n"
  23.     end
  24.     return data
  25. end
  26.  
  27. -- Function to pulse a bundled cable signal
  28. local function pulseBundledSignal(color)
  29.     for i = 1, 8 do
  30.         redstone.setBundledOutput(doorSide, color)
  31.         sleep(0.2)
  32.         redstone.setBundledOutput(doorSide, 0)
  33.         sleep(0.2)
  34.     end
  35. end
  36.  
  37. -- Function to draw the login screen
  38. local function drawLoginScreen()
  39.     term.clear()
  40.     term.setCursorPos(1, 1)
  41.     print("== SECURE TERMINAL LOGIN ==")
  42.     term.setCursorPos(1, 3)
  43.     write("Username: ")
  44.     local inputUsername = read()
  45.     term.setCursorPos(1, 4)
  46.     write("Password: ")
  47.     local inputPassword = read("*")
  48.  
  49.     if inputUsername == username and inputPassword == password then
  50.         loggedIn = true
  51.         print("Login successful!")
  52.         sleep(1)
  53.     else
  54.         print("Login failed. Access denied.")
  55.         sleep(2)
  56.     end
  57. end
  58.  
  59. -- Function to draw the main menu
  60. local function drawMenu()
  61.     term.clear()
  62.     term.setCursorPos(1, 1)
  63.     print("== SECURE TERMINAL MENU ==")
  64.     for i, option in ipairs(options) do
  65.         if selectedOption == i then
  66.             term.setTextColor(colors.yellow)
  67.             term.setBackgroundColor(colors.gray)
  68.         else
  69.             term.setTextColor(colors.white)
  70.             term.setBackgroundColor(colors.black)
  71.         end
  72.         term.setCursorPos(2, i + 2)
  73.         term.clearLine()
  74.         term.write(option)
  75.     end
  76.     term.setTextColor(colors.white)
  77.     term.setBackgroundColor(colors.black)
  78. end
  79.  
  80. -- Function to handle mouse input for menu selection
  81. local function handleMouseInput()
  82.     while true do
  83.         local event, button, x, y = os.pullEvent("mouse_click")
  84.         if button == 1 then -- Left click
  85.             local optionIndex = y - 2
  86.             if optionIndex >= 1 and optionIndex <= #options then
  87.                 selectedOption = optionIndex
  88.                 drawMenu()
  89.                 return
  90.             end
  91.         end
  92.     end
  93. end
  94.  
  95. -- Function to handle menu selection
  96. local function handleMenuSelection()
  97.     while loggedIn do
  98.         drawMenu()
  99.         handleMouseInput()
  100.         if selectedOption == 1 then
  101.             term.clear()
  102.             print("Are you sure you want to open the door? (y/n)")
  103.             local confirm = read():lower()
  104.             if confirm == "y" then
  105.                 print("Opening Door...")
  106.                 pulseBundledSignal(colors.green)
  107.             end
  108.             drawMenu()
  109.         elseif selectedOption == 2 then
  110.             term.clear()
  111.             print("Are you sure you want to close the door? (y/n)")
  112.             local confirm = read():lower()
  113.             if confirm == "y" then
  114.                 print("Closing Door...")
  115.                 pulseBundledSignal(colors.red)
  116.             end
  117.             drawMenu()
  118.         elseif selectedOption == 3 then
  119.             term.clear()
  120.             print("Retrieving logs...")
  121.             sleep(1)
  122.             print(generateCorruptData())
  123.             sleep(4)
  124.             drawMenu()
  125.         elseif selectedOption == 4 then
  126.             term.clear()
  127.             print("Logging Out...")
  128.             sleep(1)
  129.             loggedIn = false
  130.         end
  131.         selectedOption = nil
  132.     end
  133. end
  134.  
  135. -- Function to reset the terminal after X minutes
  136. local function resetTimer()
  137.     sleep(resetTime)
  138.     loggedIn = false
  139.     print("System reset. Login required again.")
  140. end
  141.  
  142. -- Main execution
  143. while true do
  144.     if not loggedIn then
  145.         drawLoginScreen()
  146.         if loggedIn then
  147.             parallel.waitForAny(handleMenuSelection, resetTimer)
  148.         else
  149.             sleep(5)
  150.         end
  151.     else
  152.         handleMenuSelection()
  153.     end
  154. end
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement