Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Code by OutlawBlue9
- --Thanks to Advent and OminousPenguin of the ComputerCraft Forums for advice and tutalage
- --Thanks to Liraal of the ComputerCraft Forums for his tutorial "A quick guide through menu making"
- --os.pullEvent = os.pullEventRaw --Turned off for debugging purposes
- version = "v0.2"
- userlist = {}
- users = {}
- status = "Logged Out"
- currentuser = "New User"
- loginid = nil
- loginpass = nil
- attempts=0
- adminmenu = {}
- usermenu = {}
- adminmenu = {"Option 1", "Option 2", "Option 3", "Log Out", "*Add User*", "*Add Admin*", "*Remove User*", "*Display Users*"}
- usermenu = {"Option 1", "Option 2", "Option 3", "Log Out"}
- function homescreen()
- term.clear()
- term.setCursorPos(1,1)
- print("Running OutSec "..version.." ".. textutils.formatTime( os.time(), false)) --currently displays Minecraft time, not real time
- print("Status: "..status)
- if status == "Logged In"
- then
- term.setCursorPos(1,3)
- print("User: " ..currentuser)
- end
- print(string.rep("*", 49))
- term.setCursorPos(1,10)
- end
- function getInput(intype, character)
- write(intype)
- input = read(character)
- return input
- end
- function newuser(admin)
- homescreen()
- if admin == true
- then
- print("Please register Admin:")
- else
- print("Please register User:")
- end
- while true do
- homescreen()
- newusername = getInput("Username:")
- if userlist[newusername] == nil
- then
- break
- else
- print("Username already taken, please try again.")
- sleep(2)
- end
- end
- newpassword = getInput("Password:", "*")
- homescreen()
- print("Username: "..newusername)
- print("Password: "..newpassword)
- print("Confirm?[Y/N]")
- local event, k1 = os.pullEvent("char")
- if k1 == "y"
- then
- table.insert(userlist, newusername)
- table.insert(users, newusername)
- userlist[newusername] = {}
- table.insert(userlist[newusername], "password")
- userlist[newusername].password = newpassword
- table.insert(userlist[newusername], "adminstatus")
- userlist[newusername].adminstatus = admin
- home()
- elseif k1 == "n" then
- newuser()
- end
- end
- function login()
- homescreen()
- loginid = getInput("Username:")
- if userlist[loginid] == nil
- then
- print("Invalid Username. Please try again.")
- sleep(2)
- login()
- end
- end
- function password()
- for attempts=0, 2, 1 do
- if attempts > 0
- then
- term.setCursorPos(1,9)
- print("Incorrect Password. ("..3-attempts.."/3 attempts remaining.)")
- end
- loginpass = getInput("Password:", "*")
- if loginpass == userlist[loginid].password
- then
- break
- else
- attempts = attempts + 1
- end
- end
- --[[ while loginpass ~= userlist[loginid].password and a <= 3 do
- if a>0
- then
- term.setCursorPos(1,9)
- print("Incorrect Password. ("..3-a.."/3 attempts remaining.)")
- end
- write("Please enter password:")
- loginpass = read("*")
- a = a + 1
- end ]]
- if attempts == 3
- then
- attempts=0
- homescreen()
- print("Too many failed attempts. Please wait.")
- sleep(2)
- home()
- else
- status = "Logged In"
- currentuser = loginid
- print("Entry Authorized.")
- sleep(2)
- home()
- end
- --[[ if loginpass == userlist[loginid].password
- then
- status = "Logged In"
- currentuser = loginid
- print("Entry Authorized.")
- sleep(2)
- homescreen()
- else
- a = a+1
- if a < 3
- then
- password()
- else
- a=0
- homescreen()
- print("Too many failed attempts. Please wait.")
- sleep(2)
- login()
- end
- end ]]
- end
- function logout()
- currentuser = nil
- status = "Logged Out"
- end
- function removeuser()
- homescreen()
- print("Remove User")
- user = getInput("Username:")
- while true do
- if userlist[user] == nil
- then
- print("Invalid Username. Please try again.")
- sleep(2)
- else
- break
- end
- end
- print("Remove User " ..user.."? [Y/N]")
- local event, k1 = os.pullEvent("char")
- if k1 == "y"
- then
- userlist[user] = nil
- users[user] = nil
- end
- home()
- end
- --[[function checkuser(id, func)
- if userlist[id] == nil
- then
- print("Invalid Username. Please try again.")
- sleep(2)
- func
- end]]
- function displayusers()
- homescreen()
- term.setCursorPos(1, 6)
- print("Userlist:")
- textutils.tabulate(users)
- print("Press [Any Key] to return to menu")
- a, b= os.pullEventRaw()
- if a == "key"
- then
- home()
- end
- end
- function future()
- homescreen()
- print("Future Update!")
- print("Press [Any Key] to return to menu.")
- a, b= os.pullEventRaw()
- if a == "key"
- then
- home()
- end
- end
- function printmenu(menu)
- n=1
- l=#menu
- while true do
- homescreen()
- term.setCursorPos(1,6)
- for i=1, l, 1 do
- if i==n
- then
- print("["..menu[i].."]")
- else
- print(" "..menu[i])
- end
- end
- term.setCursorPos(1,19)
- print("Select a number[arrow up/arrow down]")
- a, b= os.pullEventRaw()
- if a == "key"
- then
- if b==200 and n>1
- then
- n=n-1
- end
- if b==208 and n<=l
- then
- n=n+1
- end
- if b==28
- then
- break
- end
- end
- end
- homescreen()
- return n
- end
- function home()
- homescreen()
- while status == "Logged Out" do
- if #userlist == 0
- then
- newuser(true)
- else
- login()
- password()
- end
- end
- if userlist[currentuser].adminstatus == true
- then
- printmenu(adminmenu)
- else
- printmenu(usermenu)
- end
- if n == 1
- then
- future()
- elseif n == 2 then
- future()
- elseif n == 3 then
- future()
- elseif n == 4 then
- logout()
- elseif n == 5 then
- newuser()
- elseif n == 6 then
- newuser(true)
- elseif n == 7 then
- removeuser()
- elseif n == 8 then
- displayusers()
- end
- end
- home()
Advertisement
Add Comment
Please, Sign In to add comment