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

Error with Password Server (Need help!)

Started by ExtraRandom, 02 September 2012 - 01:43 PM
ExtraRandom #1
Posted 02 September 2012 - 03:43 PM
So i just followed the roaming profiles tutorial on the wiki (link in spoiler) and the server runs fine but when using one of the PC's meant to be connected to the system i get the error

startup:9: attempt to call nil




Spoilerhttp://computercraft...oaming_Profiles
dcleondc #2
Posted 02 September 2012 - 05:22 PM
So i just followed the roaming profiles tutorial on the wiki (link in spoiler) and the server runs fine but when using one of the PC's meant to be connected to the system i get the error

startup:9: attempt to call nil




Spoilerhttp://computercraft...oaming_Profiles
make sure on line 9 you have term.clear() typed right
ExtraRandom #3
Posted 02 September 2012 - 05:45 PM
yep its the same
sjele #4
Posted 02 September 2012 - 05:54 PM
It's so much easyer to figure stuff like this out if you post code.
Easy way to get code is:
(worldname)/computer/disk (if it is on disk, there find the right one and copy paste
(worldname)/computer/computer id and find it there.

Make sure that you have term.clear() typed right
ExtraRandom #5
Posted 02 September 2012 - 06:54 PM
local locker = true
local failed = true
local attempted_login = true
local password_server = 68
rednet.open("left")
while locker do
attempted_login = false
term.clear()
term.setCursor(1,1)
print("Welcome to a TEST PC")
print("What would you like to do?")
print("[1] Login (*)")
print("[2] Shutdown")
write(">")
local input = read()
if input == "2" then
  os.shutdown()
elseif input == "1" then
  attempted_login = true
  print("Please Login....")
  write("Username: ")
  local username = read()
  write("Password: ")
  local password = read ("*")
  rednet.send(password_server, username)
  senderId, message, distance = rednet.receive(5)
  if password == message then
   failed = false
   locker = false
   term.clear()
   term.setCursorPos(1,1)
   print("Welcome ", username)
  else
   print("Not Authorised.")
   sleep(1)
  end
else
  print("Command Not Recognised...")
  sleep(2)
end
end
sjele #6
Posted 02 September 2012 - 07:58 PM
I have noted the point of fixing

local locker = true
local failed = true
local attempted_login = true
local password_server = 68
rednet.open("left")
while locker do
attempted_login = false
term.clear()
term.setCursorPos(1,1) --see fix down below
print("Welcome to a TEST PC")
print("What would you like to do?")
print("[1] Login (*)")
print("[2] Shutdown")
write(">")
local input = read()
if input == "2" then
  os.shutdown()
elseif input == "1" then
  attempted_login = true
  print("Please Login....")
  write("Username: ")
  local username = read()
  write("Password: ")
  local password = read ("*")
  rednet.send(password_server, username)
  senderId, message, distance = rednet.receive(5)
  if password == message then
   failed = false
   locker = false
   term.clear()
   term.setCursorPos(1,1)
   print("Welcome ", username)
  else
   print("Not Authorised.")
   sleep(1)
  end
else
  print("Command Not Recognised...")
  sleep(2)
end
end

It is supposed to be
 term.setCursorPos(1, 1) 
and not
 term.setCursor(1, 1)
cant_delete_account #7
Posted 02 September 2012 - 08:15 PM
That program on the wiki has a lot of bugs, I'll edit it and hopefully fix them.
ExtraRandom #8
Posted 02 September 2012 - 09:57 PM
I have noted the point of fixing

local locker = true
local failed = true
local attempted_login = true
local password_server = 68
rednet.open("left")
while locker do
attempted_login = false
term.clear()
term.setCursorPos(1,1) --see fix down below
print("Welcome to a TEST PC")
print("What would you like to do?")
print("[1] Login (*)")
print("[2] Shutdown")
write(">")
local input = read()
if input == "2" then
  os.shutdown()
elseif input == "1" then
  attempted_login = true
  print("Please Login....")
  write("Username: ")
  local username = read()
  write("Password: ")
  local password = read ("*")
  rednet.send(password_server, username)
  senderId, message, distance = rednet.receive(5)
  if password == message then
   failed = false
   locker = false
   term.clear()
   term.setCursorPos(1,1)
   print("Welcome ", username)
  else
   print("Not Authorised.")
   sleep(1)
  end
else
  print("Command Not Recognised...")
  sleep(2)
end
end

It is supposed to be
 term.setCursorPos(1, 1) 
and not
 term.setCursor(1, 1)

thanks
Magus #9
Posted 02 September 2012 - 10:08 PM
That program on the wiki has a lot of bugs, I'll edit it and hopefully fix them.

and it doesn't take advantage of the power of lua tables, using them more like c arrays,
imho it would be better to do somthing like this


validSender = {
   [13] = true,
   [14] = true,
   [15] = true,
}
passwdb = {
--  usrname	   password
   ["hello"]   = "scriptkitty",
   ["creeper"] = "passssssssssword",
}

function nextlogin()
   -- keep receiving messages until we get one
   -- from a valid sender
   local senderID, message
   repeat
	 senderID, message = rednet.receive()
   until validSender[senderID]
   -- seperate username and password from the message
   -- and return them
   local msgPattern = "usr{([%w]*)}passwd{([%w]*)}"
   return string.match(message, msgPattern)
end
	 
for usrname, password in nextlogin do
   if passwdb[usrname] == password then
	  -- code for valid response goes hhere
   else
	  -- code for invalid responce goes here
   end
end