Posted 10 September 2012 - 10:20 PM
I've tried debugging this problem for over 2 hours now and I can't find the issue(s). It's probably something stupid, but if someone would like to have a go at it, I would very much appreciate anything you may or may not find. :D/>/> The purpose of this program is for a client to send a username and password to a server computer that then checks if the account exists, and if not, starts creating an account with the help of the clientside.
SERVER:
CLIENT:
PROBLEMATIC CODE:
SERVER:
CLIENT:
SERVER:
function clear()
term.clear()
term.setCursorPos(1,1)
end
function new()
rednet.send(x,"NEWREADY")
x,y,z = rednet.receive()
f = io.open(z,"w")
f:write("USERNAME: "..z.."n")
rednet.send(x,"PASS?")
x,y,z = rednet.receive()
f:write("PASSWORD: "..z.."n")
rednet.send(x,"MC?")
x,y,z = rednet.receive()
f:write("MCUSER: "..z.."n")
f:close()
rednet.send(x,"DONE")
end
function validate()
x,y,z = rednet.receive()
if z == "NEW" then
new()
else
print("New Login Attempt")
if fs.exists(z) then
print("Username "..z.." exists!")
rednet.send(x,"true")
f = fs.open(z,"w")
x,y,z = rednet.receive()
password = f.readLine(2)
if password == z then
MCUser = f.readLine(3)
rednet.send(x,MCUser)
else
rednet.send(x,"false")
new()
end
else
rednet.send(x,"false")
end
end
end
rednet.open("top")
validate()
CLIENT:
--Variables
redSide = "top"
serverID = 7
compName = os.getComputerID()
--Clear function
function clear()
term.clear()
term.setCursorPos(1,1)
end
--NewAccount
function new()
clear()
print("Username")
user = io.read()
print("Password:")
password = read("*")
print("MC Username:")
MCUser = io.read()
rednet.send(serverID,"NEW")
x,y,z = rednet.receive()
if x == serverID and z == "NEWREADY" then
rednet.send(serverID,user)
x,y,z = rednet.receive()
if x == serverID and z == "PASS?" then
rednet.send(serverID,password)
x,y,z = rednet.receive()
if x == serverID and z == "MC?" then
rednet.send(serverID,MCUser)
x,y,z = rednet.receive()
if x == serverID and z == "DONE" then
print("Account created!")
print("Username: "..user)
print("Password: The password you entered...")
print("MCUsername: "..MCUser)
print("Rebooting to apply changes...")
sleep(3)
os.reboot()
end
end
end
end
end
--Main
function login()
print("######OSTest1.0######")
print("########Login########")
print("---------------------")
print("Username:")
user = io.read()
print("Password:")
pass = read("*")
clear()
print("Opening Rednet...")
rednet.open(redSide)
print("Sending username...")
rednet.send(serverID,user)
x,y,z = rednet.receive(10)
if x == serverID and z == "true" then
print("Account exists!")
sleep(1)
print("Sending password...")
rednet.send(serverID,pass)
a,b,c = rednet.receive(10)
if a == serverID and c ~= "false" then
print("Password validated!")
sleep(1)
print("Welcome "..c.."!")
elseif a == serverID and c == "false" then
print("Password invalid.")
sleep(2)
login()
end
elseif x == serverID and z == "false" then
print("Account not yet created.")
print("Please enter admin password now to create one")
print("Administrator Password:")
adminPass = read("*")
rednet.send(serverID,adminPass)
d,e,f = rednet.receive()
if d == serverID and f == "true" then
print("Administrator Logged In!")
print("Create a new account now!")
sleep(3)
new()
end
end
end
function boot()
textutils.slowPrint("Welcome to OSTest v1.1!")
sleep(2)
clear()
login()
end
boot()
PROBLEMATIC CODE:
SERVER:
if fs.exists(z) then
print("Username "..z.." exists!")
rednet.send(x,"true")
f = fs.open(z,"w")
x,y,z = rednet.receive()
password = f.readLine(2)
if password == z then
MCUser = f.readLine(3)
rednet.send(x,MCUser)
else
rednet.send(x,"false")
new()
end
else
rednet.send(x,"false")
end
end
end
rednet.open("top")
validate()
CLIENT:
rednet.send(serverID,user)
x,y,z = rednet.receive(10)
if x == serverID and z == "true" then
print("Account exists!")
sleep(1)
print("Sending password...")
rednet.send(serverID,pass)
a,b,c = rednet.receive(10)
if a == serverID and c ~= "false" then
print("Password validated!")
sleep(1)
print("Welcome "..c.."!")
elseif a == serverID and c == "false" then
print("Password invalid.")
sleep(2)
login()
end
elseif x == serverID and z == "false" then
print("Account not yet created.")
print("Please enter admin password now to create one")
print("Administrator Password:")
adminPass = read("*")
rednet.send(serverID,adminPass)
d,e,f = rednet.receive()
if d == serverID and f == "true" then
print("Administrator Logged In!")
print("Create a new account now!")
sleep(3)
new()
end
end
end