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

Rennet not communicating

Started by moneymaster2012, 04 July 2017 - 02:20 PM
moneymaster2012 #1
Posted 04 July 2017 - 04:20 PM
Hi.

A currency system I am making is getting me stumped with the wireless modems not communicating.

I have 2 computers: a server and an ATM (client).

The client makes a login request to the server.

When I type any random username and password, the program continues like it should. But when I type a username that is in the users/ folder, all computers just freeze, no matter if my password is correct or incorrect.

If anybody could follow along in the program and spot out any issues, please feel free to tell me so.

Client Snippet

clear()
print("[Login to debit account]")
print(" ")
rednet.open("top")
rednet.broadcast("login")
write("Username: ")
uInput = read()
rednet.broadcast(uInput)
write("Password: ")
pInput = read("*")
rednet.broadcast(pInput)
local q,w,e = rednet.receive()
if w == "notExist" then
  clear()
  print("[Login to debit account]")
  print(" ")
  term.setTextColor(colors.red)
  textutils.slowPrint("Username or password does not match.")
  term.setTextColor(colors.black)
  sleep(2)
  shell.run("login")
end
local s,m,p = rednet.receive()
if m == "correct" then
  shell.run("menu")
elseif m == "incorrect" then
  clear()
  print("[Login to debit account]")
  print(" ")
  term.setTextColor(colors.red)
  textutils.slowPrint("Username or password does not match.")
  term.setTextColor(colors.black)
  sleep(2)
  shell.run("login")
end

Server Snippet

elseif m == "login" then
  
	local s,m,p = rednet.receive() -- username
	local s2,m2,p2 = rednet.receive() -- password
  
	local h = fs.exists("users/"..m)
	if h == true then
	  local h = fs.open("users/"..m.."/password", "r")
	  local pass = h.readLine()
	  h.close()
	  if m2 == pass then
		rednet.broadcast("correct")
		os.reboot()
	  else
		rednet.broadcast("incorrect")
		os.reboot()
	  end
	else
	  rednet.broadcast("notExist")
	  os.reboot()
	end
  end
end
KingofGamesYami #2
Posted 04 July 2017 - 04:35 PM
The problem is you are discarding the "correct" message.


local q,w,e = rednet.receive() --# this line receives "correct"
if w == "notExist" then --# it doesn't match this, so skip everything inside the if
  clear()
  print("[Login to debit account]")
  print(" ")
  term.setTextColor(colors.red)
  textutils.slowPrint("Username or password does not match.")
  term.setTextColor(colors.black)
  sleep(2)
  shell.run("login")
end
local s,m,p = rednet.receive() --# wait for another message (which is never sent!)
moneymaster2012 #3
Posted 04 July 2017 - 04:58 PM
The problem is you are discarding the "correct" message.


local q,w,e = rednet.receive() --# this line receives "correct"
if w == "notExist" then --# it doesn't match this, so skip everything inside the if
  clear()
  print("[Login to debit account]")
  print(" ")
  term.setTextColor(colors.red)
  textutils.slowPrint("Username or password does not match.")
  term.setTextColor(colors.black)
  sleep(2)
  shell.run("login")
end
local s,m,p = rednet.receive() --# wait for another message (which is never sent!)
Thank you so much!