Guest User

ui

a guest
Apr 9th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. function center(y,str)
  2.   local w,h = term.getSize()
  3.   local x = (w/2) - (#str/2)
  4.   term.setCursorPos(x,y)
  5.   print(str)
  6. end
  7.  
  8. function render()
  9. term.setBackgroundColor(colors.white)
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. paintutils.drawLine(1,1,51,1,colors.lightGray)
  13. term.setCursorPos(1,1)
  14. term.setTextColor(colors.white)
  15. center(1,"Venatus reLIVE")
  16. term.setBackgroundColor(colors.white)
  17. term.setTextColor(colors.black)
  18. end
  19.  
  20. function renderstart()
  21. render()
  22. center(3,"Please select what you want to do.")
  23. center(4,"Press the button on your keyboard to continue.")
  24. center(6,"[L] Login")
  25. center(7,"[C] Create")
  26. center(8,"[E] Exit")
  27. end
  28.  
  29. function renderlogin()
  30.   render()
  31.   center(3,"Please input the following information.")
  32. end
  33.  
  34. renderstart()
  35.  
  36. local bRunning = true
  37.  
  38. while bRunning do
  39.   local e,key = os.pullEvent("key")
  40.   if key == keys.l then
  41.     renderlogin()
  42.     term.setCursorPos(2,5)
  43.     write("Username: ")
  44.     local username = read()
  45.     term.setCursorPos(2,6)
  46.     write("Password: ")
  47.     local password = read("*")
  48.     local auth = shell.run("auth "..username.." "..password)
  49.     if auth == true then
  50.       render()
  51.       center(5,"Login successful.")
  52.       center(6,"Welcome back, "..username..".")
  53.       sleep(3)
  54.       local bRunning = false
  55.       _G.session = {active = true, user = username, pass = password}
  56.       return
  57.     elseif auth == false then
  58.       render()
  59.       center(5,"Login error.")
  60.       center(6,"Either username/password is wrong or server is down.")
  61.       sleep(3)
  62.       local bRunning = false
  63.       return
  64.     end
  65.   elseif key == keys.c then
  66.     render()
  67.     center(2,"Input the following information.")
  68.     term.setCursorPos(2,4)
  69.     write("Username: ")
  70.     local username = read()
  71.     term.setCursorPos(2,5)
  72.     write("Password: ")
  73.     local password = read("*")
  74.     local new = shell.run("newuser "..username.." "..password)
  75.     if new == true then
  76.       render()
  77.       center(5,"The account '"..username.."' has been created.")
  78.       center(6,"We hope you enjoy Venatus reLIVE.")
  79.       sleep(3)
  80.       local bRunning = false
  81.       _G.session = {active = true, user = username, pass = password}
  82.       return
  83.     elseif new == "test" then
  84.       render()
  85.       center(5,"There was an error processing your request.")
  86.       center(6,"Either a user already exists with that name or the")
  87.       center(7,"server is offline.")
  88.       sleep(3)
  89.       local bRunning = false
  90.       return
  91.     end
  92.   elseif key == keys.e then
  93.     local bRunning = false
  94.     return
  95.   end
  96. end
Add Comment
Please, Sign In to add comment