Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- serverID = 5
- currentUser = {}
- os.loadAPI("gui")
- modemSide = "top"
- rednet.open(modemSide)
- allChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
- function randomString(length)
- e = ""
- for i = 1, length do
- r = math.random(#allChars)
- e = e..string.sub(allChars,r,r)
- end
- return e
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- term.setBackgroundColor(colors.lightBlue)
- clear()
- term.setCursorPos(23,4)
- print("LOG IN")
- gui.newButton(17,6,18,3,"",colors.lightGray)
- usernameArea = gui.newButton(18,7,16,1,"usernameArea",colors.gray)
- gui.newButton(17,10,18,3,"",colors.lightGray)
- passwordArea = gui.newButton(18,11,16,1,"passwordArea",colors.gray)
- submit = gui.newButton(22,15,8,3,"submit",colors.red)
- term.setCursorPos(23,16)
- term.setBackgroundColor(colors.red)
- term.write("Submit")
- username = ""
- password = ""
- while true do
- title = gui.waitForButtons(usernameArea,passwordArea,submit)
- if title == "usernameArea" then
- username = gui.inputField(18,7,username,16,colors.gray)
- elseif title == "passwordArea" then
- password = gui.inputField(18,11,password,16,colors.gray,"*")
- elseif title == "submit" then
- rednet.send(serverID, {{username," ",1,password},"LOG_IN"})
- id,msg,d = rednet.receive(.3)
- if id == serverID then
- currentUser = msg
- while true do
- term.setBackgroundColor(colors.lightBlue)
- clear()
- inhibitors = gui.newButton(2,2,12,3,"INHIBITORS ",colors.blue)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(3,3)
- term.write("Inhibitors")
- switches = gui.newButton(2,6,10,3,"SWITCHES",colors.blue)
- term.setCursorPos(3,7)
- term.write("Switches")
- keyLocks = gui.newButton(2,10,11,3,"KEY_LOCKS ",colors.blue)
- term.setCursorPos(3,11)
- term.write("Key Locks")
- account = gui.newButton(2,14,9,3,"ACCOUNT",colors.blue)
- term.setCursorPos(3,15)
- term.write("Account")
- addAccount = gui.newButton(15,2,13,3,"ADD_ACCOUNT",colors.blue)
- term.setCursorPos(16,3)
- term.write("Add Account")
- admin = gui.newButton(15,6,7,3,"ADMIN",colors.blue)
- term.setCursorPos(16,7)
- term.write("Admin")
- back = gui.newButton(15,10,6,3,"BACK",colors.blue)
- term.setCursorPos(16,11)
- term.write("Back")
- choice = gui.waitForButtons(back,addAccount,account,inhibitors,switches,keyLocks,admin)
- if choice == "INHIBITORS " or choice == "SWITCHES" or choice == "KEY_LOCKS " then
- while true do
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print(choice)
- rednet.send(serverID, {currentUser,"GET_"..choice})
- id,msg,d = rednet.receive(.5)
- if id == serverID then
- if type(msg) == "table" then
- drawArray = {}
- for i,v in ipairs(msg) do
- table.insert(drawArray,v[4].."("..v[3].."): "..v[2])
- end
- table.insert(drawArray,"<--")
- selection = gui.drawArray(drawArray,3)
- if selection ~= nil and selection ~= #drawArray then
- term.setBackgroundColor(colors.lightBlue)
- msgToServer = string.sub(choice,1,-3)
- rednet.send(serverID,{currentUser,"CHANGE_"..msgToServer,msg[selection][1]})
- sleep(.3)
- elseif selection == #drawArray then
- term.setBackgroundColor(colors.lightBlue)
- clear()
- break
- end
- end
- else
- print("SERVER ERROR")
- sleep(1)
- end
- end
- elseif choice == "ADMIN" then
- while true do
- sleep(.3)
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("Admin")
- term.setBackgroundColor(colors.blue)
- changeKey = gui.newButton(2,2,22,3,"CHANGE_KEY",colors.blue)
- term.setCursorPos(3,3)
- term.write("Change Key Clearance")
- changeUserClearance = gui.newButton(2,6,23,3,"CHANGE_USER_CLEARANCE",colors.blue)
- term.setCursorPos(3,7)
- term.write("Change User Clearance")
- removeUser = gui.newButton(2,10,13,3,"REMOVE_USER",colors.blue)
- term.setCursorPos(3,11)
- term.write("Remove User")
- back = gui.newButton(2,14,6,3,"BACK",colors.blue)
- term.setCursorPos(3,15)
- term.write("Back")
- choice2 = gui.waitForButtons(changeKey,changeUserClearance,removeUser,back)
- if choice2 == "CHANGE_KEY" then
- while true do
- sleep(.3)
- rednet.send(serverID,{currentUser,"GET_KEY_LOCKS "})
- id,msg,d = rednet.receive(.3)
- displayArray = {}
- if id == serverID then
- allLocks = msg
- for i,v in ipairs(allLocks) do
- table.insert(displayArray,v[4]..":"..v[5])
- end
- table.insert(displayArray,"Back")
- term.setBackgroundColor(colors.lightBlue)
- clear()
- selection = gui.drawArray(displayArray)
- if selection ~= nil and selection ~= #displayArray then
- newClearance = allLocks[selection][5]
- while true do
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print(allLocks[selection][4]..":"..allLocks[selection][5])
- term.setBackgroundColor(colors.blue)
- up = gui.newButton(2,3,1,1,"UP",colors.blue)
- term.setCursorPos(2,3)
- term.write("^")
- down = gui.newButton(2,4,1,1,"DOWN",colors.blue)
- term.setCursorPos(2,4)
- term.write("V")
- term.setBackgroundColor(colors.red)
- submit = gui.newButton(2,6,8,3,"SUBMIT",colors.red)
- term.setCursorPos(3,7)
- term.write("Submit")
- term.setCursorPos(3,3)
- term.setBackgroundColor(colors.lightBlue)
- term.write(newClearance)
- choice3 = gui.waitForButtons(up,down,submit)
- if choice3 == "UP" then
- newClearance = newClearance +1
- elseif choice3 == "DOWN" then
- newClearance = newClearance - 1
- elseif choice3 == "SUBMIT" then
- rednet.send(serverID,{currentUser,"CHANGE_KEY_LOCK_CLEARANCE",allLocks[selection],newClearance})
- break
- end
- end
- elseif selection == #displayArray then
- break
- end
- else
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("TOO LOW CLEARANCE OR SERVER ERROR")
- sleep(1)
- break
- end
- end
- elseif choice2 == "CHANGE_USER_CLEARANCE" then
- while true do
- sleep(.3)
- rednet.send(serverID,{currentUser,"GET_USERS"})
- id,msg,d = rednet.receive(.3)
- if id == serverID then
- displayArray = {}
- for i,v in ipairs(msg) do
- table.insert(displayArray,v[1]..":"..v[3])
- end
- table.insert(displayArray,"Back")
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("Users")
- selection = gui.drawArray(displayArray)
- if selection ~= nil and selection ~= #displayArray then
- newClearance = msg[selection][3]
- while true do
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print(displayArray[selection])
- up = gui.newButton(2,3,1,1,"UP",colors.blue)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(2,3)
- term.write("^")
- down = gui.newButton(2,4,1,1,"DOWN",colors.blue)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(2,4)
- term.write("V")
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos(3,3)
- term.write(newClearance)
- term.setBackgroundColor(colors.red)
- submit = gui.newButton(2,7,8,3,"SUBMIT",colors.red)
- term.setCursorPos(3,8)
- term.write("Submit")
- choice3 = gui.waitForButtons(up,down,submit)
- if choice3 == "UP" then
- newClearance = newClearance + 1
- elseif choice3 == "DOWN" then
- newClearance = newClearance - 1
- elseif choice3 == "SUBMIT" then
- rednet.send(serverID, {currentUser,"CHANGE_USER_CLEARANCE",msg[selection],newClearance})
- break
- end
- end
- elseif selection == #displayArray then
- break
- end
- else
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("TOO LOW CLEARANCE LEVEL OR SERVER ERROR")
- os.sleep(1)
- break
- end
- end
- elseif choice2 == "REMOVE_USER" then
- while true do
- sleep(.3)
- rednet.send(serverID,{currentUser,"GET_USERS"})
- id,msg,d = rednet.receive(.3)
- if id == serverID then
- displayArray = {}
- for i,v in ipairs(msg) do
- table.insert(displayArray,v[1]..":"..v[3])
- end
- term.setBackgroundColor(colors.lightBlue)
- clear()
- table.insert(displayArray,"Back")
- selection = gui.drawArray(displayArray)
- if selection ~= nil and selection ~= #displayArray then
- rednet.send(serverID,{currentUser,"REMOVE_USER",msg[selection]})
- elseif selection == #displayArray then
- break
- end
- else
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("TOO LOW CLEARANCE OR SERVER ERROR")
- sleep(1)
- break
- end
- end
- elseif choice2 == "BACK" then
- break
- end
- end
- elseif choice == "BACK" then
- term.setBackgroundColor(colors.black)
- clear()
- return exit
- elseif choice == "ADD_ACCOUNT" then
- newUsername = ""
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("Create Account")
- print("A password will be randomly generated and can be changed later")
- gui.newButton(2,5,10,3," ",colors.lightGray)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(3,5)
- term.write("USERNAME")
- usernameBox = gui.newButton(3,6,8,1,"USERNAME_BOX",colors.gray)
- term.setBackgroundColor(colors.red)
- submit = gui.newButton(2,9,8,3,"SUBMIT",colors.red)
- term.setCursorPos(3,10)
- term.write("Submit")
- term.setBackgroundColor(colors.blue)
- back = gui.newButton(2,13,6,3,"BACK",colors.blue)
- term.setCursorPos(3,14)
- term.write("Back")
- while true do
- choice2 = gui.waitForButtons(usernameBox,submit,back)
- if choice2 == "USERNAME_BOX" then
- newUsername = gui.inputField(3,6,newUsername,8,colors.gray)
- elseif choice2 == "SUBMIT" then
- rednet.send(serverID,{currentUser,"ADD_ACCOUNT",newUsername})
- id2,msg2,d2 = rednet.receive(.3)
- if id2 == serverID then
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("SUBMITTED")
- print("PASSWORD: "..msg2)
- print()
- print("PRESS ENTER")
- read()
- else
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("SUBMISSION FAILED")
- sleep(1)
- end
- break
- elseif choice2 == "BACK" then
- break
- end
- end
- elseif choice == "ACCOUNT" then
- while true do
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("Welcome "..currentUser[1])
- print("Clearance Level: "..currentUser[3])
- term.setBackgroundColor(colors.blue)
- resetCard = gui.newButton(2,4,12,3,"RESET_CARD",colors.blue)
- term.setCursorPos(3,5)
- term.write("Reset Card")
- resetPassword = gui.newButton(2,8,16,3,"RESET_PASSWORD",colors.blue)
- term.setCursorPos(3,9)
- term.write("Reset Password")
- printCard = gui.newButton(2,12,12,3,"PRINT_CARD",colors.blue)
- term.setCursorPos(3,13)
- term.write("Print Card")
- back = gui.newButton(2,16,6,3,"BACK",colors.blue)
- term.setCursorPos(3,17)
- term.write("Back")
- choice2 = gui.waitForButtons(printCard,resetCard,resetPassword,back)
- if choice2 == "RESET_CARD" then
- newCard = randomString(6)
- rednet.send(serverID,{currentUser,"RESET_CARD",newCard})
- currentUser[2] = newCard
- found = false
- for i,v in ipairs(peripheral.getNames()) do
- if peripheral.getType(v) == "drive" then
- found = true
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("ENTER DISK")
- while true do
- e = os.pullEvent()
- if e == "disk" then
- file = fs.open("disk/access", "w")
- file.write(newCard)
- file.close()
- break
- end
- end
- end
- end
- if not found then
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("ATTATCH A DISK DRIVE")
- sleep(1)
- end
- elseif choice2 == "PRINT_CARD" then
- found = false
- for i,v in ipairs(peripheral.getNames()) do
- if peripheral.getType(v) == "drive" then
- found = true
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("ENTER CARD")
- while true do
- e = os.pullEvent()
- if e == "disk" then
- file = fs.open("disk/access", "w")
- file.write(currentUser[2])
- file.close()
- break
- end
- end
- end
- end
- if not found then
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("NO DRIVE FOUND")
- sleep(1)
- end
- elseif choice2 == "RESET_PASSWORD" then
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("Reset Password")
- gui.newButton(2,3,12,3," ",colors.lightGray)
- pField = gui.newButton(3,4,10,1,"pField",colors.gray)
- submit = gui.newButton(2,7,8,3,"submit",colors.red)
- term.setBackgroundColor(colors.red)
- term.setCursorPos(3,8)
- term.write("Submit")
- newPassword = ""
- while true do
- choice3 = gui.waitForButtons(pField,submit)
- if choice3 == "pField" then
- newPassword = gui.inputField(3,4,newPassword,10,colors.gray)
- elseif choice3 == "submit" then
- if newPassword ~= nil then
- rednet.send(serverID,{currentUser,"RESET_PASSWORD",newPassword})
- break
- end
- end
- end
- elseif choice2 == "BACK" then
- clear()
- break
- end
- end
- end
- end
- else
- term.setBackgroundColor(colors.lightBlue)
- clear()
- print("SERVER ERROR")
- sleep(1.5)
- os.shutdown()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement