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

Error with no error messages.

Started by CODsniperkid, 10 September 2012 - 08:20 PM
CODsniperkid #1
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:

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
Luanub #2
Posted 10 September 2012 - 10:32 PM
What's wrong with it? What does it not do or do wrong? More information is always better then less.
GopherAtl #3
Posted 10 September 2012 - 10:40 PM
might not be the only issue, didn't go through all the code, but right at the start of server, you call rednet.send("NEWREADY"), but rednet.send needs 2 params, the first being the id of the computer to send to. Did you mean rednet.broadcast("NEWREADY") there?
CODsniperkid #4
Posted 11 September 2012 - 03:38 AM
might not be the only issue, didn't go through all the code, but right at the start of server, you call rednet.send("NEWREADY"), but rednet.send needs 2 params, the first being the id of the computer to send to. Did you mean rednet.broadcast("NEWREADY") there?
So I fixed that, but it still doesn't run through the program. Both the client and the server program stop running after I send the username and password to the server.
CODsniperkid #5
Posted 11 September 2012 - 03:55 AM
I updated the first post with the problematic parts of both pieces of code.
Kilobyte #6
Posted 11 September 2012 - 06:02 PM
can you please post the entire code file and the exact problem that occurs?

apart from that you may also want to format your code like this:

function foo()
  for i = 1, 5 do
	print("bar")
  end
end
instead of

function foo()
for i = 1, 5 do
print("bar")
end
end
that makes it a lot more readable and makes troubleshooting a lot easier :)/>/>