Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Secure Terminal for ComputerCraft 1.12.2
- -- Features: Login Interface, Door Control with Confirmation, Mouse Input
- local doorSide = "bottom" -- Change to where the redstone signal is sent
- local resetTime = 5 * 60 -- Time in seconds before terminal resets
- local idleTime = 120 -- Time in seconds before auto-reset due to inactivity
- local loggedIn = false
- local username = "admin"
- local password = "password"
- local options = {"Open Door", "Close Door", "Check Access Logs", "Logout"}
- local selectedOption = nil
- -- Function to generate corrupted logs
- local function generateCorruptData()
- local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"
- local data = "DATA CORRUPTED\n"
- for i = 1, 10 do
- local line = ""
- for j = 1, math.random(10, 25) do
- line = line .. chars:sub(math.random(1, #chars), math.random(1, #chars))
- end
- data = data .. line .. "\n"
- end
- return data
- end
- -- Function to pulse a bundled cable signal
- local function pulseBundledSignal(color)
- for i = 1, 8 do
- redstone.setBundledOutput(doorSide, color)
- sleep(0.2)
- redstone.setBundledOutput(doorSide, 0)
- sleep(0.2)
- end
- end
- -- Function to draw the login screen
- local function drawLoginScreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("== SECURE TERMINAL LOGIN ==")
- term.setCursorPos(1, 3)
- write("Username: ")
- local inputUsername = read()
- term.setCursorPos(1, 4)
- write("Password: ")
- local inputPassword = read("*")
- if inputUsername == username and inputPassword == password then
- loggedIn = true
- print("Login successful!")
- sleep(1)
- else
- print("Login failed. Access denied.")
- sleep(2)
- end
- end
- -- Function to draw the main menu
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("== SECURE TERMINAL MENU ==")
- for i, option in ipairs(options) do
- if selectedOption == i then
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.gray)
- else
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- term.setCursorPos(2, i + 2)
- term.clearLine()
- term.write(option)
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- -- Function to handle mouse input for menu selection
- local function handleMouseInput()
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if button == 1 then -- Left click
- local optionIndex = y - 2
- if optionIndex >= 1 and optionIndex <= #options then
- selectedOption = optionIndex
- drawMenu()
- return
- end
- end
- end
- end
- -- Function to handle menu selection
- local function handleMenuSelection()
- while loggedIn do
- drawMenu()
- handleMouseInput()
- if selectedOption == 1 then
- term.clear()
- print("Are you sure you want to open the door? (y/n)")
- local confirm = read():lower()
- if confirm == "y" then
- print("Opening Door...")
- pulseBundledSignal(colors.green)
- end
- drawMenu()
- elseif selectedOption == 2 then
- term.clear()
- print("Are you sure you want to close the door? (y/n)")
- local confirm = read():lower()
- if confirm == "y" then
- print("Closing Door...")
- pulseBundledSignal(colors.red)
- end
- drawMenu()
- elseif selectedOption == 3 then
- term.clear()
- print("Retrieving logs...")
- sleep(1)
- print(generateCorruptData())
- sleep(4)
- drawMenu()
- elseif selectedOption == 4 then
- term.clear()
- print("Logging Out...")
- sleep(1)
- loggedIn = false
- end
- selectedOption = nil
- end
- end
- -- Function to reset the terminal after X minutes
- local function resetTimer()
- sleep(resetTime)
- loggedIn = false
- print("System reset. Login required again.")
- end
- -- Main execution
- while true do
- if not loggedIn then
- drawLoginScreen()
- if loggedIn then
- parallel.waitForAny(handleMenuSelection, resetTimer)
- else
- sleep(5)
- end
- else
- handleMenuSelection()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement