Posted 14 December 2014 - 09:52 PM
Hello, I am trying to make a password protected program which will lock certain rooms off to people with different access levels. The access computers that ask users to input their username and password then asks one of the main servers in my base for a list of all users, to see whether or not the user is allowed in. I have tried everything I can to try and fix the issue, however this is my first time programming in lua and therefore I still don't understand a lot. Below is my code for the access computer and the main server.
Access Computer:
Main Server:
Thank you :)/>
Access Computer:
Spoiler
os.pullEvent = os.pullEventRaw
function topBar()
term.clear()
term.setCursorPos(1, 1)
print("MMOS Version 1.0")
term.setCursorPos(1, 3)
end
rednet.open("right")
while true do
rednet.send(3, "Send userList")
repeat
receivedId, userListRednet = rednet.receive()
until receivedId == 3
f = fs.open("userListRednet", "r")
userList = textutils.unserialize(f.readAll())
f.close()
topBar()
print("Enter your username:")
name = read()
for i = 1, #userList do
if name == userList[i][1] then
userPassword = userList[i][2]
userAccessLevel = userList[i][3]
break
end
end
topBar()
print("Enter your password:")
password = read("*")
if password == userPassword then
topBar()
textutils.slowPrint("Welcome "..name..". You have been granted Level "..userAccessLevel.." Access.")
redstone.setOutput("back", true)
term.setCursorPos(1, 6)
textutils.slowPrint("The entrance will close in 16 seconds.")
for i = 1, 15 do
secondsLeft = 16 - i
term.setCursorPos(1, 6)
term.clearLine()
print("The entrance will close in "..secondsLeft.." seconds.")
sleep(1)
end
topBar()
textutils.slowPrint("The entrance is now locked.")
sleep(3)
redstone.setOutput("back", false)
else
topBar()
print("Access Denied.")
sleep(3)
end
end
Main Server:
Spoiler
os.pullEvent = os.pullEventRaw
while true do
userList = {{"name1", "password1", 1}, {"name2", "password2", 2}, {"Name3", "password3", 3}}
receivedId, receivedMessage = rednet.receive()
userListRednet = textutils.serialize(userList)
rednet.send(0, userListRednet)
end
Thank you :)/>