This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Tiin57's profile picture

Looping program

Started by Tiin57, 14 July 2012 - 10:36 PM
Tiin57 #1
Posted 15 July 2012 - 12:36 AM
I'm not quite sure how to describe this error. I'm trying to make a rednet authentication with a server and client. The client sends the password to the server, which checks the password against a makeshift database. If the password is right, it sends back a code phrase, which tells the client to let the user into CraftOS.
The problem is that when users 2 and 3 log in, no matter what password is put in, the client returns a wrong password error. I can't tell if it's an issue with the client or the server, so I'll post them both.

CLIENT

print("Welcome to TiinOS login system.")
print("Please select a user:")
print("1. Tiin")
print("2. Boblit")
print("3. Oran")
t = io.read()
if t == "1" then
print("Please enter the password.")
t = io.read()
rednet.broadcast(t)
local scrap, m = rednet.receive()
if m == "tiin" then
print("Welcome, Tiin.")
else
print("Wrong!")
shell.run("client2")
end
end
if t == "2" then
print("Please enter the password.")
t = io.read()
rednet.broadcast(t)
local scrap, m = rednet.receive()
if m == "boblit" then
print("Welcome, Trevor.")
else
print("Wrong!")
shell.run("client2")
end
end
if t == "3" then
print("Please enter the password.")
t = io.read()
rednet.broadcast(t)
local scrap, m = rednet.receive()
if m == "oran" then
print("Welcome, Oran.")
else
print("Wrong!")
shell.run("client2")
end
end

SERVER

print("Restarting server...")
local scrap, m = rednet.receive()
if m == "empire" then
rednet.broadcast("tiin")
else
rednet.broadcast("x")
end
shell.run("server2")
local scrap, m = rednet.receive()
if m == "Trevor" then
rednet.broadcast("boblit")
else
rednet.broadcast("x")
end
shell.run("server2")
local scrap, m = rednet.receive()
if m == "Irish" then
rednet.broadcast("oran")
else
rednet.broadcast("x")
end
shell.run("server2")
Please help!
Lyqyd #2
Posted 15 July 2012 - 12:44 AM
You have it set up such that each user must log in in order. First user one must log in, then user two must log in, then finally user three would be able to log in.

Corrected client:


print("Welcome to TiinOS login system.")
print("Please select a user:")
print("1. Tiin")
print("2. Boblit")
print("3. Oran")
t = read()
if t == "1" then
	print("Please enter the password.")
	t = read("*") --use read("*") for hidden inputs.
	rednet.broadcast(t)
	local scrap, m = rednet.receive()
	if m == "tiin" then
		print("Welcome, Tiin.")
	else
		print("Wrong!")
		shell.run("client2")
	end
elseif t == "2" then --use elseif for distinct options from one input, rather than subsequent if statements.
	print("Please enter the password.")
	t = read("*")
	rednet.broadcast(t)
	local scrap, m = rednet.receive()
	if m == "boblit" then
		print("Welcome, Trevor.")
	else
		print("Wrong!")
		shell.run("client2")
	end
elseif t == "3" then
	print("Please enter the password.")
	t = read("*")
	rednet.broadcast(t)
	local scrap, m = rednet.receive()
	if m == "oran" then
		print("Welcome, Oran.")
	else
		print("Wrong!")
		shell.run("client2")
	end
end

Corrected server:


while true do
local scrap, m = rednet.receive()
    if m == "empire" then
        rednet.broadcast("tiin")
    elseif m == "Trevor" then
        rednet.broadcast("boblit")
    elseif m == "Irish" then
        rednet.broadcast("oran")
    else
        rednet.broadcast("x")
    end
end
Tiin57 #3
Posted 15 July 2012 - 02:00 AM
Oh… Thank you.