Advertisement
kylergs

Logon Sys 1.1

Nov 18th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. w,h = term.getSize()
  2. local menustate = "Logon Program"
  3. local user = ""
  4.  
  5. function isInteger(nIn)
  6.     if math.floor(nIn) == nIn then return true
  7.     else return false end
  8. end
  9. function printCentred(str , h)
  10.   term.setCursorPos(w/2 - #str/2, h)
  11.   term.write(str)
  12. end
  13. function printRight(str , h)
  14.   term.setCursorPos(w - #str, h)
  15.   term.write(str)
  16. end
  17. function printLeft(str , h)
  18.   term.setCursorPos(1, h)
  19.   term.write(str)
  20. end
  21.  
  22. function returnFileAsTable(aFile) --This function and the two bellow it are credit of Challenge.Accepted on the ComputerCraft Forums
  23.     f= fs.open(aFile,"r")
  24.     aTable = {}
  25.     aLine = f.readLine()
  26.     while aLine ~= nil do
  27.         table.insert(aTable, aLine)
  28.         aLine = f.readLine()
  29.     end
  30.     return aTable
  31. end
  32. function seperateString(aString, sep)
  33.     p = string.find(aString, sep)
  34.     return string.sub(aString, 1, p-1), string.sub(aString, p+1)
  35. end
  36. function iterateTable(aTable)
  37.     local keyTable = {}
  38.     local definitionTable = {}
  39.     for i=1, #aTable do
  40.         key, def = seperateString(aTable[i], ":")
  41.         table.insert(keyTable, key)
  42.         table.insert(definitionTable, def)
  43.     end
  44.     return keyTable, definitionTable
  45. end
  46.  
  47. function drawHeader()
  48.   term.setTextColour(colours.white)
  49.   printCentred("KYLEOS - TEST 1.0", 1)
  50.   printLeft(string.rep("-",w),2)
  51.   printLeft(string.rep("-",w),h-1)
  52.   printLeft(menustate.." : "..user,h)
  53.   printRight("made by kylergs",h)
  54. end
  55.  
  56. function drawLogon()
  57.   printCentred("Please LogOn to your user", 5)
  58.   printCentred("Username: ",8)
  59.   printCentred("Password: ",10)
  60. end
  61.  
  62. function drawLog(acc)
  63.     term.clear()
  64.     if acc then
  65.         drawHeader()
  66.         printCentred("Logon Accepted", 6)
  67.         printCentred("Logging on to - "..user, 8)
  68.         printCentred(" Press any Key to continue...  ", 11)
  69.     else
  70.         drawHeader()
  71.         printCentred("Logon Denied", 6)
  72.         printCentred("Reseting to guest",8)
  73.         printCentred("Press any Key to continue", 11)
  74.         user = "guest"
  75.     end
  76.     os.pullEvent("key")
  77.     sleep(0.1)
  78. end
  79.  
  80. function logon(users,cUser)
  81.     local usr
  82.     user = cUser
  83.     local pass
  84.     term.clear()
  85.     drawHeader()
  86.     drawLogon()
  87.     term.setCursorPos(w/2+5,8)
  88.     usr = read()
  89.     term.setCursorPos(w/2+5,10)
  90.     inpass = read("*")
  91.     flag = false
  92.     if users[usr] then
  93.         if users[usr].pass == inpass then
  94.             user = usr
  95.             drawLog(true)
  96.         else
  97.             drawLog(false)
  98.         end
  99.     else
  100.         drawLog(false)
  101.     end
  102.  return user
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement