Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- w,h = term.getSize()
- local menustate = "Logon Program"
- local user = ""
- function isInteger(nIn)
- if math.floor(nIn) == nIn then return true
- else return false end
- end
- function printCentred(str , h)
- term.setCursorPos(w/2 - #str/2, h)
- term.write(str)
- end
- function printRight(str , h)
- term.setCursorPos(w - #str, h)
- term.write(str)
- end
- function printLeft(str , h)
- term.setCursorPos(1, h)
- term.write(str)
- end
- function returnFileAsTable(aFile) --This function and the two bellow it are credit of Challenge.Accepted on the ComputerCraft Forums
- f= fs.open(aFile,"r")
- aTable = {}
- aLine = f.readLine()
- while aLine ~= nil do
- table.insert(aTable, aLine)
- aLine = f.readLine()
- end
- return aTable
- end
- function seperateString(aString, sep)
- p = string.find(aString, sep)
- return string.sub(aString, 1, p-1), string.sub(aString, p+1)
- end
- function iterateTable(aTable)
- local keyTable = {}
- local definitionTable = {}
- for i=1, #aTable do
- key, def = seperateString(aTable[i], ":")
- table.insert(keyTable, key)
- table.insert(definitionTable, def)
- end
- return keyTable, definitionTable
- end
- function drawHeader()
- term.setTextColour(colours.white)
- printCentred("KYLEOS - TEST 1.0", 1)
- printLeft(string.rep("-",w),2)
- printLeft(string.rep("-",w),h-1)
- printLeft(menustate.." : "..user,h)
- printRight("made by kylergs",h)
- end
- function drawLogon()
- printCentred("Please LogOn to your user", 5)
- printCentred("Username: ",8)
- printCentred("Password: ",10)
- end
- function drawLog(acc)
- term.clear()
- if acc then
- drawHeader()
- printCentred("Logon Accepted", 6)
- printCentred("Logging on to - "..user, 8)
- printCentred(" Press any Key to continue... ", 11)
- else
- drawHeader()
- printCentred("Logon Denied", 6)
- printCentred("Reseting to guest",8)
- printCentred("Press any Key to continue", 11)
- user = "guest"
- end
- os.pullEvent("key")
- sleep(0.1)
- end
- function logon(users,cUser)
- local usr
- user = cUser
- local pass
- term.clear()
- drawHeader()
- drawLogon()
- term.setCursorPos(w/2+5,8)
- usr = read()
- term.setCursorPos(w/2+5,10)
- inpass = read("*")
- flag = false
- if users[usr] then
- if users[usr].pass == inpass then
- user = usr
- drawLog(true)
- else
- drawLog(false)
- end
- else
- drawLog(false)
- end
- return user
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement