Posted 13 August 2012 - 12:09 PM
So I've got a console that I'd like to run as a server, and several other consoles that I'd run as a client. Each have modems connected, and I've checked all ID's of all computers. The idea is you log in to a computer and then it opens the door (A more complex variation of the password-protected doors). The problem is after I've got the server up and running, and the client up and running, the client will always give me a "Not Authorised" message (an error message that I write client-side).
If anyone could tell me why I'm getting the error message that'd be perfect. Below is the code, let me know if I need to provide any more details. Also, the Client doesn't have any door-opening code in it, because that code is quite trivial and easy to do.
Eventually it'll be set up so that certain doors have permission levels, so only Administrators can enter the server room, etc.
Server:
Client code:
If anyone could tell me why I'm getting the error message that'd be perfect. Below is the code, let me know if I need to provide any more details. Also, the Client doesn't have any door-opening code in it, because that code is quite trivial and easy to do.
Eventually it'll be set up so that certain doors have permission levels, so only Administrators can enter the server room, etc.
Server:
term.clear() --Clear any text
term.setCursorPos(1,1) --Set cursor position to beginning
write"This is not a user-accessible computer." -- User information
write"Log in at one of the USER PCs." --User information
local firstCycle = true -- Used to determine whether to run bootUp function. Boolean variable
local validSender = false --Used to determine whether valid information has been entered. Boolean variable
local modemSide = "right" --Determines modem side. String variable
local valid = false --Used to determine whether check is made as to whether to return password or not. Boolean variable
users = {{uname = "XenoG", pword = "pl455ey"},
{uname = "Test", pword = "user"},
{uname = "Xenogene", pword = "lolgasm"}
} --Users table. Left is key, right is value. In effect Username-Password (Key-Value)
senders = {612, 613, 617, 618, 619, 621} --Table of all computer ID's that can access server.
function bootUp() --New function "bootUp()"
rednet.open(modemSide) --Sends message to rednet to make sure the modem is open
end --End function
while true do --Main server loop
validSender = false --set validSender to false. Needs to be done every loop round
if firstCycle then --If the this is the first cycle then
bootUp() --Call the bootUp() function
end --End IF statement
senderId, message, distance = rednet.receive() --rednet.receive() function call. Loop waits here until a message is received
for i,v in ipairs(senders) do --For index, value, search in the table senders, then execute next line
if v == senderId then --If v is equal to a senderId (found in senders table) then
validSender = true --Set validSender to true
break --Break the loop
end --End IF statement
end --End FOR loop
if validSender then --If validSender is true, execute next line
for k,v in pairs(users) do --For index, value, search in the table users, then execute next line
if message == k then --If k is equal to message (found in users table) then
valid = true --Set valid to true
password = users[v.value] -- Set password to the value of v
else --Otherwise
valid = false --Set valid to false
end --End IF statement
end --End FOR loop
if valid then --If valid is true, execute next line
rednet.send(senderId, password) -- Send the senderID and the password to rednet
else --Otherwise
rednet.send(senderId, "Not Valid") --Send a Not Valid message to rednet
end --End IF statement
end --End IF statement
end --End WHILE TRUE DO loop
Client code:
local locker = true
local attempted_login = true
local password_server = 17 -- change to the ID of your password server computer
rednet.open("left") -- change to the side your rednet modem is on
while locker do
attempted_login = false
term.clear()
term.setCursorPos(1,1)
print("Welcome to a USERS PC : Roaming Profile Enabled")
print("What would you like to do?")
print("[1] Login (*)")
print("[2] Shutdown")
write("> ")
local input = read()
if input == "2" then
os.shutdown()
elseif input == "1" then
attempted_login = true
print("Please login...")
write("Username: ")
local username = read()
write("Password: ")
local password = read("*")
rednet.send(password_server, username)
senderId, message, distance = rednet.receive(5)
if password == message then
locker = false
term.clear()
term.setCursorPos(1,1)
print("Welcome ", username)
else
print("Not authorised.")
sleep(1)
end
else
print("Command not recognised...")
sleep(2)
end
end