Advertisement
Guest User

cdrive.lua

a guest
Mar 3rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1. rednet.open("top")
  2. local serverId
  3.  
  4. print("Connecting to server...")
  5. rednet.broadcast("","cdrive-findserver")
  6. repeat
  7.     local id,msg,pro = rednet.receive("cdrive-gotserver",3)
  8.     if pro == "cdrive-gotserver" then  
  9.         serverId = id
  10.         print("Success! Connected to server id "..serverId)
  11.     elseif id == nil then
  12.         printError("Failed to connect to server!")
  13.         return
  14.     end
  15. until serverId
  16.  
  17. print("Drawing login UI...")
  18.  
  19. local function drawLoginUI()
  20.     term.setCursorPos(2,2)
  21.     term.setBackgroundColor(colors.white)
  22.     term.setTextColor(colors.gray)
  23.     term.clear()
  24.     term.write("cDrive Login")
  25.     term.setCursorPos(2,4)
  26.     term.setBackgroundColor(colors.lightGray)
  27.     term.setTextColor(colors.gray)
  28.     term.write(" Username                   ")
  29.     term.setCursorPos(2,6)
  30.     term.write(" Password                   ")
  31.     term.setCursorPos(2,8)
  32.     term.setBackgroundColor(colors.gray)
  33.     term.setTextColor(colors.lightGray)
  34.     term.write(" Login ")
  35.     term.setCursorPos(11,8)
  36.     term.write(" Cancel ")
  37.     term.setCursorPos(21,8)
  38.     term.write(" Sign Up ")
  39. end
  40.  
  41. local function drawSignupUI()
  42.     term.setBackgroundColor(colors.white)
  43.     term.clear()
  44.     term.setCursorPos(2,2)
  45.     term.setTextColor(colors.gray)
  46.     term.write("Loading...")
  47.     rednet.send(serverId, nil, "cdrive-requestwave")
  48.     local id, wave, pro = rednet.receive("cdrive-gotwave",3)
  49.    
  50.     term.clear()
  51.     term.setCursorPos(2,2)
  52.     term.write("When you sign up, your wave will be "..wave)
  53.     sleep(100)
  54. end
  55.  
  56. local username = ""
  57. local password = ""
  58.  
  59. local function loginButtons()
  60.     while true do
  61.         local event, b, x, y = os.pullEvent("mouse_click")
  62.         if x >= 11 and x <= 19 and y == 8 then
  63.             term.setBackgroundColor(colors.black)
  64.             term.clear()
  65.             term.setCursorPos(1,1)
  66.             return
  67.         elseif x >= 21 and x <= 30 and y == 8 then
  68.             drawSignupUI()
  69.             return
  70.         elseif x >= 2 and x <= 29 and y == 4 then
  71.             term.setTextColor(colors.black)
  72.             term.setBackgroundColor(colors.lightGray)
  73.             term.setCursorPos(3,4)
  74.             term.write(string.rep(" ", 27))
  75.             term.setCursorPos(3,4)
  76.             username = read()
  77.         elseif x >= 2 and x <= 29 and y == 6 then
  78.             term.setTextColor(colors.black)
  79.             term.setBackgroundColor(colors.lightGray)
  80.             term.setCursorPos(3,6)
  81.             term.write(string.rep(" ", 27))
  82.             term.setCursorPos(3,6)
  83.             password = read("\7")
  84.            
  85.         end
  86.     end
  87. end
  88.  
  89. drawLoginUI()
  90. loginButtons()
  91.  
  92. rednet.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement