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

easy rednet fix

Started by moneymaster2012, 06 July 2017 - 04:44 PM
moneymaster2012 #1
Posted 06 July 2017 - 06:44 PM
I cannot seem to find the issue with these sets of code.

When I enter in the username and password fields, the program exists on the client AND the server - no matter what I put.

Seems like an easy fix.

Client Snippet

local function lClear()
  clear()
  print("[Login to debit account]")
  print(" ")
end
rednet.open("top")
rednet.broadcast("login")
lClear()
write("Username: ")
local user1 = read()
write("Password: ")
local pass1 = read("*")
rednet.broadcast(user1)
rednet.broadcast(pass1)
local h = rednet.receive()
if h == "notExist" then
  lClear()
  term.setTextColor(colors.red)
  textutils.slowPrint("Invalid credentials.")
  sleep(1)
  term.setTextColor(colors.black)
  shell.run("login")
elseif h == "exist" then
  local m = rednet.receive()
  if m == "correct" then
   shell.run("menu")
  elseif m == "incorrect" then
   lClear()
   term.setTextColor(colors.red)
   textutils.slowPrint("Invalid credentials.")
   sleep(1)
   term.setTextColor(colors.black)
   shell.run("login")
  end
end

Server Snippet

elseif m == "login" then
   
    local user = rednet.receive()
    local pass = rednet.receive()
    local i = fs.exists("users/"..user)
    if i == true then
	  rednet.broadcast("exist")
	  local t = fs.open("users/"..user,"r")
	  local h = t.readLine()
	  if pass == h then
	    rednet.broadcast("correct")
	  else
	    rednet.broadcast("incorrect")
	  end
    else
	  rednet.broadcast("notExist")
    end
  end
Anavrins #2
Posted 06 July 2017 - 06:55 PM
There doesn't seems to be any while or for loops in either script, so naturally it would exit out after one try.
KingofGamesYami #3
Posted 06 July 2017 - 06:56 PM
You're not receiving messages, you're receiving IDs. Take a look at the return values for rednet.receive
moneymaster2012 #4
Posted 06 July 2017 - 07:13 PM
You're not receiving messages, you're receiving IDs. Take a look at the return values for rednet.receive

My darn. Thank you for reminding me!
moneymaster2012 #5
Posted 06 July 2017 - 07:25 PM
Ok fixed the problem. Now, when I type in a username that does not exist, it still goes to the "notExist" statement (changed some outputs to test theory).

Any problems you see in there?

You're not receiving messages, you're receiving IDs. Take a look at the return values for rednet.receive
Bomb Bloke #6
Posted 07 July 2017 - 12:41 AM
Difficult to see problems in your current code if you don't reveal it.